MCP Server
The XBTFX MCP Server exposes the full Trading API through the Model Context Protocol (MCP), allowing AI assistants to trade forex, crypto, metals, indices, stocks, and energies on your XBTFX MetaTrader 5 account.
npm: @xbtfx/mcp-trading |
GitHub: XBTFX/xbtfx-mcp-server |
Version: 1.1.0
Quick Start
Section titled “Quick Start”Claude Code
Section titled “Claude Code”claude mcp add xbtfx-trading -e XBTFX_API_KEY=xbtfx_live_your_key_here -- npx @xbtfx/mcp-tradingClaude Desktop
Section titled “Claude Desktop”Add to claude_desktop_config.json:
{ "mcpServers": { "xbtfx-trading": { "command": "npx", "args": ["@xbtfx/mcp-trading"], "env": { "XBTFX_API_KEY": "xbtfx_live_your_key_here" } } }}See Supported Clients for Cursor, Windsurf, OpenAI Codex, and other clients.
Available Tools
Section titled “Available Tools”Account & Market Data
Section titled “Account & Market Data”| Tool | Description |
|---|---|
get_auth_status | Check API key status, login, margin mode, permissions |
get_account | Balance, equity, margin, free margin, P&L, leverage |
get_positions | Open positions with ticket, symbol, side, volume, prices, P&L |
get_orders | Pending limit/stop orders |
get_history | Deal history by period or custom date range |
get_symbols | All 400+ tradeable instruments with bid/ask (large response, 2 weight) |
get_symbol | Full contract spec — digits, volume limits, spread, swaps, margins, sessions |
get_quote | Live bid/ask for one or more symbols (max 20) |
Trading
Section titled “Trading”| Tool | Description |
|---|---|
trade | Open a position (buy/sell) with optional SL/TP |
close_position | Close a position (full or partial) |
modify_position | Update SL/TP on an existing position |
close_by | Close against an opposite position (hedging accounts only) |
reverse_position | Close and re-open in the opposite direction |
close_all | Close all open positions (10 weight) |
close_symbol | Close all positions for one symbol (10 weight) |
How It Works
Section titled “How It Works”The MCP server runs locally as a subprocess of your AI client. It connects to https://interface.xbtfx.com using your API key and translates MCP tool calls into REST API requests.
AI Client ←MCP→ xbtfx-mcp-server ←HTTPS→ interface.xbtfx.com ←bridge→ MT5All trading tools support idempotency — the server auto-generates an Idempotency-Key header for each trade to prevent duplicates on retry.
Example Conversation
Section titled “Example Conversation”You: What’s my account balance?
AI: calls get_account — Your balance is $988.00 with $888.00 free margin. Leverage is 1:1000. No open positions.
You: What’s the current EURUSD price?
AI: calls get_quote — EURUSD bid: 1.16638, ask: 1.16639, spread: 0.00001
You: Buy 0.01 lots of EURUSD with a 50 pip stop loss
AI: calls get_symbol then trade — Opened BUY 0.01 EURUSD. Retcode 10008 (placed). SL set at 1.14850.
Configuration
Section titled “Configuration”See Configuration for environment variables and advanced setup.