
MetaTrader 5 MCP Bridge
io.github.vincentwongso由 GitHub 帳號 vincentwongso 發布v1.4.2更新於 Oct 24, 2026
Let an AI agent read and trade a MetaTrader 5 account over MCP, behind a human-approval gate.
概覽
一個本機 MCP 橋接服務,讓 AI 助理讀取 MetaTrader 5 帳戶並下單、改單、取消或平倉,可選人工核准關卡。
- 可以做什麼
- 讀取帳戶資訊、報價、持倉、掛單、成交歷史與 OHLC K 線,並提供券商端保證金估算和僅限 Windows 的原生圖表截圖。下單、改單、取消與平倉,每次呼叫都經過預檢、可選的人工確認、冪等處理與稽核日誌。訂閱帳戶、持倉與依品種報價的即時快照,並接收變更通知。
- 適用情境
- 適合想讓 AI 代理監控 MetaTrader 5 帳戶並代為交易的交易者,建議先在模擬帳戶試用。也適合需要對代理發起的訂單保留人工核准步驟與可重播稽核紀錄的情境。
- 執行需求
- 以 Python 3.10+ 本機程序執行(PyPI 套件,可用 uvx 或 python -m 啟動),Windows 原生執行,Linux 透過一體化 Docker 映像執行。需要已登入券商並開啟自動交易(AlgoTrading)的 MetaTrader 5 終端機。選用環境變數 MT5_LOGIN、MT5_PASSWORD 與 MT5_SERVER 可覆寫終端機登入資訊,密碼僅透過環境變數提供。圖表截圖需要圖形介面終端機與另行安裝的 MQL5 專家顧問。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 MetaTrader 5 MCP Bridge,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
MetaTrader 5 MCP Bridge
Let an AI agent manage your MetaTrader 5 account over Model Context Protocol - with configurable human approval gate.
[PyPI version] [PyPI downloads] [Python] [License: MIT] [Tests] [GitHub stars] [MCP] [Ruff]
[mt5-mcp demo: an AI agent places and closes a live trade over MCP]
A Hermes agent placing then closing a real 0.01-lot trade on a demo account, end-to-end over MCP on Linux.
[The same round-trip in MetaTrader 5's History tab]
Not a mock-up - the same round-trip in MetaTrader 5's own History tab; the tickets and balance match the recording.
⚠️ This software places real trades through your MetaTrader 5 terminal with real orders and irreversible fills. Read DISCLAIMER.md and SECURITY.md before connecting it to a live account. Always test using your demo account first.
Runs locally - in the same process tree as your agent, no cloud, no telemetry. Windows (native) or Linux (via Docker); Python 3.10+.
📖 The story behind this: this project is built step by step in Wiring AI agent into MetaTrader 5, Part 1 of the Trade with AI agent series on the Fintrix engineering blog.
What it is
mt5-mcp lets an AI agent read your MetaTrader 5 account and place trades
through it, over the Model Context Protocol.
- 12 read-only tools: account, quotes, positions, orders, history, OHLC bars, broker-authoritative margin estimates, and native chart screenshots (Windows). No consent gate.
- 4 mutating tools:
place_order,modify_order,cancel_order,close_position, each behind a preflight + human-consent + idempotency + audit layer. - 3 subscribable resources: live
account://,positions://, andquotes://{symbol}snapshots that push change notifications. - 2 ready-to-use Claude Code skills ship in
.claude/skills/:mt5-market-dataandmt5-tradingteach an agent how to read the account and run the consent flow safely.
Full catalogue and the consent flow: docs/tools.md.
Why mt5-mcp
- A safety layer, not just an API wrapper. Every mutating call routes through preflight checks -> an opt-in human-consent gate (arm it to require approval) -> idempotency -> an append-only audit log, so you can put a human in the loop on trades and always keep a replayable record of what the agent did.
- An honest threat model. It treats an LLM wired to
place_orderas a live attack surface and says so plainly - the MCP is explicitly not the security boundary (see SECURITY.md). - Verifiable proof, not a mock-up. The demo above is a real round-trip; the tickets and balance match MetaTrader 5's own History tab.
- Local-first. No cloud, no telemetry; runs beside your agent. Windows-native
or Linux via an all-in-one Docker image (no
rpycversion-matching).
Quickstart (Windows, native)
- Launch MetaTrader 5 and log into your broker. Enable AlgoTrading (toolbar button green).
- Verify the terminal is reachable:
python -m mt5_mcp doctor: expect[INFO] backend: nativeand[PASS]lines. - Run it:
python -m mt5_mcp serve.
Wire it to OpenClaw in one command (registers the mcp.servers entry):
Quickstart (Linux, Docker)
The MT5 terminal + the MCP run headless in an all-in-one image; your agent talks MCP over HTTP. No host Python, no bridge.
Log the terminal in once via the KasmVNC web UI at http://127.0.0.1:3001
(File -> Login to Trade Account; persists across restarts), then point your
agent at http://127.0.0.1:8765/mcp. Wire it to OpenClaw in one command:
Full walkthrough: docs/installation.md.
Chart screenshots (Windows only)
get_chart_screenshot(symbol, timeframe, annotations?) returns a PNG of the
native MT5 chart, optionally annotated, so an LLM can read it visually
(candles, support/resistance, patterns). Because the MetaTrader5 Python API
cannot capture charts, this uses a small MQL5 Expert Advisor that runs inside
a GUI terminal and calls ChartScreenShot().
See Chart annotations for marking up support/resistance lines, trendlines and notes before capture.
Setup (one time):
- Install and attach the
AgentScreenshotEA - seemql5/README.md. - Optionally set a template so your indicators/drawings appear in the shot:
[screenshot]template = "agent.tpl"in your config, or leave it unset for the default chart.
Config knobs ([screenshot] section): width (default 1600), height
(default 900), template (default none), timeout_s (default 10).
Not available on the headless Linux/Docker deployment: it needs a GUI
terminal. Off Windows the tool returns SCREENSHOT_NOT_SUPPORTED.
For AI agents
If you've been handed this repository to install and run, follow the runbook in docs/agents.md. It covers platform detection, install, verification, registering the server, and the hard safety rules for trades - read it before calling any mutating tool.
Documentation
Safety
mt5-mcp is not the security boundary, the broker's MT5 server enforces
the hard limits (margin, max-lot, symbol permissions). Pre-flight checks in the
policy engine are UX guardrails to catch agent mistakes early, not security
controls.
The human-consent gate is opt-in and off by default: auto_approve_notional
defaults to 0, so mutating calls auto-execute (full-open) - intended for trusted
or unattended agents. Arm the gate by setting auto_approve_notional > 0:
orders/closes whose notional is at or above it then return an ApprovalPreview
you must confirm, and modifying a stop to widen or remove it also requires
approval. The pre-flight limits (max_*) and symbol allow/deny lists are likewise
opt-in (0 / empty = off). Every mutating call is recorded in an append-only audit
JSONL log regardless. For vulnerability disclosure, see
SECURITY.md.
Architecture
mt5-mcp wraps the MetaTrader 5 Python library behind a FastMCP server. A single MT5Client (src/mt5_mcp/adapter/) owns the terminal connection, broker-timezone inference, and type conversions; everything else sits on top of it. The Pydantic models in src/mt5_mcp/types.py / src/mt5_mcp/config.py are the source of truth for the data and config schemas.
The module paths shown (tools/, resources/, policy/, streaming/,
adapter/, types.py, config.py) all live under src/mt5_mcp/.
Contributing
Contributions are welcome, see CONTRIBUTING.md for the dev setup, test workflow, and project principles.
License
MIT - see LICENSE.
來源:README.md,提交 d433842
工具
0版本歷史
1- v1.4.2最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分