metaeditor5-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@metaeditor5-mcp Write a simple moving average crossover EA, compile it, and backtest on EURUSD."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
metaeditor5-mcp
MCP server that lets an AI author MQL5 Expert Advisors/indicators/scripts, compile them with MetaEditor's CLI, and backtest them with MetaTrader 5's Strategy Tester — without a human driving the MetaEditor/MetaTrader GUI.
What this does and doesn't do
Does: write/read/list/delete
.mq5/.mqh/.mqproj/.setfiles under the MetaTrader data folder'sMQL5tree, compile them viaMetaEditor64.exe /compile, and run them through the Strategy Tester viaterminal64.exe /configfor historical backtesting.Doesn't: attach an EA to a live/demo chart or place any real order. Backtesting is a closed historical simulation with no live connection. Deploying an EA to actually trade is a manual step in the MetaTrader terminal GUI, and this project intentionally does not automate it.
Doesn't: accept arbitrary/absolute filesystem paths. Every path-taking tool only accepts paths relative to the MQL5 sandbox root (
Experts,Include,Indicators,Scripts,Libraries,Files), validated to reject..traversal and anything resolving outside it.
Related MCP server: Filesystem MCP Server
Requirements
Windows. MetaEditor/MetaTrader 5 desktop only ships for Windows, and this server shells out to
MetaEditor64.exe/terminal64.exedirectly, so it only runs on Windows (including inside a Windows VM) — not macOS/Linux, even if MT5 is run there under Wine.MetaTrader 5 installed (which includes MetaEditor). Any broker's installer works — the server doesn't hardcode any broker.
Node.js 18+.
Setup
git clone https://github.com/dchumari/metaeditor5-mcp.git
cd metaeditor5-mcp
npm install
npm run buildAdd to Claude Code's MCP config (.mcp.json), replacing the path below with the absolute
path to wherever you cloned this repo:
{
"mcpServers": {
"metaeditor5": {
"command": "node",
"args": ["C:\\path\\to\\metaeditor5-mcp\\dist\\index.js"]
}
}
}The server auto-detects your MetaTrader 5 installation and its data folder by scanning
%APPDATA%\MetaQuotes\Terminal\*\origin.txt. If you have more than one installation, set
MCP_MT5_INSTALL_DIR to the one you want (e.g. C:\Program Files\MetaTrader 5), or pass
installDirHint to the get_environment_info tool.
Backtesting requires an account login
Verified empirically: MetaTrader's Strategy Tester refuses to start with no account
specified ("tester not started because the account is not specified"), even for a pure
historical simulation. To use run_backtest, log into any demo or live account in the
MetaTrader 5 terminal (File → Login to Trade Account, or open a new demo account) with
"Save my login details" checked.
That's normally the only setup step needed: run_backtest resolves the login to use, in
order, from (1) the login argument, (2) the MCP_MT5_LOGIN environment variable, (3) the
account number MetaTrader already has saved as its current login (read from
config/common.ini's Login= key — verified working end-to-end). Set MCP_MT5_LOGIN
explicitly only if you have multiple saved accounts and the terminal's current one isn't the
one you want used. The account's password is never read, stored, or passed by this
server — it relies entirely on MetaTrader's own saved/remembered credentials for that
login. Never pass a password through an MCP tool call.
First backtest for a new symbol/date range may need a retry. Verified on a fresh demo
account: the Strategy Tester downloads missing history from the broker in the background,
but its own internal timeout for that (~18s) can be shorter than one authentication
round-trip on a fresh connection, causing the first attempt to fail with "no history data"
even though the download is actually still happening (visible as growing .hcc files under
bases/<server>/history/<symbol>/). Simply calling run_backtest again against the same
symbol/range once it's downloaded resolves it.
Environment variables
Variable | Purpose |
| Pin the MT5 install directory if more than one is found |
| Account number for Strategy Tester runs (see above) |
| Compile timeout (default 120000) |
| Backtest timeout (default 600000) |
Tools
Tool | Purpose |
| Resolve/re-resolve the MT5 install + data folder |
| List files/dirs under the MQL5 sandbox |
| Read a source file |
| Create/overwrite a source file |
| Delete a single file |
| Compile via MetaEditor CLI, parsed errors/warnings + |
| Run the Strategy Tester, parsed performance metrics |
| Read the MQL5 journal log |
Development
npm test # unit tests (sandbox, log parser, ini builder, report parser)
npm run dry-run -- env # exercise modules directly, no MCP client needed
npm run smoke-test # write -> compile -> (backtest if MCP_MT5_LOGIN set) -> cleanup
npm run dev # run the server directly with tsx, for local iterationVerified end-to-end
Both compile and run_backtest have been run for real against a live MetaTrader 5
installation (build 6182) with a demo account, through the actual MCP server over stdio, not
just their underlying modules:
compile's log format (src/compile/logParser.ts) was verified against realMetaEditor64.exe /logoutput, including a clean compile and one with an error and a warning — seetest/logParser.test.tsfor the captured fixture. Exit codes were confirmed unreliable (one run exited 1 with zero errors, another exited 0 with a real error), which is why success is derived only from the parsed log plus a freshly-written.ex5.run_backtest's report parsing (src/backtest/reportParser.ts) was verified against a real Strategy Tester report. Two bugs surfaced only through this real run and are now fixed:Expert=needs Windows backslashes (a forward-slash value is silently ignored, and the terminal falls back to whichever EA it last remembers running — no error at all), and the report is written directly to the data folder root rather than underTester/as might be assumed (it's now parsed there, then moved into the sandboxedFiles/.mcp/scratch dir so repeated runs don't litter your live MetaTrader data folder). The real report's labels matchedLABEL_MAP's guesses exactly for this build; if a different build/locale doesn't, the result'srawfield always carries every parsed label/value pair regardless, so nothing is silently lost — extendLABEL_MAPfrom there if needed.
Available Tools
8 toolscompileCompile an MQL5 fileA
Compiles a .mq5/.mqh/.mqproj file via MetaEditor's CLI and returns structured errors/warnings parsed from the compile log, plus the resulting .ex5 path on success. Success requires both zero parsed errors AND a freshly-written .ex5 (the process exit code is not trustworthy and is ignored).
Inputs: path (required), timeoutMs, includePath.
delete_fileDelete an MQL5 source fileB
Deletes a single file (not a directory) under the sandboxed MQL5 data folder.
Inputs: path (required).
get_environment_infoGet MetaTrader 5 environment infoA
Resolves (or re-resolves) the MetaEditor/MetaTrader 5 installation and its MQL5 data folder. Call this first, and again if you get an 'ambiguous' or 'error' result, passing installDirHint.
Inputs: installDirHint.
get_journalRead the MQL5 journal logB
Reads the terminal's MQL5 journal log for a given date (defaults to the latest).
Inputs: date, tailLines.
list_filesList MQL5 source filesA
Lists files/directories under the sandboxed MQL5 data folder (Experts, Include, Indicators, Scripts, Libraries, Files). Omit dir to see the top-level allowed folders.
Inputs: dir, recursive.
read_fileRead an MQL5 source fileA
Reads a text file (e.g. .mq5/.mqh) from under the sandboxed MQL5 data folder.
Inputs: path (required).
run_backtestRun a Strategy Tester backtestA
Runs a compiled EA through MetaTrader's Strategy Tester (a closed historical simulation - no live connection, no real orders) and returns parsed performance metrics. Requires the EA to already be compiled (call compile first). Requires an account login: the Strategy Tester refuses to start without one. Resolution order: the login argument, then MCP_MT5_LOGIN, then whichever account is currently saved/logged into this terminal (from common.ini) - so if you're already logged into a demo/live account with 'save password' checked, no login needs to be passed at all.
Inputs: period (required), symbol (required), toDate (required), fromDate (required), +8 more.
write_fileWrite an MQL5 source fileA
Creates or overwrites a .mq5/.mqh/.mqproj/.set file under the sandboxed MQL5 data folder (e.g. write an EA to "Experts/MyStrategy/MyEA.mq5"). Set overwrite:true to replace an existing file.
Inputs: path (required), content (required), overwrite, createDirs.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool has a clearly distinct purpose: file CRUD (list/read/write/delete), environment setup, compile, backtest, and journal reading. The file tools all target the same resource but with unambiguous distinct verbs, and the build/run/log tools occupy separate roles with no overlap.
Most names follow a clean verb_noun pattern (list_files, read_file, write_file, delete_file, get_environment_info, get_journal, run_backtest). Two are bare verbs (compile, run_backtest partially) which is a minor deviation but still readable and predictable.
Eight tools is well-scoped for an MQL5 file+compile+backtest workflow, with each tool earning its place covering a distinct stage of the author-test loop.
File read/write/delete, compile, backtest, and journal cover the core edit-build-test lifecycle completely. Minor gaps exist (no explicit directory creation, rename/move, or file search), but write_file's path handling likely covers directory needs for most workflows.
Maintenance
Related MCP Connectors
Let AI agents read and trade MetaTrader 5 accounts. Sign in with OAuth; read-only unless you allow.
MCP server exposing the Backtest360 engine API as tools for AI agents.
Read-only access to your MetaTrader 4 and 5 accounts for AI agents: balances, open positions, trade history with win rate, live quotes, symbol specs and candles. It cannot place, modify or close orders.
Read-only MetaTrader 5 for AI agents: balances, positions, history and prices. Sign in with OAuth.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides secure, sandboxed file system access for AI assistants to read, write, and manage project files with controlled command execution capabilities, all confined to a designated workspace directory.MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with a sandboxed filesystem via MCP tools for reading, writing, searching, and monitoring files, including batch processing and resource discovery for resume management.-
- FlicenseNot gradedqualityBmaintenanceEnables reproducible evaluation of AI coding agents by exposing repository inspection, code editing, test running, and deterministic verification through MCP tools.-
- AlicenseAqualityBmaintenanceEnables AI agents to perform software engineering tasks inside an isolated, deterministic sandbox—exploring repositories, reproducing failures, applying patches, running tests, and verifying solutions against hidden suites through MCP tools.8MIT