#
tokens: 1917/50000 9/9 files
lines: on (toggle) GitHub
raw markdown copy reset
# Directory Structure

```
├── .env.example
├── .gitignore
├── .python-version
├── Dockerfile
├── pyproject.toml
├── README.md
├── server.py
├── services
│   ├── __init__.py
│   └── tools.py
└── uv.lock
```

# Files

--------------------------------------------------------------------------------
/.python-version:
--------------------------------------------------------------------------------

```
1 | 3.11
2 | 
```

--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------

```
 1 | # Python-generated files
 2 | __pycache__/
 3 | *.py[oc]
 4 | build/
 5 | dist/
 6 | wheels/
 7 | *.egg-info
 8 | 
 9 | # Virtual environments
10 | .venv
11 | .env
```

--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------

```
1 | # Deriv API Configuration
2 | DERIV_API_TOKEN=your_api_token_here  # Get from https://app.deriv.com/account/api-token
3 | DERIV_APP_ID=1089  # Default app_id, can be changed if you have your own
```

--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------

```markdown
 1 | # Deriv API Server
 2 | 
 3 | A Model Context Protocol (MCP) server and OpenAI function calling service for interacting with the Deriv API.
 4 | 
 5 | ## Features
 6 | 
 7 | - Active symbols list
 8 | - Get Account Balance
 9 | 
10 | ## Installation
11 | 
12 | ### Local Installation
13 | 
14 | ```bash
15 | curl -LsSf https://astral.sh/uv/install.sh | sh
16 | ```
17 | 
18 | ### Docker Installation
19 | 
20 | 1. Build the Docker image:
21 | ```bash
22 | docker build -t deriv-api-mcp .
23 | ```
24 | 
25 | ## Environment Setup
26 | 
27 | Create a `.env` file in your project root:
28 | 
29 | ```env
30 | DERIV_API_TOKEN=your_api_key_here
31 | ```
32 | 
33 | ## Usage with Claude Desktop
34 | 
35 | Claude Desktop provides full support for MCP features. To use this server:
36 | 
37 | 1. Install [Claude Desktop](https://claude.ai/download)
38 | 
39 | 2. Add to your Claude Desktop configuration:
40 |    - On macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
41 |    - On cline VSCode: `/Users/raju/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`
42 |    - On Windows: `%APPDATA%\Claude\claude_desktop_config.json`
43 | 
44 | ### For Local Installation
45 | ```json
46 | {
47 |   "mcpServers": {
48 |     "deriv-api-mcp": {
49 |       "command": "uv",
50 |       "args": [
51 |         "--directory",
52 |         "/Users/raju/Sites/deriv/mcp-deriv-api-server",
53 |         "run",
54 |         "server.py"
55 |       ]
56 |     }
57 |   }
58 | }
59 | ```
60 | 
61 | ### For Docker Installation
62 | ```json
63 | {
64 |   "mcpServers": {
65 |     "deriv-api-mcp": {
66 |       "command": "docker",
67 |       "args": [
68 |         "run",
69 |         "--rm",
70 |         "-i",
71 |         "deriv-api-mcp"
72 |       ]
73 |     }
74 |   }
75 | }
76 | ```
77 | 
78 | 3. Restart Claude Desktop
79 | 
80 | The server provides the following tools:
81 | - `get_active_symbols`: Get a list of active trading symbols
82 | - `get_account_balance`: Get the current account balance
83 | 
84 | ## Usage with OpenAI Function Calling
85 | 
86 | 
87 | ## Rate Limits
88 | 
89 | Please refer to the [Deriv API documentation](https://api.deriv.com) for current rate limits and usage guidelines.
90 | 
91 | ## License
92 | 
93 | MIT
94 | 
```

--------------------------------------------------------------------------------
/services/__init__.py:
--------------------------------------------------------------------------------

```python
1 | 
```

--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------

```toml
 1 | [project]
 2 | name = "deriv-api-mcp"
 3 | version = "0.1.0"
 4 | description = "Add your description here"
 5 | readme = "README.md"
 6 | requires-python = ">=3.11"
 7 | dependencies = [
 8 |     "mcp[cli]>=1.2.0",
 9 |     "python-deriv-api>=0.1.6",
10 |     "python-dotenv>=1.0.1",
11 | ]
12 | 
```

--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------

```dockerfile
 1 | # Use Python 3.11 as base image
 2 | FROM python:3.11-slim
 3 | 
 4 | # Set working directory
 5 | WORKDIR /app
 6 | 
 7 | # Install pip and project dependencies
 8 | RUN pip install --no-cache-dir pip --upgrade
 9 | 
10 | # Copy project files
11 | COPY pyproject.toml .
12 | COPY server.py .
13 | COPY services/ services/
14 | 
15 | # Install project dependencies
16 | RUN pip install --no-cache-dir .
17 | 
18 | # Copy .env file if it exists (for development)
19 | COPY .env* ./
20 | 
21 | # Expose any necessary ports (if needed)
22 | # EXPOSE 8000
23 | 
24 | # Run the server
25 | CMD ["python", "server.py"]
26 | 
```

--------------------------------------------------------------------------------
/server.py:
--------------------------------------------------------------------------------

```python
 1 | import json
 2 | import os
 3 | import sys
 4 | from mcp.server.fastmcp import FastMCP
 5 | from deriv_api import DerivAPI
 6 | 
 7 | from services.tools import get_symbols, get_balance
 8 | # Initialize FastMCP server
 9 | mcp = FastMCP("deriv-api-mcp")
10 | # Load the .env file
11 | 
12 | @mcp.tool()
13 | async def get_active_symbols() -> dict:
14 |     active_symbols = await get_symbols()
15 |     return active_symbols
16 | 
17 | @mcp.tool()
18 | async def get_account_balance() -> dict:
19 |     response = await get_balance()
20 |     return response
21 | 
22 | 
23 | if __name__ == "__main__":
24 |     # Initialize and run the server
25 |     print("Deriv MCP server running on stdio", file=sys.stderr)
26 |     mcp.run(transport='stdio')
27 | 
```

--------------------------------------------------------------------------------
/services/tools.py:
--------------------------------------------------------------------------------

```python
 1 | # run it like PYTHONPATH=. python3 examples/simple_bot1.py
 2 | import sys
 3 | import asyncio
 4 | import os
 5 | from deriv_api import DerivAPI
 6 | from deriv_api import APIError
 7 | from dotenv import load_dotenv
 8 | 
 9 | load_dotenv()
10 | 
11 | api_token = os.getenv('DERIV_API_TOKEN', '')
12 | if not api_token:
13 |     raise ValueError("DERIV_API_TOKEN environment variable is required")
14 | 
15 | app_id = os.getenv("DERIV_APP_ID", "1089")  # Default to app_id 16929
16 | 
17 | 
18 | async def get_symbols():
19 |     api = DerivAPI(app_id=app_id)
20 | 
21 |     response = await api.ping({'ping': 1})
22 |     if response['ping']:
23 |         print(response['ping'])
24 | 
25 |     active_symbols = await api.active_symbols({"active_symbols": "brief", "product_type": "basic"})
26 |     return active_symbols
27 | 
28 | async def get_balance() -> dict:
29 |     api = DerivAPI(app_id=app_id)
30 |     try:
31 |         # Authorize
32 |         authorize = await api.authorize(api_token)
33 |         print(authorize)
34 | 
35 |         # Get Balance
36 |         response = await api.balance()
37 |         return response['balance']
38 |     finally:
39 |         await api.clear()
40 | 
```