MCP server: let Claude, Cursor, VS Code and other AI agents trade MT5
Connect an AI assistant or agent to fxapis over the Model Context Protocol. Setup for Claude, Claude Code, Claude Desktop, Cursor, VS Code and the OpenAI and Anthropic APIs, the full tool reference, and the safety model for letting an agent near a real MetaTrader 5 account.
fxapis runs a hosted Model Context Protocol (MCP) server. Point an MCP client at it with an fxapis API key and the assistant can list your MetaTrader 5 accounts, read positions, orders and deals, bring accounts online and — if the key allows it — place, modify and close trades.
https://api.fxapis.com/mcpThere is nothing to install or run: the server is part of the API, and the MT5 terminals run in our EU cloud, as they do for every other fxapis call.
An agent with a trading key trades real money
Every fxapis key, fx_test_ included, reaches a real broker. Start with a broker demo
account and a read-only key. Give an agent trading:reduce (close, move stops, cancel)
before you ever give it trading:execute (open positions). Read Safety model
before connecting a live account.
How it works
- Transport: Streamable HTTP, stateless. It speaks both the 2026-07-28 revision of the
protocol and the 2025 revisions (clients that start with an
initializehandshake), and answers in plain JSON. There are no sessions, so any of our servers can answer any request. - Authentication: your fxapis API key, in
Authorization: Bearer fx_live_….X-API-Key: fx_live_…is accepted too, for clients that only offer that header. A missing or invalid key gets401with aWWW-Authenticate: Bearerchallenge. OAuth sign-in is not available yet. - The same rules as the REST API. Each tool calls the ordinary
/v1endpoints with your key. Scopes, workspace isolation, rate limits, plan limits, idempotency and our trading kill switch apply exactly as they do to your own code — the MCP server cannot do anything the key could not do over REST. Each tool call counts as one or two API calls on your plan. - Deliberately missing: connecting an MT5 account and managing API keys. Connecting takes the broker password, and a broker credential must never pass through a language model's context. Do both in the fxapis console.
Create a key for the agent
In the console, create a key just for the assistant, with the fewest scopes that do the job:
| The agent should… | Scopes |
|---|---|
| Report on accounts, positions and history | accounts:read, trading:read, history:read |
| …and bring accounts online or take them offline | add accounts:write |
| …and manage risk: close, move stops, cancel — never open | add trading:reduce |
| …and open new positions | add trading:execute |
A key without the scope for a tool gets MISSING_SCOPE back from that tool, and the agent is
told to ask you rather than work around it. Revoke the key in the console and the agent is
cut off on its very next call.
Connect your client
Replace fx_live_… with your key in each example. Keep the key out of anything you commit.
Claude (claude.ai and Claude Desktop)
Custom connectors are added in Customize → Connectors → Add custom connector (on Team and Enterprise plans an Owner adds it under Organization settings → Connectors).
- MCP server URL:
https://api.fxapis.com/mcp - Authentication: choose No sign-in.
- Request headers: add
authorizationwith the valueBearer fx_live_…— include the wordBearerand the space; Claude sends the value exactly as typed.
Connectors you add on claude.ai are also available in the Claude desktop app.
Request headers are in beta at Claude
Anthropic is rolling out the Request headers section to a limited set of organizations
(Anthropic's connector docs, checked 30
September 2026).
If your dialog does not show it, claude.ai cannot send an API key yet — use Claude Code, or
Claude Desktop through mcp-remote as below, until it does. Header settings cannot be edited
later: to change the key, remove the connector and add it again.
Claude Desktop without request headers. Claude Desktop can run the open-source
mcp-remote bridge, which adds the header for it.
Add this to claude_desktop_config.json (Settings → Developer → Edit Config), then restart
Claude Desktop. Node.js 18 or newer must be installed.
{
"mcpServers": {
"fxapis": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://api.fxapis.com/mcp", "--header", "Authorization:${FXAPIS_AUTH}"],
"env": { "FXAPIS_AUTH": "Bearer fx_live_…" }
}
}
}The header is passed through an environment variable because some systems split arguments on spaces.
Claude Code
claude mcp add --transport http fxapis https://api.fxapis.com/mcp \
--header "Authorization: Bearer $FXAPIS_KEY"Or share it with your team in the project's .mcp.json, reading the key from each person's
environment:
{
"mcpServers": {
"fxapis": {
"type": "http",
"url": "https://api.fxapis.com/mcp",
"headers": { "Authorization": "Bearer ${FXAPIS_KEY}" }
}
}
}Run /mcp inside Claude Code to check that fxapis is connected.
ChatGPT
ChatGPT's developer-mode apps currently connect with OAuth or with no authentication; they do not send an API key (OpenAI's developer mode guide, checked 30 September 2026). Because fxapis requires a key and does not offer OAuth sign-in yet, the fxapis MCP server cannot be added to ChatGPT today. Agents built on the OpenAI API can use it — see OpenAI API.
Cursor
Add to ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project):
{
"mcpServers": {
"fxapis": {
"url": "https://api.fxapis.com/mcp",
"headers": { "Authorization": "Bearer ${env:FXAPIS_KEY}" }
}
}
}${env:FXAPIS_KEY} reads the key from your environment; you can also paste the key in its
place in a file that is never committed. The server appears under Settings → MCP.
VS Code (GitHub Copilot agent mode)
Add .vscode/mcp.json. VS Code asks for the key the first time and stores it securely:
{
"inputs": [
{ "type": "promptString", "id": "fxapis-key", "description": "fxapis API key", "password": true }
],
"servers": {
"fxapis": {
"type": "http",
"url": "https://api.fxapis.com/mcp",
"headers": { "Authorization": "Bearer ${input:fxapis-key}" }
}
}
}OpenAI API (Responses)
{
"type": "mcp",
"server_label": "fxapis",
"server_url": "https://api.fxapis.com/mcp",
"authorization": "fx_live_…",
"require_approval": {
"never": { "tool_names": ["list_accounts", "get_account_status", "list_positions", "get_order", "list_orders"] }
}
}Put this in the request's tools array. require_approval as written lets the model read
freely and asks your code to approve every other call, including every trade. The value in
authorization is not stored by OpenAI; send it with each request
(OpenAI's MCP guide, checked 30
September 2026).
Anthropic API (Messages)
{
"model": "claude-opus-5",
"max_tokens": 16000,
"mcp_servers": [
{ "type": "url", "url": "https://api.fxapis.com/mcp", "name": "fxapis", "authorization_token": "fx_live_…" }
],
"tools": [{ "type": "mcp_toolset", "mcp_server_name": "fxapis" }],
"messages": [{ "role": "user", "content": "Which of my MT5 accounts are online?" }]
}Send it with the anthropic-beta: mcp-client-2025-11-20 header. Both halves are needed: the
server under mcp_servers and the mcp_toolset entry in tools.
Any other client
Any client that supports Streamable HTTP and custom headers works: URL
https://api.fxapis.com/mcp, header Authorization: Bearer fx_live_…. To test from a terminal
with the MCP Inspector:
npx @modelcontextprotocol/inspector --cli https://api.fxapis.com/mcp --transport http \
--header "Authorization: Bearer $FXAPIS_KEY" --method tools/listTools
Arguments are snake_case. Account ids are the fxapis UUIDs from list_accounts, not MT5 login
numbers. Volumes and prices are best sent as strings ("0.10", "1.08450"); numbers are
accepted and converted. Every result carries the API's own data as structured content, plus a
one-line summary for the model.
Read-only
These never change anything. Clients that honour readOnlyHint can run them without asking.
| Tool | What it does | Scope |
|---|---|---|
get_workspace | Plan, its limits and features, and whether trading is switched off | accounts:read |
get_usage | This month's orders, multi-account orders and API calls against the plan | accounts:read |
list_accounts | Every connected MT5 account with its id, login, server and state | accounts:read |
get_account | One account: broker, currency, leverage, state | accounts:read |
get_account_status | Just the state — poll it after bring_accounts_online until ready | accounts:read |
list_positions | Positions on an account as last observed, with observedAt | trading:read |
list_orders | Orders, newest first, filtered by account, state, symbol and time; paginated | trading:read |
get_order | One order, the broker's return code and fill; optionally its deals | trading:read (+ history:read for deals) |
list_deals | The broker's deal history for an account, including deals no order of yours caused | history:read |
list_multi_account_orders | Recent multi-account orders, with a result per account | trading:read |
get_multi_account_order | One multi-account order, to follow it until it settles | trading:read |
calculate | Margin an order would need, or profit between two prices — asks the broker, opens nothing | trading:read |
Account lifecycle
These start or stop the account's terminal in our cloud. They never trade and are safe to repeat.
| Tool | What it does | Scope |
|---|---|---|
bring_accounts_online | Starts and logs in up to 200 accounts; returns at once with a result per account | accounts:write |
take_account_offline | Stops the terminal. Open positions, stop losses and take profits stay at the broker | accounts:write |
Trading
These act on a real broker account. They are marked destructiveHint: true, so a client that
asks before acting will ask. Each one requires an idempotency_key.
| Tool | What it does | Scope |
|---|---|---|
place_market_order | Opens a position at market, with optional stop loss and take profit | trading:execute |
place_pending_order | Places a limit, stop or stop-limit order that waits at the broker | trading:execute |
close_position | Closes a position in whole or in part | trading:reduce |
modify_position | Moves or removes a position's stop loss and take profit | trading:reduce |
cancel_order | Cancels a pending order that has not triggered | trading:reduce |
place_multi_account_order | Places the same trade on many accounts at once | trading:execute |
cancel_multi_account_order | Calls off a multi-account order before anything is sent | trading:reduce |
The idempotency key. The agent generates a fresh key — a UUID is ideal — for each new
action, and sends the same key again if it retries that action after an error or a timeout.
It is the Idempotency-Key header of the REST API, passed through unchanged.
Market orders, pending orders, closes and multi-account orders take an Idempotency-Key: with
the same key, fxapis returns the first answer instead of acting twice, so a retried order is
never a second order and a retried close is never an opposite position. Stop changes and
cancels are safe to repeat.
Errors
A failure comes back as an MCP tool error (isError: true) whose text starts with the API's
own error code, followed by the message and what to do next:
ORDER_UNRESOLVED (HTTP 502): Something went wrong and we do not know yet whether the order was sent. We are confirming it with the broker. Do not resend it.
Next step: Do NOT resend this order. Its outcome is unknown and it may be live at the broker. Poll get_order with the orderId in details until it leaves `unknown`, and tell the user.The same code, status, message, request id and next step are in the result's _meta under
com.fxapis/error, for programs. The codes that matter most to an agent:
| Code | Meaning for the agent |
|---|---|
ORDER_UNRESOLVED | The outcome is unknown and the order may be live. Never resend; poll get_order |
SEND_FAILED | Nothing reached the broker. Retry with the same idempotency_key |
ORDER_REJECTED | The broker refused it; nothing was opened. Tell the user the reason |
MISSING_SCOPE | The key does not allow this. Ask the user; do not look for another way |
ACCOUNT_NOT_READY / NO_RUNTIME | Bring the account online, wait for ready, then retry |
RATE_LIMITED | Wait retryAfterSeconds, then retry once |
TRADING_DISABLED | Trading is switched off for the account or workspace. Do not retry |
Safety model
An agent is a new kind of caller: it can misread a request, act on text planted in a web page or a message it was asked to summarize, or loop. The protections, from strongest to weakest:
- The key's scopes. These are enforced by the API on every call, whatever the model
decides. A read-only key cannot trade, and a
trading:reducekey can only ever close, cancel and move stops — it cannot open exposure. Start there. - Demo accounts. Connect a broker demo account while you learn how an agent behaves with it. There is no simulated market at fxapis; demo accounts are how you test.
- Your plan's limits. Opening orders are refused once the plan's limits are reached (closing is never refused for billing), and rate limits apply per class of request.
- Your client's approvals. Trading tools are marked destructive and read-only tools are marked read-only, so clients such as Claude Code and Cursor ask before a trade. Do not choose "always allow" for trading tools on a live account.
- The tool descriptions. Every trading tool tells the model it trades real money and to confirm symbol, side, volume and account with you first. That shapes behaviour; it does not enforce anything. Scopes do.
Every order an agent places is recorded like any other — in list_orders and in the console —
with the key that placed it. Tool calls are logged with the tool name, the
workspace and the outcome — never the arguments.
Example prompts
- "Which of my MT5 accounts are online, and what positions are open on each?"
- "What was my realised profit on EURUSD this week on the Vantage demo account?"
- "How much margin would 0.5 lots of XAUUSD need on account 2?"
- "Bring all my accounts online, then tell me when they are ready."
- "Move the stop loss on my gold position to break-even." (needs
trading:reduce) - "Close half of every open EURUSD position on the demo account." (needs
trading:reduce) - "Buy 0.01 lots of EURUSD on the demo account with a 20-pip stop." (needs
trading:execute) - "Did anything go wrong with today's orders? Show me any that are still
unknown."
Limits of the MCP server today
- API keys only. OAuth sign-in, which would let a claude.ai or ChatGPT user connect with their fxapis login instead of a key, is planned.
- No streaming or notifications. Tools answer once. Following an account coming online or a multi-account order settling is done by polling, as with the REST API; fxapis has no event webhooks yet.
- MetaTrader 5 only. MT4 is not supported.
TradingView alerts to MT5 — no EA, no VPS
Turn TradingView alerts into MetaTrader 5 orders with a secret webhook URL: create a hook in the console or the API, set up the TradingView alert step by step, message formats and placeholders for indicators and strategies, closing, idempotency, the IP allowlist, troubleshooting and limits.
Monitor MT5 trader accounts for prop-firm rules
Use deals, positions and order history from the fxapis MT5 API to check prop-firm rules such as daily loss and maximum drawdown on your side, with read-only and reduce-only API keys, and close every position on an account that breaches.