MT5 MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MT5 MCP Servershow EURUSD H1 candles and my current account balance"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MT5 MCP Server
Custom Model Context Protocol (MCP) server that connects Claude Desktop directly to MetaTrader 5. Lets Claude pull historical/live data, run backtests, inspect your account, and place orders with mandatory two-step confirmation.
Features
Historical data: OHLCV candles, raw ticks, symbol contract specs
Real-time quotes: bid/ask/spread, market depth, live tick monitoring
Account inspection: balance, equity, open positions, pending orders, deal history
Order management: market & pending orders, position close, SL/TP modify — all with token-based confirmation
Backtesting: vectorized signal-based engine with EMA/SMA/RSI/cross helpers, returns Sharpe, drawdown, profit factor, win rate
Safety gateway: lot-size limits, per-session order cap, demo-only enforcement by default
Related MCP server: MetaTrader 5 MCP Server
Requirements
Windows (MetaTrader5 Python package is Windows-only)
Python 3.13 or newer
MetaTrader 5 desktop terminal, logged into a broker account
Claude Desktop
Installation
1. Place the project
Copy the entire mt5_mcp_server folder to a permanent location, for example:
C:\Users\YourName\mt5_mcp_server\2. Install Python dependencies
Open PowerShell in the project folder and run:
pip install -r requirements.txt3. Configure environment
Copy .env.example to .env and edit if you need custom settings. The defaults
are safe (demo-only, 1.0 lot max, 20 orders per session, confirmation required).
copy .env.example .envIf your MT5 terminal is already logged in, you can leave login/password blank — the server will use the active session.
4. Configure MT5 to allow algorithmic trading
In MetaTrader 5:
Tools → Options → Expert Advisors
Check "Allow algorithmic trading"
Check "Allow DLL imports" (for the Python integration)
Click OK
5. Run the connection test
python test_connection.pyYou should see [OK] on every check. If any check fails, fix it before
registering the MCP server with Claude Desktop.
6. Register with Claude Desktop
Open Claude Desktop's config file:
Windows:
%APPDATA%\Claude\claude_desktop_config.json
Merge in the MCP server entry from claude_desktop_config.example.json,
adjusting paths to match your install. A minimal example:
{
"mcpServers": {
"mt5": {
"command": "python",
"args": ["C:\\Users\\YourName\\mt5_mcp_server\\server.py"],
"env": {
"PYTHONPATH": "C:\\Users\\YourName\\mt5_mcp_server",
"SAFETY_MODE": "demo",
"MAX_LOT_SIZE": "0.1"
}
}
}
}Restart Claude Desktop. The mt5 server should now appear in the connectors
list, and Claude can call its tools.
Available Tools
Connection
mt5_info— terminal + account infosafety_status— current safety config & session counters
Historical Data
get_ohlcv(symbol, timeframe, count|start, end)— OHLCV barsget_ticks(symbol, count|start, end)— raw ticksget_symbol_info(symbol)— contract specslist_symbols(group?)— broker symbol list
Real-time
get_current_price(symbol)— bid/ask/spread snapshotget_market_depth(symbol)— DOM (broker-dependent)monitor_symbol(symbol, duration_seconds)— sample live ticks (max 30s)
Account & Positions (read-only)
get_account_info()— balance, equity, margin, leverageget_positions(symbol?)— open positionsget_orders(symbol?)— pending ordersget_history(days)— closed deals over last N days
Order Operations (two-step)
Every write operation requires prepare_* then confirm_* with the token:
prepare_order/confirm_order— open new market or pending orderprepare_close_position/confirm_close_position— close (full or partial)prepare_modify_position/confirm_modify_position— change SL/TP
Backtesting
run_backtest(symbol, timeframe, buy_when, sell_when, ...)— vectorized backtestcalculate_metrics(trades, initial_balance)— performance metrics
Backtest signal expressions support:
sma(close, n),ema(close, n),rsi(close, n)cross_above(a, b),cross_below(a, b),shift(s, n)References:
open,high,low,close,volume
Example:
buy_when: cross_above(ema(close, 12), ema(close, 26)) & (rsi(close, 14) < 70)
sell_when: cross_below(ema(close, 12), ema(close, 26))Safety Architecture
The server is designed to make accidental order placement very hard:
Demo enforcement.
SAFETY_MODE=demo(default) refuses to operate if the logged-in account is not demo. This catches the most common foot-gun.Two-step orders. Every trade-modifying tool is split into
prepare_*andconfirm_*. The prepare step returns a one-time token that's bound to exact parameters. The confirm step validates the token + that the params match. This means a single rogue tool call cannot place an order — Claude must first call prepare, show you the summary, wait for your "go ahead", then call confirm with the token. Tokens expire after 5 minutes.Lot-size limit.
MAX_LOT_SIZE(default 1.0) caps any single order's volume.Per-session cap.
MAX_ORDERS_PER_SESSION(default 20) prevents runaway loops from filling your account with trades. Resets on server restart.Broker-side validation. All orders go through MT5's own validation (volume_min/max, allowed trade modes, margin checks).
Going to live trading
When you're ready (after substantial demo testing), edit .env:
SAFETY_MODE=live
MAX_LOT_SIZE=0.05 # start TINY on real moneyThe two-step confirmation flow stays in place — there is intentionally no way to disable it.
Troubleshooting
"MT5 initialize() failed" — Make sure the MT5 desktop terminal is running
and logged in. The Python package attaches to a running terminal; it doesn't
launch one. Try setting MT5_TERMINAL_PATH in .env if auto-detect fails.
"Symbol 'XXXUSD' not found" — The symbol must exist for your broker. Use
list_symbols(group="*USD*") to see what's available. Some brokers add
suffixes like EURUSD.r or EURUSD-pro.
Server doesn't appear in Claude Desktop — Check the path in
claude_desktop_config.json is absolute and uses double backslashes on Windows.
Check Claude Desktop's developer logs (Help → View Logs) for spawn errors.
"SAFETY: account is REAL" — You connected a live account but
SAFETY_MODE=demo. This is intentional protection. Either log into a demo
account in MT5, or set SAFETY_MODE=live in .env (only after you've
thoroughly tested).
Ticks/quotes empty during weekend — Forex market is closed Friday evening to Sunday evening (UTC). Historical data still works.
Development workflow
The recommended Claude flow when building a new strategy:
"Pull the last 5000 H1 EURUSD bars" —
get_ohlcv"Try a 12/26 EMA crossover strategy" —
run_backtest"Show me the metrics broken down by year" — Claude analyses returned trade list
"Tighten the SL to 30 points and retest" — iterate
"Once happy, draft the equivalent MQL5 EA file" — Claude writes
.mq5to yourMQL5/Experts/folder via the FileSystem connector"Open a 0.01 lot demo BUY at market with 30-point SL" —
prepare_order→ you review →confirm_order
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect any MCP client to MetaTrader 4/5 to read prices, manage positions, and place trades.
Trade 16 crypto exchanges + MetaTrader 5 from your AI assistant via one MCP connection.
- Era ContextOAuthapp.era
Personal finance, bank account, and shared memory connector for Claude, ChatGPT, Gemini Spark & more
Trade across 22+ exchanges and brokers from any MCP-capable AI agent, no install required.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables users to capture real MetaTrader 5 chart snapshots with custom indicators and fetch market data through natural language in Claude Desktop.3MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants to connect to MetaTrader 5 for trading, market data access, and account management through the Model Context Protocol.99 PyPI224MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with MetaTrader 5 for market data, technical analysis, Fibonacci calculations, and trading via MCP clients such as Claude.MIT
- FlicenseAqualityDmaintenanceEnables Claude AI to perform forex trading operations and market data analysis through MetaTrader 5, including order placement, position management, and multi-timeframe candle data retrieval.16-