mt5-mcp
MetaTrader 5 (MT5) MCP Server & Web GUI Workstation
A high-performance Model Context Protocol (MCP) Server and interactive Web GUI Workstation for MetaTrader 5 on Windows. This project connects AI assistants (Antigravity, Claude Desktop, Cursor, etc.) and quantitative traders directly to their local MT5 installation to:
Pull historical market data (OHLCV bars across timeframes M1–MN1 and millisecond-precision tick streams) with high-speed Parquet and CSV exports.
Execute strategy backtests via built-in Python quantitative engines and native MT5 Strategy Tester automation (
terminal64.exe /config:tester.ini).Inspect demo account status, equity curves, active symbols, market watch quotes, and open positions.
Interactive Financial Web GUI: Built with TradingView Lightweight Charts, real-time telemetry, Strategy Studio with equity curve visualizer, and account login manager.
Strict Trading Safety Guard: Ensures demo and live orders can only execute with explicit confirmation.
Architecture Overview
┌────────────────────────────────────────────────────────┐
│ AI Client │
│ (Antigravity / Claude Desktop / Cursor) │
└───────────────────────────┬────────────────────────────┘
│ MCP Protocol (stdio)
┌───────────────────────────▼────────────────────────────┐
│ MT5 MCP Server (Python) │
│ - FastMCP Server (`src/mt5_mcp/server.py`) │
│ - Data Caching & Parquet/CSV Export Engine │
│ - Quantitative Strategy Backtesting Engine │
└─────────────┬────────────────────────────┬─────────────┘
│ │
┌─────────────▼──────────────┐ ┌──────────▼─────────────┐
│ MetaTrader5 Python API │ │ MT5 Native Tester Auto │
│ - copy_rates_range() │ │ - tester.ini builder │
│ - copy_ticks_range() │ │ - terminal64.exe CLI │
│ - account_info() / login()│ │ - Report XML/HTML │
└─────────────┬──────────────┘ └──────────┬─────────────┘
│ │
┌─────────────▼────────────────────────────▼─────────────┐
│ MetaTrader 5 Windows Terminal │
│ (Demo Account Connected) │
└────────────────────────────────────────────────────────┘Installation & Prerequisites
1. Requirements
Windows 10 / 11 (64-bit)
MetaTrader 5 desktop terminal installed
Python 3.10, 3.11, or 3.12 (64-bit)
uv(recommended) or standardpip
2. Enable Algorithmic Trading in MT5
In your MetaTrader 5 terminal:
Navigate to Tools -> Options -> Expert Advisors.
Check Allow algorithmic trading.
Check Allow DLL imports (if required by custom indicators).
3. Setup Virtual Environment
# Clone the repository
git clone https://github.com/remomein05/mt5-mcp.git
cd mt5-mcp
# Create virtual environment and install dependencies
uv venv --python 3.12 .venv
.venv\Scripts\activate
uv pip install -e ".[dev]"Web GUI Workstation (Interactive Dashboard)
The repository includes a dedicated financial-grade Web GUI Dashboard with TradingView charting, real-time market watch, strategy backtesting studio, and account management:
# Launch via console script
mt5-mcp-gui
# Or launch via Python module
.venv\Scripts\python -m mt5_mcp.gui --port 8000Then open http://127.0.0.1:8000 in your browser.
GUI Features:
📊 TradingView Lightweight Charts: Smooth candlestick and volume charting with interactive timeframe selector (
M1,M5,M15,M30,H1,H4,D1).📈 Strategy Backtest Studio: Configure strategy parameters (
SMA Crossover,RSI Reversal,Bollinger Bands), run simulations, and inspect Equity Growth Curves, KPIs (Sharpe ratio, Max Drawdown %, Win Rate %), and closed trades logs.📦 Historical Data Exporter: Instant one-click extraction of candlestick data to Parquet and CSV files.
🔍 Market Watch: Real-time symbol exploration with wildcard search (e.g.
*USD*,Crypto*) and live floating spread indicators.⚙️ MT5 Connect & Account Login Modal: Seamlessly connect to your active MT5 terminal or switch/log in to any demo account with custom Login ID, Password, Broker/Server, and optional executable path (with Enter key submission and Esc key dismissal).
📋 Open Positions & Native MT5 Tester Panel: View open trades and automate native MQL5 Expert Advisors headlessly with batch
.iniconfigurations.
MCP Client Configuration
Claude Desktop / Antigravity / Cursor (mcp_config.json)
Add the MT5 MCP server to your MCP client configuration:
{
"mcpServers": {
"mt5": {
"command": "C:\\Users\\<USER>\\source\\repos\\mt5_mcp\\.venv\\Scripts\\python.exe",
"args": [
"-m",
"mt5_mcp.server"
],
"env": {
"PYTHONUNBUFFERED": "1"
}
}
}
}Available MCP Tools
1. Connection & Account Management
Tool | Parameters | Description |
|
| Initializes connection to MT5 terminal or logs in to a specific demo account. |
| None | Returns demo account balance, equity, leverage, free margin, and profit. |
| None | Returns MT5 build version, connection state, ping, and data directories. |
2. Market Exploration & Historical Data
Tool | Parameters | Description |
|
| Searches available symbols with wildcard filtering. |
|
| Returns contract specifications (spread, point, digits, swap rates). |
|
| Retrieves real-time bid, ask, and last price. |
|
| Extracts historical OHLCV data across timeframes ( |
|
| Extracts millisecond-precision tick streams with optional Parquet/CSV export. |
3. Strategy Testing & Simulation
Tool | Parameters | Description |
| None | Lists built-in backtest models ( |
|
| Executes backtest on historical MT5 data and returns Sharpe ratio, Max Drawdown %, Win Rate %, Profit Factor, and trade log. |
|
| Automates native MT5 Strategy Tester using generated |
4. Positions & Trading (Guarded)
Tool | Parameters | Description |
|
| Lists open positions on the demo account. |
|
| Lists closed deals and historical order executions. |
|
| Places demo orders with strict safety guard requiring |
Running Tests
Run the comprehensive pytest suite verifying connectivity, historical extraction, quantitative backtesters, and GUI REST APIs:
.venv\Scripts\pytest -vLicense
MIT License.