Model Context Protocol server wrapping the MetaTrader 5 Python library.
Project description
mt5-mcp
Model Context Protocol server wrapping the MetaTrader 5 Python library: exposes a logged-in MT5 terminal as a set of MCP tools an AI agent can call.
⚠️ 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.
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. It runs locally, in the same
process tree as your agent, no cloud, no telemetry.
- 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.
Full catalogue and the consent flow: docs/tools.md.
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.
Linux (the MT5 terminal runs in an all-in-one Docker image; the agent talks MCP over HTTP) and wiring to an agent are in docs/installation.md.
For AI agents
If you are an AI agent and have been handed this repository to install and run, follow this procedure.
- Detect the platform and pick a backend. Windows runs the
MetaTrader5library natively; Linux runs the terminal in an all-in-one Docker image (the agent talks MCP over HTTP). Full per-platform steps: docs/installation.md. - Install from this checkout:
- Windows:
pip install .(oruv sync --extra dev). Tell the human to launch MetaTrader 5, log into their broker, and enable AlgoTrading. - Linux (recommended): bring up the Docker image — creds in
deploy/.env, thendocker compose -f deploy/docker-compose.yml up -d(it uses the published image; add--buildonly for localdeploy/changes). The server runs in the container and serves MCP over HTTP; the one-time VNC login + bridge alternative are indocs/installation.md.
- Windows:
- Verify before doing anything else: Windows →
python -m mt5_mcp doctor(expect the backend +[PASS]lines); Docker image → after the human's one-time VNC login, your firstpingreturnsok: true. Do not proceed if verification fails — report it to the human and stop. - Register / run the server: Docker image → it's already serving; register
http://127.0.0.1:8765/mcp. Windows →python -m mt5_mcp serve(stdio) with a config underexamples/clients/(e.g.hermes.json) that scopes you to the read-only tools by default. - Operate read-only unless explicitly asked to trade. The read tools are safe to call freely.
- ⚠️ Hard rule, if live account and using real money.
place_order,modify_order, andclose_positionexecute real, irreversible trades. When one returns anApprovalPreview, show it verbatim to the human and only retry withapproval_confirmed=trueafter they explicitly approve that specific order. Never auto-confirm, never batch-approve, never trade on a demo assumption — confirm it's a demo account first.
Tool semantics and the full consent flow: docs/tools.md.
Under Claude Code, the skills in .claude/skills/ teach these directly.
Documentation
| Guide | What's in it |
|---|---|
| Installation & setup | Requirements, Windows + Linux/Docker setup, wiring to an agent. |
| 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.
Mutating actions above the configured auto_approve_notional (or that widen
stops) require explicit human approval via the ApprovalPreview flow. Every
mutating call is recorded in an append-only audit JSONL log. 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. On top of it: the MCP tools
(src/mt5_mcp/tools/), subscribable resources (src/mt5_mcp/resources/), the
consent / idempotency / audit layer (src/mt5_mcp/policy/), and the
change-detection streaming subsystem (src/mt5_mcp/streaming/). The Pydantic
models in src/mt5_mcp/types.py and src/mt5_mcp/config.py are the source of
truth for the data and config schemas.
Contributing
Contributions are welcome, see CONTRIBUTING.md for the dev setup, test workflow, and project principles.
License
MIT - see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mt5_trading_mcp-1.2.1.tar.gz.
File metadata
- Download URL: mt5_trading_mcp-1.2.1.tar.gz
- Upload date:
- Size: 216.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b4f07da9e3961120b5bf4ac50c0ac1b6fde5c3c058e9b7331f6edcf0feb5fb7
|
|
| MD5 |
94127158e2f20717ae57f6021a3d7e1a
|
|
| BLAKE2b-256 |
93d7090d0867e02a403e378df4e9431a89aa1f86f520b74424a75a5048b5390e
|
Provenance
The following attestation bundles were made for mt5_trading_mcp-1.2.1.tar.gz:
Publisher:
publish.yml on vincentwongso/mt5-trading-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mt5_trading_mcp-1.2.1.tar.gz -
Subject digest:
0b4f07da9e3961120b5bf4ac50c0ac1b6fde5c3c058e9b7331f6edcf0feb5fb7 - Sigstore transparency entry: 1699590426
- Sigstore integration time:
-
Permalink:
vincentwongso/mt5-trading-mcp@584bcc54b142963117b1c81f00b0ad69dfdb673f -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/vincentwongso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@584bcc54b142963117b1c81f00b0ad69dfdb673f -
Trigger Event:
push
-
Statement type:
File details
Details for the file mt5_trading_mcp-1.2.1-py3-none-any.whl.
File metadata
- Download URL: mt5_trading_mcp-1.2.1-py3-none-any.whl
- Upload date:
- Size: 72.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6c6b30d23261925cfc48fcbcdfeb0a77e5647a1f70d3feb7e12c6694dc024b0
|
|
| MD5 |
f7cdf51c5f4c2698d93e3f9bc094c3b4
|
|
| BLAKE2b-256 |
574dc0437e97a58b82dd68d95957201ca76f89a16f9b8e8df615b22fca87f08b
|
Provenance
The following attestation bundles were made for mt5_trading_mcp-1.2.1-py3-none-any.whl:
Publisher:
publish.yml on vincentwongso/mt5-trading-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mt5_trading_mcp-1.2.1-py3-none-any.whl -
Subject digest:
e6c6b30d23261925cfc48fcbcdfeb0a77e5647a1f70d3feb7e12c6694dc024b0 - Sigstore transparency entry: 1699590538
- Sigstore integration time:
-
Permalink:
vincentwongso/mt5-trading-mcp@584bcc54b142963117b1c81f00b0ad69dfdb673f -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/vincentwongso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@584bcc54b142963117b1c81f00b0ad69dfdb673f -
Trigger Event:
push
-
Statement type: