mt5-mcp

mt5-mcp

Enables AI assistants and traders to connect to a local MetaTrader 5 terminal, fetch historical market data, run strategy backtests, monitor account status, and manage demo trades via natural language, with an interactive web GUI.

Category
访问服务器

README

MetaTrader 5 (MT5) MCP Server & Web GUI Workstation

Python 3.10+ MCP MetaTrader 5 License: MIT

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:

  1. Pull historical market data (OHLCV bars across timeframes M1–MN1 and millisecond-precision tick streams) with high-speed Parquet and CSV exports.
  2. Execute strategy backtests via built-in Python quantitative engines and native MT5 Strategy Tester automation (terminal64.exe /config:tester.ini).
  3. Inspect demo account status, equity curves, active symbols, market watch quotes, and open positions.
  4. Interactive Financial Web GUI: Built with TradingView Lightweight Charts, real-time telemetry, Strategy Studio with equity curve visualizer, and account login manager.
  5. 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 standard pip

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 8000

Then 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 .ini configurations.

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
mt5_connect path, login, password, server Initializes connection to MT5 terminal or logs in to a specific demo account.
mt5_account_summary None Returns demo account balance, equity, leverage, free margin, and profit.
mt5_terminal_info None Returns MT5 build version, connection state, ping, and data directories.

2. Market Exploration & Historical Data

Tool Parameters Description
mt5_get_symbols group (e.g. *USD*) Searches available symbols with wildcard filtering.
mt5_symbol_details symbol (e.g. EURUSD) Returns contract specifications (spread, point, digits, swap rates).
mt5_symbol_current_tick symbol Retrieves real-time bid, ask, and last price.
mt5_fetch_historical_bars symbol, timeframe, count, date_from, date_to, export_format Extracts historical OHLCV data across timeframes (M1 to MN1) with optional Parquet/CSV export.
mt5_fetch_ticks symbol, count, date_from, date_to, export_format Extracts millisecond-precision tick streams with optional Parquet/CSV export.

3. Strategy Testing & Simulation

Tool Parameters Description
mt5_list_backtest_strategies None Lists built-in backtest models (sma_crossover, rsi_reversal, bollinger_bands).
mt5_run_strategy_backtest symbol, timeframe, strategy_name, bars_count, initial_cash, lot_size, params Executes backtest on historical MT5 data and returns Sharpe ratio, Max Drawdown %, Win Rate %, Profit Factor, and trade log.
mt5_run_native_tester expert_name, symbol, period, deposit, currency, leverage, model, from_date, to_date, visual Automates native MT5 Strategy Tester using generated .ini configs and headless terminal64.exe execution.

4. Positions & Trading (Guarded)

Tool Parameters Description
mt5_get_open_positions symbol (optional) Lists open positions on the demo account.
mt5_get_order_history days, symbol (optional) Lists closed deals and historical order executions.
mt5_place_demo_order symbol, order_type, volume, sl, tp, explicit_user_approval Places demo orders with strict safety guard requiring explicit_user_approval=True.

Running Tests

Run the comprehensive pytest suite verifying connectivity, historical extraction, quantitative backtesters, and GUI REST APIs:

.venv\Scripts\pytest -v

License

MIT License.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选