Skip to main content
Glama

MetaTrader 5 (MT5) MCP Server & Web GUI Workstation

Python 3.10+ MCP MetaTrader 5 License: MIT

Windows上のMetaTrader 5向けの高性能Model Context Protocol (MCP)サーバーおよびインタラクティブなWeb GUI Workstationです。このプロジェクトは、AIアシスタント(Antigravity、Claude Desktop、Cursorなど)とクオンツトレーダーを、ローカルのMT5インストールに直接接続して、以下を可能にします:

  1. 履歴マーケットデータの取得(M1–MN1のタイムフレームにわたるOHLCVバーとミリ秒精度のティックストリーム)を、高速なParquetおよびCSVエクスポート機能付きで提供します。

  2. ストラテジーバックテストの実行を、内蔵のPythonクオンツエンジンとネイティブMT5ストラテジーテスターの自動化(terminal64.exe /config:tester.ini)を通じて行います。

  3. デモ口座のステータス、エクイティカーブ、アクティブな銘柄、マーケットウォッチの気配値、およびオープンポジションを確認できます。

  4. インタラクティブな金融Web GUI:TradingView Lightweight Charts、リアルタイムテレメトリー、エクイティカーブ可視化機能付きStrategy Studio、アカウントログインマネージャーで構成されています。

  5. 厳格な取引安全ガード:デモおよびライブ注文が明示的な確認なしには実行されないようにします。


アーキテクチャ概要

 ┌────────────────────────────────────────────────────────┐
 │                      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)                 │
 └────────────────────────────────────────────────────────┘

Related MCP server: MetaTrader MCP Server

インストールと前提条件

1. 要件

  • Windows 10 / 11 (64-bit)

  • MetaTrader 5 デスクトップターミナルがインストールされていること

  • Python 3.10, 3.11, or 3.12 (64-bit)

  • uv(推奨)または標準のpip

2. MT5でアルゴリズム取引を有効にする

MetaTrader 5ターミナルで次の操作を行います:

  • ツール -> オプション -> エキスパートアドバイザー の順に移動します。

  • アルゴリズミック取引を許可にチェックを入れます。

  • DLLインポートを許可にチェックを入れます(カスタムインジケーターで必要な場合)。

3. 仮想環境のセットアップ

# 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(インタラクティブダッシュボード)

このリポジトリには、TradingViewチャート、リアルタイムマーケットウォッチ、ストラテジーバックテストスタジオ、アカウント管理を備えた、金融グレードの専用Web GUIダッシュボードが含まれています:

# Launch via console script
mt5-mcp-gui

# Or launch via Python module
.venv\Scripts\python -m mt5_mcp.gui --port 8000

次に、ブラウザで**http://127.0.0.1:8000**を開きます。

GUI機能:

  • 📊 TradingView Lightweight Charts:インタラクティブなタイムフレーム選択(M1、M5、M15、M30、H1、H4、D1)対応の滑らかなローソク足・出来高チャート。

  • 📈 Strategy Backtest Studio:ストラテジーパラメータ(SMA Crossover、RSI Reversal、Bollinger Bands)を設定し、シミュレーションを実行して、エクイティ成長曲線、KPI(シャープレシオ、最大ドローダウン%、勝率%)、および決済済み取引ログを確認できます。

  • 📦 Historical Data Exporter:ローソク足データをParquetおよびCSVファイルにワンクリックですぐに抽出できます。

  • 🔍 Market Watch:ワイルドカード検索(例:*USD*、Crypto*)によるリアルタイムの銘柄探索と、ライブの変動スプレッドインジケーター。

  • ⚙️ MT5 Connect & Account Login Modal:アクティブなMT5ターミナルにシームレスに接続するか、カスタムのログインID、パスワード、ブローカー/サーバー、およびオプションの実行ファイルパスを使用して任意のデモ口座に切り替え/ログインできます(Enterキーで送信、Escキーで閉じる)。

  • 📋 Open Positions & Native MT5 Tester Panel:オープン中の取引を表示し、バッチ.ini設定を使用してネイティブMQL5エキスパートアドバイザーをヘッドレスで自動化します。


MCPクライアント設定

Claude Desktop / Antigravity / Cursor (mcp_config.json)

MT5 MCPサーバーをMCPクライアント設定に追加します:

{
  "mcpServers": {
    "mt5": {
      "command": "C:\\Users\\<USER>\\source\\repos\\mt5_mcp\\.venv\\Scripts\\python.exe",
      "args": [
        "-m",
        "mt5_mcp.server"
      ],
      "env": {
        "PYTHONUNBUFFERED": "1"
      }
    }
  }
}

利用可能なMCPツール

1. 接続とアカウント管理

ツール

パラメータ

