mcp-mt5
Click on "Install 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., "@mcp-mt5compile and deploy the moving average EA"
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.
mcp-mt5
Model Context Protocol server for the MetaTrader 4/5 build pipeline. Compile MQL sources, deploy compiled EAs, run Strategy Tester, parse reports, tail logs — all driven by an LLM agent without touching the MetaTrader UI.
What this is — and what it isn't
✅ This server | ❌ Not this server |
MetaTrader dev harness — compile, deploy, backtest, parse | Live trading (orders, positions, quotes) |
Wraps | Wraps the |
Runs entirely offline against installed terminal | Connects to a broker server |
Iterates strategies before they go live | Executes strategies in production |
Use case: an LLM agent edits
.mq5source → compiles → deploys → runs Strategy Tester → reads report → adjusts → repeats. No broker login, no human in the loop, no risk of real-money execution.
For runtime trading, pair this with a live-trading MCP — they target different layers and compose well.
Related MCP server: CODESYS MCP Toolkit
Tools
The server exposes 32 tools and 3 MCP resources across nine categories.
🔍 Discovery & terminal selection
Tool | Description |
| Dump resolved paths, terminal hash, edition, and missing-component issues |
| Enumerate every MT4/5 terminal data folder under |
| Switch the active terminal data folder mid-session by origin path, hash, or install dir — handy for testing across multiple brokers |
🔨 Build & deploy
Tool | Description |
| Invoke MetaEditor CLI on a |
| Compile, then copy the resulting |
| Same as |
| Compile + deploy + run a 1-day headless backtest + scan the journal for runtime errors. Catches problems that pass |
| Copy a compiled binary into |
| Copy a |
| Enumerate |
🔎 Source analysis
Tool | Description |
| Parse |
| Auto-build a |
| Recursive |
| Grep a symbol across MQL files, skipping comments and string literals |
| LOC, function count, max nesting per file — or aggregated across an entire tree |
| Pull MetaEditor |
| Detect duplicate magic-number assignments across the project |
⚠️ Lint & validation
Tool | Description |
| Structural rules: missing |
| Flag MT4-style API calls ( |
| Sanity-check a |
🎨 Format
Tool | Description |
| Format a source file via |
| Same as above but reports whether changes are needed without writing the file |
✏️ Refactor
Tool | Description |
| Whole-word rename across all MQL files in a tree, with |
| Brace-aware extraction of a contiguous block into a new helper function — inline or into an external |
📊 Strategy Tester
Tool | Description |
| Programmatically update keys in a |
| Launch |
| Best-effort parser for the latest |
| Sort optimization passes by a chosen criterion and return the top N |
| Locate and parse the latest tester HTML report into a structured |
| Diff two tester reports key-by-key with absolute and percent deltas |
| Verify a candidate report stays within guard thresholds vs a baseline (e.g. "net_profit may not drop more than 5%") |
|
|
📝 Logs & snapshots
Tool | Description |
| Tail the last N lines of either |
| Freeze a copy of source files into a timestamped folder with a |
| Enumerate previously captured snapshots |
📡 MCP resources
Live, re-readable URIs that an MCP client can poll instead of calling a tool repeatedly.
URI | Description |
| Latest tail of |
| Today's daily MT5 journal log |
| Most recent Strategy Tester journal |
Quick start
Install
pip install mcp-mt5Requires Windows + an installed MetaTrader 4 or 5 terminal.
Register with an MCP client
Most MCP clients accept a JSON entry under mcpServers. The server inherits its configuration from environment variables:
{
"mcpServers": {
"mt5": {
"command": "mcp-mt5",
"env": {
"MT5_INSTALL": "C:\\Program Files\\MetaTrader 5"
}
}
}
}Refer to your client's documentation for the exact config file location.
Verify the install
Once registered, ask your agent to call env_info:
{
"edition": "mt5",
"install": "C:\\Program Files\\MetaTrader 5",
"terminal_hash": "<32-char-hex-hash>",
"metaeditor": "C:\\Program Files\\MetaTrader 5\\MetaEditor64.exe",
"experts_dir": "C:\\Users\\<you>\\AppData\\Roaming\\MetaQuotes\\Terminal\\<hash>\\MQL5\\Experts",
"issues": []
}An empty issues array means everything is wired up correctly.
Configuration
Resolution priority for the MetaTrader install + data folder:
Explicit env vars (below)
Auto-scan of
%APPDATA%\MetaQuotes\Terminal\*\origin.txtfor a folder whose origin matchesMT5_INSTALLPortable mode fallback (data colocated with install dir)
Env var | Default | Notes |
|
| Install dir containing |
| (auto-detected) |
|
| (auto-detected) | 32-char folder name |
|
| Set to |
MT4 support
Set MT5_EDITION=mt4 and point MT5_INSTALL at your MT4 install. The server switches to metaeditor.exe (32-bit), terminal.exe, and the MQL4/ data tree automatically.
Example workflow
A typical LLM-driven iteration loop:
1. env_info → verify paths
2. compile_and_deploy source="MyEA.mq5" → 0 errors, .ex5 deployed ✅
3. patch_tester_ini config="tester.ini" updates={
"Tester.Symbol": "EURUSD",
"Tester.FromDate": "2025.01.01",
"TesterInputs.RiskPct": "1.5"
}
4. run_backtest config="tester.ini" wait=true
5. read_tester_report → summary.net_profit = 1234.56
summary.profit_factor = 1.45
6. tail_log mode="tester" lines=200 structured=true → diagnose journal warnings
7. <edit Signal.mqh based on findings>
8. → loop back to step 2A sample tester.ini
; Launch: terminal64.exe /config:tester.ini
; Period codes: M1=1, M5=5, M15=15, H1=16385, H4=16388, D1=16408
; Model: 0=Every tick, 1=1 min OHLC, 4=Real ticks
[Tester]
Expert=MyEA
Symbol=EURUSD
Period=M15
Model=1
FromDate=2024.01.01
ToDate=2024.12.31
Deposit=10000
Currency=USD
Leverage=500
Visual=0
ShutdownTerminal=1 ; required so run_backtest can wait for the run to finish
Report=tester_report
[TesterInputs]
; ParamName=value||start||step||stop||(N=fixed|Y=optimize)
; RiskPct=1.0||0.1||0.1||3.0||NA more complete sample lives at examples/tester.ini.
Development
git clone https://github.com/PHUICMT/mcp-mt5
cd mcp-mt5
pip install -e ".[dev]"
pytest # runs the 18-test suite
ruff check src tests # lintsCI runs on Windows for Python 3.10, 3.11, and 3.12 against every push to main. Tagging a release (e.g. v0.2.0) triggers an OIDC publish to PyPI.
Project layout
mcp-mt5/
├── src/mcp_mt5/
│ ├── server.py # FastMCP tool definitions
│ ├── paths.py # Layout detection + origin.txt scan
│ └── parsers.py # Compile log + tester HTML report parsers
├── tests/ # 18 pytest tests, no live MT5 required
├── examples/ # Sample tester.ini + client config
└── .github/workflows/ # CI + PyPI releaseLimitations
Windows-only. MetaTrader CLI binaries don't ship for Linux/macOS. Wine ports may work but are untested.
No live broker access. This server intentionally never authenticates to a broker. Use a separate MCP server for runtime trading.
Tester report parsing is best-effort. MetaTrader's HTML output isn't a stable schema; the raw HTML is also returned alongside the parsed structure so you can fall back to text inspection when needed.
Optimization runs are not parsed yet. Single-pass backtests are fully supported;
.optresults are on the roadmap.
Roadmap
All v0.3.x roadmap items shipped in v0.4.0. Future ideas:
Real tree-sitter MQL grammar for
extract_function(current implementation is brace-counting + regex)WebSocket transport for long-lived sessions (currently stdio only)
Linux/Wine port for non-Windows agents
License
MIT © 2026 PHUICMT
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/PHUICMT/mcp-mt5'
If you have feedback or need assistance with the MCP directory API, please join our Discord server