MetaTrader5 MCP Server
Enables trading on MetaTrader5 platform via MCP, including account management, order placement, market data, technical indicators, and signal tools.
README
MetaTrader5 MCP Server
A Model Context Protocol (MCP) server that provides trading interfaces for MetaTrader5 (MT5) platform.
Features
- Account Management: Get account info, balance, equity, margin
- Position Management: View, modify, and close open positions
- Order Operations: Place market/pending orders, cancel orders
- Market Data: Get symbol info, current prices (ticks)
- Rates/Candles: Fetch OHLCV via start_pos/count or date range
- Indicators: Compute SMA, EMA, RSI, MACD, Bollinger Bands, ATR, Stochastic
- Bundle Indicators: Compute multiple indicators in a single call
- Signal Tools: EMA crossover regime flags and confluence scoring for entries
Installation
Install dependencies with uv:
uv sync
Configuration
Environment variables are now configured directly in your MCP client settings (no .env file needed).
Claude Desktop / Kiro
Add to your mcp.json configuration file:
{
"mcpServers": {
"mt5-trading": {
"command": "uvx",
"args": ["mt5-mcp"],
"env": {
"MT5_LOGIN": "your_account_number",
"MT5_PASSWORD": "your_password",
"MT5_SERVER": "your_broker_server",
"MT5_PATH": "C:\\Program Files\\MetaTrader 5\\terminal64.exe",
"MT5_TIMEOUT": "60000",
"DEFAULT_DEVIATION": "20",
"DEFAULT_MAGIC": "234000"
}
}
}
}
Required Environment Variables:
MT5_LOGIN- Your MT5 account numberMT5_PASSWORD- Your MT5 account passwordMT5_SERVER- Your broker's server nameMT5_PATH- Path to MT5 terminal executable
Optional Environment Variables:
MT5_TIMEOUT- Connection timeout in milliseconds (default: 60000)DEFAULT_DEVIATION- Default price deviation in points (default: 20)DEFAULT_MAGIC- Default magic number for orders (default: 234000)
Alternative: Local Development
For local development, you can also run directly:
# Set environment variables and run
MT5_LOGIN=your_account MT5_PASSWORD=your_pass MT5_SERVER=your_server MT5_PATH="C:\Program Files\MetaTrader 5\terminal64.exe" uv run python mt5_mcp/server.py
Or use the legacy method with uv directory:
{
"mcpServers": {
"mt5-trading": {
"command": "uv",
"args": [
"--directory",
"D:\\path\\mt5-mcp",
"run",
"python",
"mt5_mcp/server.py"
],
"env": {
"MT5_LOGIN": "your_account_number",
"MT5_PASSWORD": "your_password",
"MT5_SERVER": "your_broker_server",
"MT5_PATH": "C:\\Program Files\\MetaTrader 5\\terminal64.exe"
}
}
}
}
Available Tools
Account Information
mt5_get_account_info- Get account balance, equity, margin, etc.mt5_get_positions- Get open positions (all or filtered by symbol)mt5_get_orders- Get pending orders
Order Operations
mt5_place_order- Place market or pending orders- Supports: buy, sell, buy_limit, sell_limit, buy_stop, sell_stop
- Optional SL/TP
mt5_close_position- Close an open position by ticketmt5_cancel_order- Cancel a pending ordermt5_modify_position- Modify SL/TP of an open position
Market Data
mt5_get_symbol_info- Get contract specificationsmt5_get_tick- Get current bid/ask prices
Rates / Candles
mt5_get_rates_from_pos- Get OHLCV starting from a position (0=current bar) withstart_posandcountmt5_get_rates_range- Get OHLCV within an ISO date rangedate_from→date_to
Indicators
All indicator tools support either direct data (closes/candles) or auto-fetch via symbol + timeframe plus either date_from/date_to or start_pos/count. Set return_last_only=true to return only the latest values.
mt5_calc_sma- Simple Moving Average- Params:
period(default 20)
- Params:
mt5_calc_ema- Exponential Moving Average- Params:
period(default 20)
- Params:
mt5_calc_rsi- Relative Strength Index- Params:
period(default 14)
- Params:
mt5_calc_macd- MACD line, signal, histogram- Params:
fast(12),slow(26),signal(9)
- Params:
mt5_calc_bbands- Bollinger Bands (upper/middle/lower)- Params:
period(20),stddev(2.0)
- Params:
mt5_calc_atr- Average True Range (requires candles)- Params:
period(14)
- Params:
mt5_calc_stochastic- Stochastic Oscillator %K/%D (requires candles)- Params:
k_period(14),d_period(3),smooth_k(1)
- Params:
Bundle Indicators
mt5_calc_bundle- Compute multiple indicators in one call using the same fetched candles- Args:
indicators: array of names from ["sma","ema","rsi","macd","bbands","atr","stochastic"]- Optional
paramsobject for per-indicator overrides (e.g.,{ "sma": {"period": 50}, "bbands": {"stddev": 2.5} }) - Supports
symbol/timeframewith range/count or directcandles/closes return_last_only: if true, returns only the latest values
- Args:
Signal Tools
mt5_signal_crossover- EMA crossover and regime flags- Params:
fast(default 50),slow(200),lookback_bars(200) - Returns:
state(above/below/equal),crossed_up,crossed_down,age_bars,slope_fast,slope_slow,spread,spread_pct,price_above_both,price_below_both,price
- Params:
mt5_signal_confluence- Confluence scoring for entries- Indicator params:
ema_fast(50),ema_slow(200),ema_near(20),rsi_period(14),macd_fast(12),macd_slow(26),macd_signal(9),bb_period(20),bb_stddev(2.0),atr_period(14) - Thresholds:
near_k_atr(0.5),atr_expansion_ratio(1.0),score_threshold(3) - Control:
direction(auto|long|short), optionalweightsfor trend/momentum/volatility/location/trigger - Returns component flags and scores for long/short plus a suggested direction
- Indicator params:
Example Usage
# In Claude Desktop, you can now ask:
"What's my MT5 account balance?"
"Show me my open positions on EURUSD"
"Place a buy order for 0.1 lot EURUSD at market"
"Close position with ticket 12345"
"Get current price for XAUUSD"
# Indicators (auto-fetch candles)
"Compute RSI(14) on EURUSD H1 using the last 300 bars (latest value only)"
"Compute MACD and Bollinger Bands on EURUSD H4 for September"
# Bundle
"Compute RSI+MACD+BBands (latest values) on EURUSD H1 using last 300 bars"
# Signals
"Give me EMA(50/200) crossover regime info on EURUSD H1"
"Compute confluence score on EURUSD H1 (defaults) and tell me if entry is ready"
Requirements
- Windows OS (MT5 only runs on Windows)
- MetaTrader5 terminal installed and running
- Python >=3.11
- Active MT5 trading account
Architecture
mt5-mcp/
├── mt5_mcp/
│ ├── __init__.py # Package init
│ ├── server.py # MCP server with tool definitions
│ ├── mt5_service.py # MT5 SDK wrapper
│ └── indicators.py # Pure-Python technical indicators
├── pyproject.toml # Project dependencies (uv)
├── .env.example # Environment template
└── README.md
Development
Run in development mode:
uv run python mt5_mcp/server.py
License
MIT
Notes
- The MT5 terminal must be running when using this MCP
- Ensure your account has trading permissions enabled
- Test on a demo account first before using with real money
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。