Connect Claude to MetaTrader 5 (MT5 MCP server)
By the Kairotick team. Updated .
MetaTrader 5 has its own MCP server built in. Once it is on, an AI app such as Claude Code or Codex can read your account, charts and prices, run the Strategy Tester and, if you allow it, place trades. We set it up and tested it on November 18, 2026. Here is the setup, what it can do, what went wrong, and how to keep it safe on a prop account.
The short answer
In MetaTrader 5, open Tools > Options > MCP, turn on Enable internal server, create an API key, click OK, then click Copy. Paste what it copies into a file named .mcp.json in your Claude Code project folder and restart Claude Code. Keep MetaTrader 5 open while you use it.
Set it up in Claude Code
- Open MetaTrader 5, click Tools > Options and open the MCP tab. If there is no MCP tab, update MetaTrader 5 first; every build we tested (6241 to 6320) had it.
- Tick Enable internal server. Keep the address
http://127.0.0.1:22346/mcpunless another app already uses that port. - Create the API Key, click OK, open the tab again and click Copy. MetaTrader puts ready settings for Claude Code and Codex on your clipboard.
- Paste the Claude Code part into
.mcp.jsonin your project folder, or into~/.claude.jsonto use it in every project. Restart Claude Code.
To check it, ask the test question from MetaQuotes' guide: Using MetaTrader MCP servers, provide a table of all the tools you can access.
If you only want your terminal, this is all .mcp.json needs. Put your own key in place of YOUR_KEY:
{
"mcpServers": {
"mt5-terminal": {
"type": "http",
"url": "http://127.0.0.1:22346/mcp",
"headers": {
"Authorization": "Bearer YOUR_KEY"
}
}
}
}Or add it with one command:
claude mcp add --transport http mt5-terminal http://127.0.0.1:22346/mcp --header "Authorization: Bearer YOUR_KEY"
The copied settings hold three servers: terminal (your MetaTrader 5, port 22346), metaeditor (MetaEditor, port 22345) and marketdata (MetaTrader.com market data and news). This page is about the terminal server. For Codex, put the Codex part into .codex/config.toml in your project folder.
Why Claude Code and not a web chat
The server listens on 127.0.0.1, which means your own computer. An AI app has to run on that same computer to reach it. MetaQuotes' guide covers Claude Code and Codex, and says any MCP app that takes the same JSON settings works too.
What the 107 tools do
| Group | What they do |
|---|---|
| Trading10 tools | Send market and pending orders, check an order before sending it, change stop loss and take profit, close positions, delete orders, work out margin and profit. |
| Account and history4 tools | Balance, equity and margin; open positions and orders; past orders, deals and positions. |
| Prices and Market Watch8 tools | Candles and ticks for any period, the Market Watch list, and depth of market. |
| Charts and indicators28 tools | Open and close charts, change symbol and timeframe, add Expert Advisors, scripts and indicators and read indicator values, draw objects, save templates, profiles and screenshots. |
| Expert Advisors and services10 tools | List your MQL5 programs and read their inputs; start, stop and register services. |
| Strategy Tester11 tools | Write the tester settings and inputs, run a backtest or an optimization, wait for it and read the report. |
| Economic calendar and news9 tools | Calendar events and their values by country or currency, and news headlines. |
| Alerts5 tools | Create, change, switch on or off and delete alerts. |
| Files and web16 tools | Find, read, write, edit and delete files, and send a web request. |
| Terminal and journals6 tools | Terminal and time information, and the terminal, Experts and tester journals. |
Counted from the server's own list on November 18, 2026. MetaQuotes says the list keeps growing, and that the tools an app sees depend on your trading, web and shell settings.
A backtest run only through MCP
We ran the MACD Sample Expert Advisor that ships with MetaTrader 5 through MCP alone: tester_prepare_config, then tester_run_backtest, then tester_get_report. EURUSD H1, January 1 to July 1, 2026, the 1 minute OHLC model, MetaQuotes-Demo prices. It took 7.5 seconds and the report came back as data: 36 trades, profit factor 1.14, net +$83.07, drawdown 2.18%. That is a sample EA, not a strategy we recommend.
Is it the same as the normal Strategy Tester? We ran one of our own Expert Advisors both ways on USDJPY M1, October 23 to November 18, 2026. All 581 lines its log wrote were identical, the profit matched to the cent, and both runs had 147 trades. The MCP run took 113 seconds against 57, because it downloaded the price history first.
Traps we hit
- Two terminals, one port. The second terminal cannot open the same address; its journal says
MCP bind error on 127.0.0.1:22346 (10048). Give it its own port in the MCP tab (we used 22356) and restart that terminal. - Use the key from the MCP tab. Without the right key the server answers 401. The key saved in the terminal's config file is encrypted, so copying it from there does not work.
- The first test downloads history. Expect the first run to be slower. If a test reports no bars, the history was not ready when it started; run it again.
- Clear files your EA appends to. If your Expert Advisor adds lines to a file, empty it before each run, or two runs end up mixed in one file.
Keep it safe on a prop or live account
- Trading is allowed by default. On our test terminal,
terminal_get_inforeported"mcp_trade_allowed": trueout of the box. - On that test copy, an order check was refused with trading is not permitted because the Algo Trading button was off. We did not test it with Algo Trading on, so assume an AI app can trade whenever Algo Trading is on.
- Set the Trading switch. Under Tools > Options > AI Assistant > Trading you can let the assistant trade, make it ask for confirmation first, or block trading. On a prop or live account, choose confirmation or no trading.
- Leave Dangerous shell operations off. It lets the assistant run PowerShell or Python outside MetaTrader's own folders. Even without it, the server can read and write files in the MQL5 and Common folders, where Expert Advisors keep their files.
- A trade the assistant places counts toward your daily loss and drawdown limits like any other trade. Check your firm's rules on automated trading before any program trades a funded account. See our prop firm rules and the drawdown calculator.
Add Kairotick for news times and prop rules
Kairotick's own MCP server is free and needs no key. With both in one Claude Code project, one question can use your account and our data:
{
"mcpServers": {
"mt5-terminal": {
"type": "http",
"url": "http://127.0.0.1:22346/mcp",
"headers": {
"Authorization": "Bearer YOUR_KEY"
}
},
"kairotick": {
"type": "http",
"url": "https://kairotick.com/mcp"
}
}
}- I have open positions. Is a high-impact US release due in the next two hours? (your open positions from MetaTrader 5, release times from Kairotick)
- Can I hold my open trades through NFP on an FTMO account? (your positions, the next NFP date and FTMO's news rule as quoted from its own page)
- How far did gold move in the first 15 minutes after the last CPI, and how big is my gold position now? (past reactions from Kairotick, your position size from MetaTrader 5)
Setup for Kairotick alone, in ChatGPT, Claude and Gemini: Use Kairotick in ChatGPT, Claude and Gemini.
Sources
Setup steps follow MetaQuotes' help pages Configuration and Capabilities, read November 23, 2026. The tool count, timings and traps come from our own test on November 18, 2026.
Questions
Does MetaTrader 5 have a built-in MCP server?
Yes. In MetaTrader 5, open Tools > Options > MCP and turn on Enable internal server. The terminal server listens on http://127.0.0.1:22346/mcp by default and needs the API key from the same tab.
Can Claude place trades on my MT5 account?
Yes, if trading is allowed. On our test terminal it was allowed by default. Under Tools > Options > AI Assistant > Trading you can make the assistant ask for confirmation first, or not trade at all.
Can I use it from ChatGPT or Claude on the web?
Not directly. The server listens only on your own computer (127.0.0.1), so the AI app has to run on the same computer. MetaQuotes documents Claude Code and Codex.
Can it run backtests?
Yes. The Strategy Tester tools write the settings, run the test and return the report. In our test a six-month EURUSD H1 backtest took 7.5 seconds.
Does MetaTrader 5 have to stay open?
Yes. The server runs inside the terminal, so MetaTrader 5 must be running while the AI app uses it.