Skip to main content

Model Context Protocol server wrapping the MetaTrader 5 Python library.

Project description

mt5-mcp

PyPI version Python License: MIT Tests

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 — real orders, real money, irreversible fills. Read DISCLAIMER.md and SECURITY.md before connecting it to a live account.

Status: v1.1.0 — first public release. 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 toolsplace_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.

Full catalogue and the consent flow: docs/tools.md.

Quickstart (Windows, native)

pip install mt5-trading-mcp
  1. Launch MetaTrader 5 and log into your broker. Enable AlgoTrading (toolbar button green).
  2. Verify the terminal is reachable: python -m mt5_mcp doctor — expect [INFO] backend: native and [PASS] lines.
  3. Run it: python -m mt5_mcp serve.

Linux (MT5 in Docker), the bridge backend, 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.

  1. Detect the platform and pick a backend. Windows runs the MetaTrader5 library natively; Linux runs the terminal in Docker and connects over a bridge.
  2. Install from this checkout:
    • Windows: pip install . (or uv sync --extra dev). Tell the human to launch MetaTrader 5, log into their broker, and enable AlgoTrading.
    • Linux: pip install '.[bridge]', then docker compose -f examples/docker-compose.yml up -d, have the human finish the MT5 install + broker login via KasmVNC at http://localhost:3000, and copy examples/config.toml.example to ~/.config/mt5-mcp/config.toml (keep the [mt5.bridge] block).
  3. Verify before doing anything else: run python -m mt5_mcp doctor. Do not proceed unless it prints the active backend and [PASS] lines. If any check is [FAIL], report it to the human and stop.
  4. Register / run the server: python -m mt5_mcp serve (stdio). To wire it into your own harness, use the matching config under examples/clients/ — e.g. hermes.json or openclaw.json — which scope you to the read-only tools by default.
  5. Operate read-only unless explicitly asked to trade. The read tools are safe to call freely.
  6. ⚠️ Hard rule — real money. place_order, modify_order, and close_position execute real, irreversible trades. When one returns an ApprovalPreview, show it verbatim to the human and only retry with approval_confirmed=true after 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mt5_trading_mcp-1.2.0.tar.gz (205.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mt5_trading_mcp-1.2.0-py3-none-any.whl (69.9 kB view details)

Uploaded Python 3

File details

Details for the file mt5_trading_mcp-1.2.0.tar.gz.

File metadata

  • Download URL: mt5_trading_mcp-1.2.0.tar.gz
  • Upload date:
  • Size: 205.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mt5_trading_mcp-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9dd5c468611b4c1822b984ccd1d245ae48548cd5b96dde996da9d02685f627d0
MD5 715c1a3aa9ec0dc44f389e66f60f0fec
BLAKE2b-256 c95c0540e18d62de50b98ac4f83f770df3f69357878f0fee6cef9619c95f0fb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mt5_trading_mcp-1.2.0.tar.gz:

Publisher: publish.yml on vincentwongso/mt5-trading-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mt5_trading_mcp-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: mt5_trading_mcp-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 69.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mt5_trading_mcp-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd454a3a75a098cb5d43c8b0f56f0727e0682d68de1d8b5b159d219a70c51327
MD5 0c01196483f8732187fb31b6e1853c70
BLAKE2b-256 19b6885379d653c915893ef751ddbe7c0f044540d0034249b2d0ad4acec4a25c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mt5_trading_mcp-1.2.0-py3-none-any.whl:

Publisher: publish.yml on vincentwongso/mt5-trading-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page