mt5-mcp
An MCP server that lets an AI agent read your MetaTrader 5 account and place trades over the Model Context Protocol, with a configurable human approval gate.
README
mt5-mcp
Let an AI agent manage your MetaTrader 5 account over Model Context Protocol - with configurable human approval gate.
<p align="center"> <img src="https://raw.githubusercontent.com/vincentwongso/mt5-trading-mcp/main/demo/mt5-mcp-demo.gif" width="600" alt="mt5-mcp demo: an AI agent places and closes a live trade over MCP"><br> <sub>A <a href="https://github.com/NousResearch">Hermes</a> agent placing then closing a real 0.01-lot trade on a <b>demo</b> account, end-to-end over MCP on Linux.</sub> </p>
<p align="center"> <img src="https://raw.githubusercontent.com/vincentwongso/mt5-trading-mcp/main/demo/mt5-history.png" width="820" alt="The same round-trip in MetaTrader 5's History tab"><br> <sub>Not a mock-up - the same round-trip in MetaTrader 5's own History tab; the tickets and balance match the recording.</sub> </p>
⚠️ 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+.
What it is
mt5-mcp lets an AI agent read your MetaTrader 5 account and place trades
through it, over the Model Context Protocol.
- 11 read-only tools: account, quotes, positions, orders, history, OHLC bars, and broker-authoritative margin estimates. 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)
pip install mt5-trading-mcp
- 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):
openclaw mcp set mt5-mcp '{"command":"python","args":["-m","mt5_mcp","serve"]}'
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.
cp deploy/.env.example deploy/.env # add MT5_LOGIN / MT5_PASSWORD / MT5_SERVER
docker compose -f deploy/docker-compose.yml up -d
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:
openclaw mcp set mt5-mcp '{"url":"http://127.0.0.1:8765/mcp","transport":"streamable-http"}'
Full walkthrough: docs/installation.md.
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
| Guide | What's in it |
|---|---|
| Installation & setup | Requirements, Windows + Linux/Docker setup, wiring to an agent. |
| For AI agents | Step-by-step runbook for an agent installing and running the server. |
| Configuration | config.toml schema, storage paths, hot-reload. |
| Tools & resources | Read tools, mutating tools + consent flow, subscribable resources. |
| MCP client setup | Per-client config snippets and Claude Code usage. |
| Transports & deployment | stdio/HTTP transports and Windows VPS patterns. |
| Contributing | How to contribute and run the tests. |
| Changelog | Release history and known limitations. |
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.
Agent / MCP client (Hermes, OpenClaw, Claude Code, Claude Desktop, …)
│
│ stdio · loopback HTTP
▼
┌──────────────────────────────────────────────────────────┐
│ FastMCP server │
│ │
│ tools/ resources/ policy/ │
│ read + subscribable consent · idempotency │
│ mutating account/quotes · audit (JSONL) │
│ │
│ streaming/ - change-detection poller + dispatcher │
│ types.py · config.py - Pydantic schemas: source of │
│ truth for data + config │
│ │
└──────────────────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────┐
│ │
│ adapter/ MT5Client │
│ one terminal connection · broker-TZ inference · │
│ type conversions · transparent reinit │
│ │
└──────────────────────────────────────────────────────────┘
│
▼
MetaTrader 5 Python library → broker terminal → broker server
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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。