How to connect MT5 to Claude and ChatGPT with MCP
MetaTrader 5 has had a built-in MCP server since build 6060 (July 2026). Turn it on under Tools → Options → MCP, click Copy, and paste the config into Claude Code or OpenAI's Codex. Or skip external clients and pick Claude or GPT as the model behind MT5's own AI Assistant. Start on a demo account with trading switched off.
What is MCP?
MCP, the Model Context Protocol, is an open standard that lets an AI assistant such as Claude or ChatGPT use tools outside the chat: read files, query a database, or ask a trading platform for prices. Anthropic created it, and it is now supported by Claude, ChatGPT and many developer tools. The project's own documentation compares it to a USB-C port: one standard plug instead of a custom cable for every device.
Three parts are involved:
- The client: the AI app you type into (Claude Code, Codex, Claude Desktop, ChatGPT).
- The MCP server: a program that exposes a list of tools, such as "get candles for a symbol" or "list open positions". The model reads the tool descriptions and decides when to call one.
- The system behind it: here, your MetaTrader 5 terminal and the trading account it is logged in to.
So when you ask "what was gold's range on the H4 chart this week?", the model calls the server's candle tool, the server asks MT5, and the answer comes back as data the model can read. The model never sees your MT5 screen; it only sees what the tools return.
Does MT5 have an official MCP server?
Yes. MetaQuotes added native MCP support to the MT5 desktop terminal in build 6060 (23 July 2026), alongside a built-in AI Assistant, and has added tools in every build since (6090, 6140, 6180 and 6230, the last on 24 September 2026). The MT5 help names Claude Code and OpenAI's Codex as external clients and gives a ready-made config for each. Check your build under Help → About; MT5 updates itself through Live Update. The AI features are disabled on Windows 7.
The terminal exposes three MCP servers:
Each connection is authenticated with an API key (a bearer token) that the terminal generates for you. The two local servers listen on 127.0.0.1, so only programs on the same computer can reach them.
What the terminal server can do, from MetaQuotes' own tool list: read Market Watch, candles (get_chart_history) and ticks; open charts and add indicators; read balance, equity, margin, open positions and trade history; attach Expert Advisors and run backtests and optimisations (tester_run_backtest, tester_get_report); read the platform and Experts journals; and place, modify and close orders (trade_send_market_order, trade_modify_sl_tp, trade_close_single_position and others). Some general tools can also run shell commands and write files. That last group is why the safety settings below come first.
MetaQuotes says the tool list keeps growing and that the reliable way to see what is available is to ask the agent: "Using MetaTrader MCP servers, provide a table of all the tools you can access."
Which route should you use?
There are three ways to put Claude or a GPT model to work on your MT5 data:
The built-in Assistant is the shortest path if you only want Claude or GPT to read your charts and history: no config files, and the trading and shell permissions sit in the same settings tab. Claude Code and Codex make sense when you want to work across your own files, notes or scripts as well as MT5.
How do you lock it down before connecting anything?
Do this first, on a demo account.
- Open Tools → Options → AI Assistant.
- Set Trading to not trade at all. The other choices are request explicit confirmation and full permission to execute.
- Set Web to GET requests only or locked out, unless you need web access.
- Leave Dangerous shell operations: PowerShell, Python, etc. switched off. With it on, the Assistant can run commands on your computer outside MT5's own folders.
- Click OK.
MetaQuotes says these settings are shared by the terminal and MetaEditor, and that the tool list an agent sees "may vary depending on your configuration for trading, web access, and shell operations". After you connect an external client, ask it for its tool table and confirm that no trade_ tools appear before you go further.
How do you enable MT5's MCP server?
- Open Tools → Options → MCP.
- Tick Enable internal server. This switches on the
terminalserver only; it does not controlmarketdataormetaeditor. - Leave the Address at its default (
http://127.0.0.1:22346/mcp) unless another program already uses that port. - Generate an API Key. External clients send it with every request.
- Click OK, then click Copy. MT5 puts a ready-made config on the clipboard with two sections, one for Claude Code and one for Codex, each listing all three servers.
Keep the MT5 terminal open while you work: the local servers only exist while it runs.
How do you connect MT5 to Claude Code?
- Create a folder for this work, for example
D:\MT5 AI. - In it, create a file named
.mcp.jsonand paste the Claude Code section from MT5. It looks like this, with your key afterBearer:{
"mcpServers": {
"terminal": {
"type": "http",
"url": "http://127.0.0.1:22346/mcp",
"headers": { "Authorization": "Bearer <your MT5 API key>" }
},
"marketdata": {
"type": "http",
"url": "https://www.metatrader.com/mcp",
"headers": { "Authorization": "Bearer <your MT5 API key>" }
},
"metaeditor": {
"type": "http",
"url": "http://127.0.0.1:22345/mcp",
"headers": { "Authorization": "Bearer <your MT5 API key>" }
}
}
}
Delete any server you do not need: if you are not writing MQL5 code, dropmetaeditor. For access from every folder, MetaQuotes says to put the same block in~/.claude.jsoninstead. - Restart Claude Code, open it in that folder, and ask: "Using MetaTrader MCP servers, provide a table of all the tools you can access."
- Test with a read-only question, for example: "Using the terminal tools, get the last 10 daily candles for XAUUSD and the high-low range of each." Claude Code asks your permission before it calls a tool. Read what it is about to run before you allow it.
Claude Desktop (the chat app) is not covered by MetaQuotes' guide. Its config file starts local programs, and its custom connectors are made from Anthropic's cloud, which cannot reach a server on 127.0.0.1. Reaching MT5 from it needs a local bridge, such as the open-source mcp-remote package, which we have not tested with MT5.
How do you connect MT5 to ChatGPT?
MetaQuotes' guide covers Codex, OpenAI's coding agent, which runs on your computer and can reach the local server directly:
- In the Codex app, use File → Open Folder and choose (or create) a project folder, for example
D:\MT5 AI. - Create the subfolder
.codexand, inside it, a file namedconfig.toml. Paste the Codex section from MT5:[mcp_servers.terminal]
url = "http://127.0.0.1:22346/mcp"
enabled = true
http_headers = { "Authorization" = "Bearer <your MT5 API key>" }
[mcp_servers.marketdata]
url = "https://www.metatrader.com/mcp"
enabled = true
http_headers = { "Authorization" = "Bearer <your MT5 API key>" } - Restart Codex and check File → Settings → Plugins → MCPs: the MT5 servers should be listed.
- Ask for the tool table, then start with read-only questions as above.
The ChatGPT chat app on the web is a different case. OpenAI's help page says it "connects to remote MCP servers", either at a public HTTPS address or through OpenAI's Secure MCP Tunnel, and full custom-server access needs a Business, Enterprise or Edu workspace (Pro users get read and fetch permissions only). Because MT5's terminal server listens only on your own PC, ChatGPT can reach it only through a tunnel run on that PC. Never publish the terminal server on an open port: anyone who reaches it gets the same tools ChatGPT does.
What about community MT5 MCP servers?
Before build 6060, open-source projects filled the gap, and they still work through MetaQuotes' MetaTrader5 Python package on Windows. Two examples, checked on 11 November 2026: metatrader-mcp-server (MIT, about 850 GitHub stars, can trade) and mt5-mcp (MIT, read-only by design: order calls are blocked). Neither is affiliated with MetaQuotes, Anthropic, OpenAI or Fintrix Markets, and we have not audited their code.
The built-in server is the better starting point for most traders: it ships with MT5, needs no Python install, authenticates every client with an API key, and exposes more of the platform (Strategy Tester, journals, chart control). A community server can still make sense if you want one that cannot place orders whatever its settings, or a tool the official server does not offer yet.
How do you keep an AI connection to your trading account safe?
The model reads tool descriptions and your words, then decides what to call. It can misread a request, misplace a decimal or act on a stale price. These rules limit what a mistake can cost:
- Start on a demo account. Run every new client, prompt and workflow on demo first, and stay there until the model's behaviour has stopped surprising you.
- Switch trading off, and enforce it twice. Set Trading to not trade at all in MT5's AI settings, and log the terminal in with the account's investor password. MetaTrader describes the investor password as access "in read-only mode (no trading operations)", and the trade server enforces it, whatever the AI settings say. Move to request explicit confirmation, on demo, only when you have decided to test order handling.
- Treat the MT5 API key like a password. It sits in plain text in
.mcp.jsonorconfig.toml. Keep those files out of shared or synced folders, never paste the key or your MT5 password into a chat, and generate a new key if one leaks. - Assume the model can be wrong, or be misled. A worked example: on 30 October 2026, gold (XAUUSD) moved between 4,028.70 and 3,869.31 on the Fintrix Markets MT5 feed, a range of $159.39. On a 100-ounce contract, that range is worth $1,593.90 on 0.10 lots and $15,939 on 1.00 lot. A model that drops one zero turns the first number into the second. Text the model reads inside a tool result, a news item, a web page or a file can also contain instructions it follows by mistake, which OpenAI's help page warns about as prompt injection. Keep web access and shell operations off unless a task needs them.
- Keep a human approving every order. If you do enable trading, choose explicit confirmation, leave the client's own permission prompts on, and read the symbol, direction and volume before you approve. MetaQuotes' own help is plain about it: "You are solely responsible for AI-generated content, AI-assisted actions, trading decisions, trading results, and any resulting losses."
Two more checks before you rely on any of it:
- Keep a log. Note what you asked, what the model called and what came back. MT5 also keeps your AI Assistant chats in the Navigator's Chats tab.
- Test the results the way you test a backtest. An AI summary of past price data is still analysis of the past, and an AI-run optimisation can overfit as easily as a manual one. Our look-ahead bias lesson explains why a result that uses information you would not have had at the time looks better than it should.
What is MT5 and MCP useful for?
Connecting an AI assistant to MT5 does not make anyone a better trader by itself. It changes how quickly you can get at your own information. Typical uses with trading switched off:
- Summarising your trade history: hold times, the instruments you trade most, how often trades are closed by stop loss.
- Pulling candles and computing ranges or averages without exporting to a spreadsheet.
- Checking a symbol's specification (contract size, swap, trading hours) in plain language.
- Setting up a Strategy Tester run for an Expert Advisor and reading the report and tester journal back.
- Reading the Experts journal to find why an EA stopped or an order was rejected.
Every answer is only as good as the data the tool returned and the model's reading of it. Check the numbers that matter in MT5 itself.
Key takeaways
- MCP is an open standard that lets an AI app call tools. Since build 6060, MT5 ships its own MCP servers:
terminal,metaeditorandmarketdata. - Enable the server under Tools → Options → MCP, generate an API key, click Copy, and paste the config into Claude Code (
.mcp.json) or Codex (.codex\config.toml). - MT5's built-in AI Assistant can also run on Claude or GPT models with your own API key, with no external client at all.
- The ChatGPT web app only reaches remote servers, so a local MT5 needs OpenAI's Secure MCP Tunnel.
- Start on demo, with trading off, logged in with the investor password, and keep a human approving every order.
Related lessons
- What is look-ahead bias in backtesting?
- What is a martingale EA, and why does it fail?
- How do you calculate position size in trading?
- Demo trading: open a practice account
Sources
- MetaQuotes, MetaTrader 5 Help, "MCP Servers and AI Assistant": https://www.metatrader5.com/en/terminal/help/mcp_and_ai
- MetaQuotes, MetaTrader 5 Help, "Configuring Settings for AI" (AI Assistant permissions, MCP tab, Copy button, Claude Code and Codex configs): https://www.metatrader5.com/en/terminal/help/mcp_and_ai/configuration
- MetaQuotes, MetaTrader 5 Help, "Tools and Operations Supported by MCP Servers" (three servers, full tool list): https://www.metatrader5.com/en/terminal/help/mcp_and_ai/capabilities
- MetaQuotes, MetaTrader 5 release notes (build 6060, 23 July 2026: native MCP; builds 6090 to 6230: added tools, Windows 7 disabled): https://www.metatrader5.com/en/releasenotes
- Model Context Protocol, "What is the Model Context Protocol (MCP)?": https://modelcontextprotocol.io/docs/2026-07-28/getting-started/intro
- Claude Help Center, "Get started with custom connectors using remote MCP" (connections originate from Anthropic's cloud): https://support.claude.com/en/articles/11175166-get-started-with-custom-connectors-using-remote-mcp
- OpenAI Help Center, "Connecting custom MCP servers in ChatGPT" (remote only, plan availability, prompt injection warning; viewed 11 November 2026): https://help.openai.com/en/articles/12584461-connecting-custom-mcp-servers-in-chatgpt
- OpenAI, "Secure MCP Tunnel": https://developers.openai.com/api/docs/guides/secure-mcp-tunnels
- mcp-remote (stdio-to-remote bridge; MIT): https://github.com/geelen/mcp-remote
- ariadng, metatrader-mcp-server (MIT): https://github.com/ariadng/metatrader-mcp-server
- Cloudmeru, MetaTrader-5-MCP-Server / mt5-mcp (read-only design; MIT): https://github.com/Cloudmeru/MetaTrader-5-MCP-Server
- MetaQuotes, MetaTrader 5 iPhone/iPad Help, "Managing Passwords" (investor password gives read-only access, no trading operations): https://www.metatrader5.com/en/mobile-trading/iphone/help/settings_accounts/account_passwords
- Fintrix Markets MT5 price data, XAUUSD 15-minute bars, 30 October 2026 trading server day (high 4,028.70, low 3,869.31).
Put your knowledge to work
Open a Fintrix Markets account, or log in and trade CFDs on forex, gold, indices and more.



