Skip to main content
Glama
metaeditor5-mcp
by dchumari

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/.set files under the MetaTrader data folder's MQL5 tree, compile them via MetaEditor64.exe /compile, and run them through the Strategy Tester via terminal64.exe /config for 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.exe directly, 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 build

Add 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

MCP_MT5_INSTALL_DIR

Pin the MT5 install directory if more than one is found

MCP_MT5_LOGIN

Account number for Strategy Tester runs (see above)

MCP_MT5_COMPILE_TIMEOUT_MS

Compile timeout (default 120000)

MCP_MT5_BACKTEST_TIMEOUT_MS

Backtest timeout (default 600000)

Tools

Tool

Purpose

get_environment_info

Resolve/re-resolve the MT5 install + data folder

list_files

List files/dirs under the MQL5 sandbox

read_file

Read a source file

write_file

Create/overwrite a source file

delete_file

Delete a single file

compile

Compile via MetaEditor CLI, parsed errors/warnings + .ex5 path

run_backtest

Run the Strategy Tester, parsed performance metrics

get_journal

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 iteration

Verified 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 real MetaEditor64.exe /log output, including a clean compile and one with an error and a warning — see test/logParser.test.ts for 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 under Tester/ as might be assumed (it's now parsed there, then moved into the sandboxed Files/.mcp/ scratch dir so repeated runs don't litter your live MetaTrader data folder). The real report's labels matched LABEL_MAP's guesses exactly for this build; if a different build/locale doesn't, the result's raw field always carries every parsed label/value pair regardless, so nothing is silently lost — extend LABEL_MAP from there if needed.

Available Tools

8 tools
compileCompile 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

    A3.9/5.0

    Scored across 8 tools

    Disambiguation5/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides 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
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables 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.
      -
    • A
      license
      A
      quality
      B
      maintenance
      Enables 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.
      8
      MIT