mcp-mt5 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_mt5-0.3.0/.github/workflows/ci.yml +33 -0
- mcp_mt5-0.3.0/.github/workflows/release.yml +96 -0
- mcp_mt5-0.3.0/.gitignore +17 -0
- mcp_mt5-0.3.0/CHANGELOG.md +56 -0
- mcp_mt5-0.3.0/LICENSE +21 -0
- mcp_mt5-0.3.0/PKG-INFO +301 -0
- mcp_mt5-0.3.0/README.md +274 -0
- mcp_mt5-0.3.0/examples/claude_desktop_config.json +10 -0
- mcp_mt5-0.3.0/examples/tester.ini +26 -0
- mcp_mt5-0.3.0/pyproject.toml +47 -0
- mcp_mt5-0.3.0/src/mcp_mt5/__init__.py +2 -0
- mcp_mt5-0.3.0/src/mcp_mt5/analysis.py +279 -0
- mcp_mt5-0.3.0/src/mcp_mt5/formatting.py +67 -0
- mcp_mt5-0.3.0/src/mcp_mt5/lint.py +169 -0
- mcp_mt5-0.3.0/src/mcp_mt5/optimization.py +94 -0
- mcp_mt5-0.3.0/src/mcp_mt5/parsers.py +165 -0
- mcp_mt5-0.3.0/src/mcp_mt5/paths.py +149 -0
- mcp_mt5-0.3.0/src/mcp_mt5/refactor.py +39 -0
- mcp_mt5-0.3.0/src/mcp_mt5/reports.py +89 -0
- mcp_mt5-0.3.0/src/mcp_mt5/server.py +660 -0
- mcp_mt5-0.3.0/src/mcp_mt5/snapshot.py +65 -0
- mcp_mt5-0.3.0/tests/__init__.py +0 -0
- mcp_mt5-0.3.0/tests/test_analysis.py +114 -0
- mcp_mt5-0.3.0/tests/test_lint.py +71 -0
- mcp_mt5-0.3.0/tests/test_misc.py +88 -0
- mcp_mt5-0.3.0/tests/test_parsers.py +69 -0
- mcp_mt5-0.3.0/tests/test_paths.py +59 -0
- mcp_mt5-0.3.0/tests/test_server_tools.py +124 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: windows-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint
|
|
30
|
+
run: ruff check src tests
|
|
31
|
+
|
|
32
|
+
- name: Test
|
|
33
|
+
run: pytest -v --cov=mcp_mt5 --cov-report=term-missing
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
outputs:
|
|
14
|
+
version: ${{ steps.meta.outputs.version }}
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
|
|
22
|
+
- name: Build wheel + sdist
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip build
|
|
25
|
+
python -m build
|
|
26
|
+
|
|
27
|
+
- name: Capture version
|
|
28
|
+
id: meta
|
|
29
|
+
run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
|
|
30
|
+
|
|
31
|
+
- name: Upload dist artifacts
|
|
32
|
+
uses: actions/upload-artifact@v4
|
|
33
|
+
with:
|
|
34
|
+
name: dist
|
|
35
|
+
path: dist/
|
|
36
|
+
|
|
37
|
+
github-release:
|
|
38
|
+
needs: build
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
permissions:
|
|
41
|
+
contents: write
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v4
|
|
44
|
+
with:
|
|
45
|
+
fetch-depth: 0
|
|
46
|
+
|
|
47
|
+
- uses: actions/download-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: dist
|
|
50
|
+
path: dist/
|
|
51
|
+
|
|
52
|
+
- name: Generate release notes
|
|
53
|
+
id: notes
|
|
54
|
+
run: |
|
|
55
|
+
version="${GITHUB_REF#refs/tags/v}"
|
|
56
|
+
notes_file=$(mktemp)
|
|
57
|
+
if [ -f CHANGELOG.md ]; then
|
|
58
|
+
awk -v ver="$version" '
|
|
59
|
+
/^## / {
|
|
60
|
+
if (capture) exit
|
|
61
|
+
if ($0 ~ ver) { capture = 1; next }
|
|
62
|
+
}
|
|
63
|
+
capture { print }
|
|
64
|
+
' CHANGELOG.md > "$notes_file"
|
|
65
|
+
fi
|
|
66
|
+
if [ ! -s "$notes_file" ]; then
|
|
67
|
+
echo "Release $version" > "$notes_file"
|
|
68
|
+
fi
|
|
69
|
+
{
|
|
70
|
+
echo 'body<<EOF'
|
|
71
|
+
cat "$notes_file"
|
|
72
|
+
echo 'EOF'
|
|
73
|
+
} >> "$GITHUB_OUTPUT"
|
|
74
|
+
|
|
75
|
+
- name: Create GitHub Release
|
|
76
|
+
uses: softprops/action-gh-release@v2
|
|
77
|
+
with:
|
|
78
|
+
name: ${{ needs.build.outputs.version }}
|
|
79
|
+
body: ${{ steps.notes.outputs.body }}
|
|
80
|
+
files: dist/*
|
|
81
|
+
generate_release_notes: true
|
|
82
|
+
|
|
83
|
+
publish-pypi:
|
|
84
|
+
needs: build
|
|
85
|
+
runs-on: ubuntu-latest
|
|
86
|
+
permissions:
|
|
87
|
+
id-token: write
|
|
88
|
+
continue-on-error: true
|
|
89
|
+
steps:
|
|
90
|
+
- uses: actions/download-artifact@v4
|
|
91
|
+
with:
|
|
92
|
+
name: dist
|
|
93
|
+
path: dist/
|
|
94
|
+
|
|
95
|
+
- name: Publish to PyPI
|
|
96
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
mcp_mt5-0.3.0/.gitignore
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0 — 2026-05-04
|
|
4
|
+
|
|
5
|
+
Full dev-loop expansion: 18 new tools across 7 modules.
|
|
6
|
+
|
|
7
|
+
### Source analysis
|
|
8
|
+
- `extract_inputs` — parse `input <type> <name> = <default>;` declarations into JSON
|
|
9
|
+
- `gen_tester_inputs` — auto-build a `[TesterInputs]` block from EA source (translates `PERIOD_*` enums to numeric codes)
|
|
10
|
+
- `resolve_includes` — recursive `#include` resolution, reports missing files
|
|
11
|
+
- `find_symbol` — grep MQL files skipping comments and string literals
|
|
12
|
+
- `code_metrics` — LOC, function count, max nesting per file or aggregated across a tree
|
|
13
|
+
- `extract_doc` — pull MetaEditor `//+--+ //| ... +--+` doc blocks into markdown
|
|
14
|
+
- `find_magic_collision` — detect duplicate magic-number assignments
|
|
15
|
+
|
|
16
|
+
### Lint / validation
|
|
17
|
+
- `syntax_check` — MetaEditor `/s` syntax-only mode for fast feedback
|
|
18
|
+
- `lint_basic` — structural rules (missing `OnInit`/`OnDeinit`, unused inputs, hardcoded magic, hardcoded symbol)
|
|
19
|
+
- `check_deprecated` — flag MT4-style API calls (`OrderSend`, `Ask`, `AccountBalance`, …) with CTrade-style replacements
|
|
20
|
+
- `validate_tester_ini` — required keys, date format, numeric sanity, cross-check inputs vs EA source
|
|
21
|
+
|
|
22
|
+
### Formatting
|
|
23
|
+
- `format_mql` / `format_check` — clang-format wrap (treats MQL as C++ with an MQL-friendly default style)
|
|
24
|
+
|
|
25
|
+
### Refactor
|
|
26
|
+
- `rename_symbol` — whole-word rename across the project, with `dry_run` preview
|
|
27
|
+
|
|
28
|
+
### Optimization
|
|
29
|
+
- `parse_optimization` — best-effort `.opt` binary reader
|
|
30
|
+
- `top_passes` — sort optimization passes by criterion
|
|
31
|
+
|
|
32
|
+
### Reports
|
|
33
|
+
- `compare_reports` — diff two tester reports key-by-key with absolute and percent deltas
|
|
34
|
+
- `regression_check` — guard thresholds (e.g. "net_profit may not drop more than 5%") with violation reporting
|
|
35
|
+
|
|
36
|
+
### Snapshots
|
|
37
|
+
- `snapshot_sources` — freeze a copy of source files into a timestamped manifest folder
|
|
38
|
+
- `list_snapshots` — enumerate previously captured snapshots
|
|
39
|
+
|
|
40
|
+
### Internal
|
|
41
|
+
- New modules: `analysis.py`, `lint.py`, `formatting.py`, `refactor.py`, `optimization.py`, `reports.py`, `snapshot.py`
|
|
42
|
+
- Test suite expanded from 18 → 38 cases
|
|
43
|
+
|
|
44
|
+
## 0.2.0 — 2026-05-04
|
|
45
|
+
|
|
46
|
+
- Refactor into `paths.py` (layout detection) + `parsers.py` (compile log + tester report) + `server.py` (MCP tools)
|
|
47
|
+
- Auto-detect terminal data folder via `origin.txt` scan
|
|
48
|
+
- MT4 support (`MT5_EDITION=mt4`, `metaeditor.exe`, `MQL4/` tree)
|
|
49
|
+
- Structured tester report parser (summary key/values + trade row detection)
|
|
50
|
+
- New tools: `list_terminals`, `kill_terminal`, `compile_and_deploy`, `patch_tester_ini`, `install_include`
|
|
51
|
+
- Pytest test suite (18 tests covering parsers, paths, server tools)
|
|
52
|
+
- GitHub Actions CI + PyPI release workflow
|
|
53
|
+
|
|
54
|
+
## 0.1.0
|
|
55
|
+
|
|
56
|
+
- Initial release: `compile`, `run_backtest`, `tail_log`, `deploy_ea`, `list_experts`, `read_tester_report`, `env_info`
|
mcp_mt5-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PHUICMT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mcp_mt5-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-mt5
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: MCP server for MetaTrader 4/5 build pipeline — compile, deploy, backtest, parse reports
|
|
5
|
+
Project-URL: Homepage, https://github.com/PHUICMT/mcp-mt5
|
|
6
|
+
Project-URL: Issues, https://github.com/PHUICMT/mcp-mt5/issues
|
|
7
|
+
Author-email: PHUICMT <icmtchannel@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: mcp,metatrader,model-context-protocol,mql4,mql5,mt4,mt5,trading
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: mcp>=1.2.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# mcp-mt5
|
|
29
|
+
|
|
30
|
+
> **Model Context Protocol server for the MetaTrader 4/5 build pipeline.**
|
|
31
|
+
> Compile MQL sources, deploy compiled EAs, run Strategy Tester, parse reports, tail logs — all driven by an LLM agent without touching the MetaTrader UI.
|
|
32
|
+
|
|
33
|
+
[](https://github.com/PHUICMT/mcp-mt5/actions/workflows/ci.yml)
|
|
34
|
+
[](https://www.python.org/)
|
|
35
|
+
[](LICENSE)
|
|
36
|
+
[](https://www.metaquotes.net/)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## What this is — and what it isn't
|
|
41
|
+
|
|
42
|
+
| ✅ This server | ❌ Not this server |
|
|
43
|
+
|----------------|--------------------|
|
|
44
|
+
| MetaTrader **dev harness** — compile, deploy, backtest, parse | Live trading (orders, positions, quotes) |
|
|
45
|
+
| Wraps `MetaEditor64.exe` / `terminal64.exe` CLI directly | Wraps the `MetaTrader5` Python package |
|
|
46
|
+
| Runs entirely offline against installed terminal | Connects to a broker server |
|
|
47
|
+
| Iterates strategies *before* they go live | Executes strategies in production |
|
|
48
|
+
|
|
49
|
+
> **Use case:** an LLM agent edits `.mq5` source → compiles → deploys → runs Strategy Tester → reads report → adjusts → repeats. No broker login, no human in the loop, no risk of real-money execution.
|
|
50
|
+
|
|
51
|
+
For runtime trading, pair this with a live-trading MCP — they target different layers and compose well.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Tools
|
|
56
|
+
|
|
57
|
+
The server exposes 29 tools across eight categories.
|
|
58
|
+
|
|
59
|
+
### 🔍 Discovery
|
|
60
|
+
|
|
61
|
+
| Tool | Description |
|
|
62
|
+
|------|-------------|
|
|
63
|
+
| `env_info` | Dump resolved paths, terminal hash, edition, and missing-component issues |
|
|
64
|
+
| `list_terminals` | Enumerate every MT4/5 terminal data folder under `%APPDATA%\MetaQuotes\Terminal` along with each `origin.txt` install path |
|
|
65
|
+
|
|
66
|
+
### 🔨 Build & deploy
|
|
67
|
+
|
|
68
|
+
| Tool | Description |
|
|
69
|
+
|------|-------------|
|
|
70
|
+
| `compile` | Invoke MetaEditor CLI on a `.mq4`/`.mq5`/`.mqh` source. Returns structured `errors[]`/`warnings[]` (file, line, column, error code, message) plus log excerpt |
|
|
71
|
+
| `compile_and_deploy` | Compile, then copy the resulting `.ex4`/`.ex5` into the terminal's `Experts/` folder in one call |
|
|
72
|
+
| `syntax_check` | Same as `compile` but uses MetaEditor's `/s` syntax-only mode for faster feedback |
|
|
73
|
+
| `deploy_ea` | Copy a compiled binary into `Experts/` (with optional rename) |
|
|
74
|
+
| `install_include` | Copy a `.mqh` header into the terminal `Include/` folder — handy for libraries like `LiveLog.mqh` |
|
|
75
|
+
| `list_experts` | Enumerate `Experts/` recursively with size and modification time |
|
|
76
|
+
|
|
77
|
+
### 🔎 Source analysis
|
|
78
|
+
|
|
79
|
+
| Tool | Description |
|
|
80
|
+
|------|-------------|
|
|
81
|
+
| `extract_inputs` | Parse `input <type> <name> = <default>;` declarations into structured records |
|
|
82
|
+
| `gen_tester_inputs` | Auto-build a `[TesterInputs]` block from EA source (translates `PERIOD_*` enums to numeric codes), optionally write into an existing `tester.ini` |
|
|
83
|
+
| `resolve_includes` | Recursive `#include` resolution that reports missing files and circular references |
|
|
84
|
+
| `find_symbol` | Grep a symbol across MQL files, skipping comments and string literals |
|
|
85
|
+
| `code_metrics` | LOC, function count, max nesting per file — or aggregated across an entire tree |
|
|
86
|
+
| `extract_doc` | Pull MetaEditor `//+--+ //\| ... +--+` doc blocks out as markdown |
|
|
87
|
+
| `find_magic_collision` | Detect duplicate magic-number assignments across the project |
|
|
88
|
+
|
|
89
|
+
### ⚠️ Lint & validation
|
|
90
|
+
|
|
91
|
+
| Tool | Description |
|
|
92
|
+
|------|-------------|
|
|
93
|
+
| `lint_basic` | Structural rules: missing `OnInit`/`OnDeinit`, unused `input`s, hardcoded magic numbers, hardcoded symbol literals |
|
|
94
|
+
| `check_deprecated` | Flag MT4-style API calls (`OrderSend`, `Ask`, `AccountBalance`, …) with `CTrade`/MT5-API replacement suggestions |
|
|
95
|
+
| `validate_tester_ini` | Sanity-check a `tester.ini` (required keys, date format, numeric ranges) and cross-check `[TesterInputs]` against the EA source declarations |
|
|
96
|
+
|
|
97
|
+
### 🎨 Format
|
|
98
|
+
|
|
99
|
+
| Tool | Description |
|
|
100
|
+
|------|-------------|
|
|
101
|
+
| `format_mql` | Format a source file via `clang-format` (treats MQL as C++ with an MQL-friendly default style) |
|
|
102
|
+
| `format_check` | Same as above but reports whether changes are needed without writing the file |
|
|
103
|
+
|
|
104
|
+
### ✏️ Refactor
|
|
105
|
+
|
|
106
|
+
| Tool | Description |
|
|
107
|
+
|------|-------------|
|
|
108
|
+
| `rename_symbol` | Whole-word rename across all MQL files in a tree, with `dry_run` preview |
|
|
109
|
+
|
|
110
|
+
### 📊 Strategy Tester
|
|
111
|
+
|
|
112
|
+
| Tool | Description |
|
|
113
|
+
|------|-------------|
|
|
114
|
+
| `patch_tester_ini` | Programmatically update keys in a `tester.ini` (e.g. `Tester.Symbol`, `Tester.FromDate`, `TesterInputs.RiskPct`) before running |
|
|
115
|
+
| `run_backtest` | Launch `terminal64.exe /config:tester.ini`, optionally headless (when `ShutdownTerminal=1`), and return the latest tester log path |
|
|
116
|
+
| `parse_optimization` | Best-effort parser for the latest `.opt` (optimization passes) binary file |
|
|
117
|
+
| `top_passes` | Sort optimization passes by a chosen criterion and return the top *N* |
|
|
118
|
+
| `read_tester_report` | Locate and parse the latest tester HTML report into a structured `summary` (net profit, profit factor, drawdown, trade counts, etc.) plus a sample of trade rows |
|
|
119
|
+
| `compare_reports` | Diff two tester reports key-by-key with absolute and percent deltas |
|
|
120
|
+
| `regression_check` | Verify a candidate report stays within guard thresholds vs a baseline (e.g. "net_profit may not drop more than 5%") |
|
|
121
|
+
| `kill_terminal` | `taskkill` if the terminal hangs |
|
|
122
|
+
|
|
123
|
+
### 📝 Logs & snapshots
|
|
124
|
+
|
|
125
|
+
| Tool | Description |
|
|
126
|
+
|------|-------------|
|
|
127
|
+
| `tail_log` | Tail the last *N* lines of either `Files/LiveLog.txt`, the daily `Logs/YYYYMMDD.log`, or the most recent tester log. Optional structured parse into `{ts, source, message}` records |
|
|
128
|
+
| `snapshot_sources` | Freeze a copy of source files into a timestamped folder with a `manifest.json` |
|
|
129
|
+
| `list_snapshots` | Enumerate previously captured snapshots |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Quick start
|
|
134
|
+
|
|
135
|
+
### Install
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pip install mcp-mt5
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
> Requires Windows + an installed MetaTrader 4 or 5 terminal.
|
|
142
|
+
|
|
143
|
+
### Register with an MCP client
|
|
144
|
+
|
|
145
|
+
Most MCP clients accept a JSON entry under `mcpServers`. The server inherits its configuration from environment variables:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"mcpServers": {
|
|
150
|
+
"mt5": {
|
|
151
|
+
"command": "mcp-mt5",
|
|
152
|
+
"env": {
|
|
153
|
+
"MT5_INSTALL": "C:\\Program Files\\MetaTrader 5"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Refer to your client's documentation for the exact config file location.
|
|
161
|
+
|
|
162
|
+
### Verify the install
|
|
163
|
+
|
|
164
|
+
Once registered, ask your agent to call `env_info`:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"edition": "mt5",
|
|
169
|
+
"install": "C:\\Program Files\\MetaTrader 5",
|
|
170
|
+
"terminal_hash": "D0E8209F77C8CF37AD8BF550E51FF075",
|
|
171
|
+
"metaeditor": "C:\\Program Files\\MetaTrader 5\\MetaEditor64.exe",
|
|
172
|
+
"experts_dir": "C:\\Users\\...\\MQL5\\Experts",
|
|
173
|
+
"issues": []
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
An empty `issues` array means everything is wired up correctly.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Configuration
|
|
182
|
+
|
|
183
|
+
Resolution priority for the MetaTrader install + data folder:
|
|
184
|
+
|
|
185
|
+
1. **Explicit env vars** (below)
|
|
186
|
+
2. **Auto-scan** of `%APPDATA%\MetaQuotes\Terminal\*\origin.txt` for a folder whose origin matches `MT5_INSTALL`
|
|
187
|
+
3. **Portable mode** fallback (data colocated with install dir)
|
|
188
|
+
|
|
189
|
+
| Env var | Default | Notes |
|
|
190
|
+
|---------|---------|-------|
|
|
191
|
+
| `MT5_INSTALL` | `C:\Program Files\MetaTrader 5` | Install dir containing `terminal64.exe` |
|
|
192
|
+
| `MT5_DATA` | _(auto-detected)_ | `%APPDATA%\MetaQuotes\Terminal\<hash>` |
|
|
193
|
+
| `MT5_TERMINAL_HASH` | _(auto-detected)_ | 32-char folder name |
|
|
194
|
+
| `MT5_EDITION` | `mt5` | Set to `mt4` for MetaTrader 4 |
|
|
195
|
+
|
|
196
|
+
### MT4 support
|
|
197
|
+
|
|
198
|
+
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.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Example workflow
|
|
203
|
+
|
|
204
|
+
A typical LLM-driven iteration loop:
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
1. env_info → verify paths
|
|
208
|
+
2. compile_and_deploy source="MyEA.mq5" → 0 errors, .ex5 deployed ✅
|
|
209
|
+
3. patch_tester_ini config="tester.ini" updates={
|
|
210
|
+
"Tester.Symbol": "EURUSD",
|
|
211
|
+
"Tester.FromDate": "2025.01.01",
|
|
212
|
+
"TesterInputs.RiskPct": "1.5"
|
|
213
|
+
}
|
|
214
|
+
4. run_backtest config="tester.ini" wait=true
|
|
215
|
+
5. read_tester_report → summary.net_profit = 1234.56
|
|
216
|
+
summary.profit_factor = 1.45
|
|
217
|
+
6. tail_log mode="tester" lines=200 structured=true → diagnose journal warnings
|
|
218
|
+
7. <edit Signal.mqh based on findings>
|
|
219
|
+
8. → loop back to step 2
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## A sample `tester.ini`
|
|
225
|
+
|
|
226
|
+
```ini
|
|
227
|
+
; Launch: terminal64.exe /config:tester.ini
|
|
228
|
+
; Period codes: M1=1, M5=5, M15=15, H1=16385, H4=16388, D1=16408
|
|
229
|
+
; Model: 0=Every tick, 1=1 min OHLC, 4=Real ticks
|
|
230
|
+
|
|
231
|
+
[Tester]
|
|
232
|
+
Expert=MyEA
|
|
233
|
+
Symbol=EURUSD
|
|
234
|
+
Period=M15
|
|
235
|
+
Model=1
|
|
236
|
+
FromDate=2024.01.01
|
|
237
|
+
ToDate=2024.12.31
|
|
238
|
+
Deposit=10000
|
|
239
|
+
Currency=USD
|
|
240
|
+
Leverage=500
|
|
241
|
+
Visual=0
|
|
242
|
+
ShutdownTerminal=1 ; required so run_backtest can wait for the run to finish
|
|
243
|
+
Report=tester_report
|
|
244
|
+
|
|
245
|
+
[TesterInputs]
|
|
246
|
+
; ParamName=value||start||step||stop||(N=fixed|Y=optimize)
|
|
247
|
+
; RiskPct=1.0||0.1||0.1||3.0||N
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
A more complete sample lives at [`examples/tester.ini`](examples/tester.ini).
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Development
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
git clone https://github.com/PHUICMT/mcp-mt5
|
|
258
|
+
cd mcp-mt5
|
|
259
|
+
pip install -e ".[dev]"
|
|
260
|
+
pytest # runs the 18-test suite
|
|
261
|
+
ruff check src tests # lints
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
CI 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.
|
|
265
|
+
|
|
266
|
+
### Project layout
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
mcp-mt5/
|
|
270
|
+
├── src/mcp_mt5/
|
|
271
|
+
│ ├── server.py # FastMCP tool definitions
|
|
272
|
+
│ ├── paths.py # Layout detection + origin.txt scan
|
|
273
|
+
│ └── parsers.py # Compile log + tester HTML report parsers
|
|
274
|
+
├── tests/ # 18 pytest tests, no live MT5 required
|
|
275
|
+
├── examples/ # Sample tester.ini + client config
|
|
276
|
+
└── .github/workflows/ # CI + PyPI release
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Limitations
|
|
282
|
+
|
|
283
|
+
- **Windows-only.** MetaTrader CLI binaries don't ship for Linux/macOS. Wine ports may work but are untested.
|
|
284
|
+
- **No live broker access.** This server intentionally never authenticates to a broker. Use a separate MCP server for runtime trading.
|
|
285
|
+
- **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.
|
|
286
|
+
- **Optimization runs are not parsed yet.** Single-pass backtests are fully supported; `.opt` results are on the roadmap.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Roadmap
|
|
291
|
+
|
|
292
|
+
- Cross-broker terminal selection helper (`select_terminal` by origin path or hash)
|
|
293
|
+
- Long-running log subscription via MCP resources
|
|
294
|
+
- Smoke-test runner that boots a 1-day Strategy Tester pass and asserts no runtime errors
|
|
295
|
+
- AST-based `extract_function` refactor (currently regex-based rename only)
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
[MIT](LICENSE) © 2026 PHUICMT
|