# Directory Structure ``` ├── .env.example ├── .gitignore ├── .python-version ├── Dockerfile ├── pyproject.toml ├── README.md ├── server.py ├── services │ ├── __init__.py │ └── tools.py └── uv.lock ``` # Files -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- ``` 3.11 ``` -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- ``` # Python-generated files __pycache__/ *.py[oc] build/ dist/ wheels/ *.egg-info # Virtual environments .venv .env ``` -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- ``` # Deriv API Configuration DERIV_API_TOKEN=your_api_token_here # Get from https://app.deriv.com/account/api-token DERIV_APP_ID=1089 # Default app_id, can be changed if you have your own ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- ```markdown # Deriv API Server A Model Context Protocol (MCP) server and OpenAI function calling service for interacting with the Deriv API. ## Features - Active symbols list - Get Account Balance ## Installation ### Local Installation ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ### Docker Installation 1. Build the Docker image: ```bash docker build -t deriv-api-mcp . ``` ## Environment Setup Create a `.env` file in your project root: ```env DERIV_API_TOKEN=your_api_key_here ``` ## Usage with Claude Desktop Claude Desktop provides full support for MCP features. To use this server: 1. Install [Claude Desktop](https://claude.ai/download) 2. Add to your Claude Desktop configuration: - On macOS: `~/Library/Application Support/Claude/claude_desktop_config.json` - On cline VSCode: `/Users/raju/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` - On Windows: `%APPDATA%\Claude\claude_desktop_config.json` ### For Local Installation ```json { "mcpServers": { "deriv-api-mcp": { "command": "uv", "args": [ "--directory", "/Users/raju/Sites/deriv/mcp-deriv-api-server", "run", "server.py" ] } } } ``` ### For Docker Installation ```json { "mcpServers": { "deriv-api-mcp": { "command": "docker", "args": [ "run", "--rm", "-i", "deriv-api-mcp" ] } } } ``` 3. Restart Claude Desktop The server provides the following tools: - `get_active_symbols`: Get a list of active trading symbols - `get_account_balance`: Get the current account balance ## Usage with OpenAI Function Calling ## Rate Limits Please refer to the [Deriv API documentation](https://api.deriv.com) for current rate limits and usage guidelines. ## License MIT ``` -------------------------------------------------------------------------------- /services/__init__.py: -------------------------------------------------------------------------------- ```python ``` -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- ```toml [project] name = "deriv-api-mcp" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.11" dependencies = [ "mcp[cli]>=1.2.0", "python-deriv-api>=0.1.6", "python-dotenv>=1.0.1", ] ``` -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- ```dockerfile # Use Python 3.11 as base image FROM python:3.11-slim # Set working directory WORKDIR /app # Install pip and project dependencies RUN pip install --no-cache-dir pip --upgrade # Copy project files COPY pyproject.toml . COPY server.py . COPY services/ services/ # Install project dependencies RUN pip install --no-cache-dir . # Copy .env file if it exists (for development) COPY .env* ./ # Expose any necessary ports (if needed) # EXPOSE 8000 # Run the server CMD ["python", "server.py"] ``` -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- ```python import json import os import sys from mcp.server.fastmcp import FastMCP from deriv_api import DerivAPI from services.tools import get_symbols, get_balance # Initialize FastMCP server mcp = FastMCP("deriv-api-mcp") # Load the .env file @mcp.tool() async def get_active_symbols() -> dict: active_symbols = await get_symbols() return active_symbols @mcp.tool() async def get_account_balance() -> dict: response = await get_balance() return response if __name__ == "__main__": # Initialize and run the server print("Deriv MCP server running on stdio", file=sys.stderr) mcp.run(transport='stdio') ``` -------------------------------------------------------------------------------- /services/tools.py: -------------------------------------------------------------------------------- ```python # run it like PYTHONPATH=. python3 examples/simple_bot1.py import sys import asyncio import os from deriv_api import DerivAPI from deriv_api import APIError from dotenv import load_dotenv load_dotenv() api_token = os.getenv('DERIV_API_TOKEN', '') if not api_token: raise ValueError("DERIV_API_TOKEN environment variable is required") app_id = os.getenv("DERIV_APP_ID", "1089") # Default to app_id 16929 async def get_symbols(): api = DerivAPI(app_id=app_id) response = await api.ping({'ping': 1}) if response['ping']: print(response['ping']) active_symbols = await api.active_symbols({"active_symbols": "brief", "product_type": "basic"}) return active_symbols async def get_balance() -> dict: api = DerivAPI(app_id=app_id) try: # Authorize authorize = await api.authorize(api_token) print(authorize) # Get Balance response = await api.balance() return response['balance'] finally: await api.clear() ```