説明

mt5_connect

path, login, password, server

MT5ターミナルへの接続を初期化するか、特定のデモ口座にログインします。

mt5_account_summary

None

デモ口座の残高、純資産、レバレッジ、有効証拠金、および損益を返します。

mt5_terminal_info

None

MT5ビルドバージョン、接続状態、ping、およびデータディレクトリを返します。

2. マーケット探索と履歴データ

ツール

パラメータ

説明

mt5_get_symbols

group(例:*USD*)

ワイルドカードフィルタリングを使用して利用可能な銘柄を検索します。

mt5_symbol_details

symbol(例:EURUSD)

契約仕様(スプレッド、ポイント、桁数、スワップレート)を返します。

mt5_symbol_current_tick

symbol

リアルタイムのBid、Ask、最終価格を取得します。

mt5_fetch_historical_bars

symbol, timeframe, count, date_from, date_to, export_format

タイムフレーム(M1 から MN1)にわたる履歴OHLCVデータを抽出し、オプションでParquet/CSVエクスポートを行います。

mt5_fetch_ticks

symbol, count, date_from, date_to, export_format

ミリ秒精度のティックストリームを抽出し、オプションでParquet/CSVエクスポートを行います。

3. ストラテジーテストとシミュレーション

ツール

パラメータ

説明

mt5_list_backtest_strategies

None

内蔵バックテストモデル(sma_crossover、rsi_reversal、bollinger_bands)を一覧表示します。

mt5_run_strategy_backtest

symbol, timeframe, strategy_name, bars_count, initial_cash, lot_size, params

履歴MT5データでバックテストを実行し、シャープレシオ、最大ドローダウン%、勝率%、プロフィットファクター、取引ログを返します。

mt5_run_native_tester

expert_name, symbol, period, deposit, currency, leverage, model, from_date, to_date, visual

生成された.ini設定とヘッドレスterminal64.exe実行を使用して、ネイティブMT5ストラテジーテスターを自動化します。

4. ポジションと取引(保護付き)

ツール

パラメータ

説明

mt5_get_open_positions

symbol(オプション)

デモ口座のオープンポジションを一覧表示します。

mt5_get_order_history

days, symbol(オプション)

決済済みの約定と履歴注文の実行を一覧表示します。

mt5_place_demo_order

symbol, order_type, volume, sl, tp, explicit_user_approval

explicit_user_approval=Trueを要求する厳格な安全ガード付きでデモ注文を発注します。


テストの実行

接続性、履歴データ抽出、クオンツバックテスター、およびGUI REST APIを検証する包括的なpytestスイートを実行します:

.venv\Scripts\pytest -v

ライセンス

MIT License.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    • Trader.AI turns trading ideas into strategies you can trade. Describe an idea, paste a strategy, or share the source of an MT5 Expert Advisor, and Trader.AI makes the rules exact (entries, exits, stops and position sizing), then backtests them on historical MT5 data for EURUSD, GBPUSD, AUDUSD, XAUUSD, XAGUSD, NAS100, SP500, USOIL, BTCUSD or ETHUSD. Results come back in the chat: return, max drawdown, win rate, Sharpe and every trade, with the rule that opened it and why it closed, plus a report link. Change the rules and backtest again; every version is saved so you can compare runs. Start from a starter strategy or see how Trader.AI's own AI traders perform in live trading. When a version backtests the way you want, export it as an MT5 Expert Advisor. Backtest results are hypothetical and don't guarantee future returns. Trader.AI doesn't place trades on your account or give investment advice. Connecting requires signing in with a Trader.AI account.

      https://trader.ai/api/mcp
    • Read-only MetaTrader 5 for AI agents: balances, positions, history and prices. Sign in with OAuth.

    • Read-only access to your MetaTrader 4 and 5 accounts for AI agents: balances, open positions, trade history with win rate, live quotes, symbol specs and candles. It cannot place, modify or close orders.

      https://mcp.fxsocket.com/mcp
    • MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents

      https://mcp.openmm.io/mcp

    Related MCP Servers

    • A
      license
      Not graded
      quality
      A
      maintenance
      Exposes a unified AI interface to MetaTrader 5 over the Model Context Protocol, enabling live quotes, historical data, technical indicators, order execution, position management, and headless backtests.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to trade on MetaTrader 5 using natural language, supporting account management, order placement, and real-time market data.
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      A local-first MCP server that bridges AI coding agents with MetaTrader 5 for inspection, market data, MQL5 development, compiling, Strategy Tester review, workspace sync, logs, audit trails, demo trading, and carefully gated live trading.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Universal MCP server that enables AI assistants to control MetaTrader 5 directly, executing trades, managing data, and automating MT5 operations through natural language.
      4
      -