Skip to main content Switch to mobile version mt5-trading-mcp 1.8.6 MCP server for MetaTrader 5: let an AI agent read market data, watch trades, and place real trades - behind a consent/audit safety layer. Windows + Linux (Docker).
pip install mt5-trading-mcp==1.8.6 Copy PIP instructions
Let an AI agent manage your MetaTrader 5 account over Model Context Protocol - with configurable human approval gate.
A Hermes agent placing then closing a real 0.01-lot trade on a demo account, end-to-end over MCP on Linux.
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.
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://, and quotes://{symbol} snapshots that push change notifications.
3 ready-to-use Claude Code skills ship in .claude/skills/: mt5-market-data and mt5-trading teach an agent how to read the account and run the consent flow safely; mt5-mql5-build teaches the MQL5 compile loop.
Full catalogue and the consent flow: docs/tools.md.
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_order as 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 rpyc version-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: native and [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"}' The image runs Wine 11.10 staging, which runs current MT5 builds (Wine 10 could not run builds newer than 28 Sep 2026). The terminal is no longer pinned, so MT5's LiveUpdate keeps it current. To build and backtest EAs on Linux, use the backtest container in deploy/docker-compose.backtest.yml (see docs/agents.md).
Known issue: fresh volumes. A new terminal does not know your broker's server, and its Login dialog can draw as a black box under Wine, so it never logs in (the MCP server then reports IPC timeouts). Workaround, once per volume:
Copy servers.dat (server addresses only) from a terminal that knows the broker, e.g. a Windows install's %APPDATA%\MetaQuotes\Terminal\
Log in with a one-off start config: stop the terminal and run terminal64.exe "/config:C:\autologin.ini" as abc, where the ini has [Common] Login=, Password=, Server= and KeepPrivate=1. Delete the ini once the journal says authorized.
So the login survives restarts, add Login= and Server= (no password) under [Common] in Config/common.ini (UTF-16) while the terminal is stopped.
Full walkthrough: docs/installation.md.
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, Fibonacci retracements and notes before capture.
Install and attach the AgentScreenshot EA - see mql5/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).
Docker: the image preinstalls the EA, the light template and a startup ini on every boot, so no manual setup is needed. Set MT5_EA_SYMBOL (default BTCUSD) to a symbol your account has, otherwise screenshots time out. The light template is wired in only when the first boot seeds config.toml; on a volume that already has one, add [screenshot] template = "agent_light.tpl" by hand (an existing config.toml also ignores MT5_MCP_AUTH_TOKEN). Elsewhere (macOS, native Linux) the tool returns SCREENSHOT_NOT_SUPPORTED.
Build MQL5 with an agent
mt5-mcp compile
mt5-mcp backtest
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.
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.
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/.
Contributions are welcome, see CONTRIBUTING.md for the dev setup, test workflow, and project principles.
Released: Nov 28, 2026
Author: Vincent Wongso Saputro
Both files in this release have provenance metadata.
View provenance details
MIT View SPDX License List
ai-agent cfd fastmcp forex llm mcp metatrader metatrader5 model-context-protocol mt5 trading
Development Status 4 - Beta
Intended Audience Developers
Financial and Insurance Industry
Operating System Microsoft :: Windows
Programming Language Python :: 3.10
Topic Office/Business :: Financial :: Investment
Software Development :: Libraries :: Python Modules
Release files for mt5-trading-mcp 1.8.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 537.3 kB
Release files / mt5_trading_mcp-1.8.6.tar.gz
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Release files / mt5_trading_mcp-1.8.6-py3-none-any.whl
Security for mt5-trading-mcp 1.8.6
Both files in this release have been uploaded with provenance metadata.
With provenance mt5_trading_mcp-1.8.6.tar.gz Nov 28, 2026
With provenance mt5_trading_mcp-1.8.6-py3-none-any.whl Nov 28, 2026
Attestation for mt5_trading_mcp-1.8.6.tar.gz
Attestation for mt5_trading_mcp-1.8.6-py3-none-any.whl
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Nov 28, 2026 2 release files Full provenance
Nov 21, 2026 2 release files Full provenance
Nov 20, 2026 2 release files Full provenance
Nov 19, 2026 2 release files Full provenance
Nov 18, 2026 2 release files Full provenance
Jul 21, 2026 2 release files Full provenance
Jul 20, 2026 2 release files Full provenance
Jul 19, 2026 2 release files Full provenance
Jun 25, 2026 2 release files Full provenance
Jun 18, 2026 2 release files Full provenance
Jun 17, 2026 2 release files Full provenance
Jun 3, 2026 2 release files Full provenance
Jun 2, 2026 2 release files Full provenance
May 31, 2026 2 release files Full provenance
May 30, 2026 2 release files Full provenance
May 19, 2026 2 release files Full provenance
May 11, 2026 2 release files Full provenance
May 8, 2026 2 release files Full provenance
May 2, 2026 2 release files Full provenance
May 1, 2026 2 release files Full provenance
May 1, 2026 2 release files No provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from fc0d8e6











