Skip to main content
Glama
edkdev

MetaTrader5 MCP Server

by edkdev

MetaTrader5 MCP サーバー

MetaTrader5(MT5)プラットフォームに取引インターフェースを提供する Model Context Protocol(MCP)サーバーです。

機能

  • アカウント管理:アカウント情報、残高、純資産、証拠金の取得

  • ポジション管理:オープンポジションの表示、変更、決済

  • 注文操作:成行/指値注文の発注、注文の取消

  • 市場データ:銘柄情報、現在価格(ティック)の取得

  • レート/ローソク足:start_pos/count または日付範囲による OHLCV の取得

  • インジケーター:SMA、EMA、RSI、MACD、ボリンジャーバンド、ATR、ストキャスティクスの計算

  • バンドルインジケーター:1回の呼び出しで複数のインジケーターを計算

  • シグナルツール:EMA クロスオーバーのレジームフラグとエントリーのコンフルエンススコアリング

Related MCP server: MetaTrader 5 MCP Server

インストール

uv で依存関係をインストールします:

uv sync

設定

環境変数は MCP クライアント設定に直接設定します(.env ファイルは不要です)。

Claude Desktop / Kiro

mcp.json 設定ファイルに追加します:

{
  "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"
      }
    }
  }
}

必須の環境変数:

  • MT5_LOGIN - MT5 アカウント番号

  • MT5_PASSWORD - MT5 アカウントパスワード

  • MT5_SERVER - ブローカーのサーバー名

  • MT5_PATH - MT5 ターミナル実行ファイルへのパス

オプションの環境変数:

  • MT5_TIMEOUT - 接続タイムアウト(ミリ秒、デフォルト:60000)

  • DEFAULT_DEVIATION - デフォルトの価格乖離(ポイント、デフォルト:20)

  • DEFAULT_MAGIC - 注文のデフォルトマジックナンバー(デフォルト:234000)

代替:ローカル開発

ローカル開発の場合は、直接実行することもできます:

# 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

または、uv ディレクトリを使用した従来の方法:

{
  "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"
      }
    }
  }
}

利用可能なツール

アカウント情報

  • mt5_get_account_info - アカウント残高、純資産、証拠金などを取得

  • mt5_get_positions - オープンポジションを取得(全銘柄または銘柄指定)

  • mt5_get_orders - 保留中の注文を取得

注文操作

  • mt5_place_order - 成行または指値注文を発注

    • 対応:buy、sell、buy_limit、sell_limit、buy_stop、sell_stop

    • オプションで SL/TP 設定可能

  • mt5_close_position - チケット番号でオープンポジションを決済

  • mt5_cancel_order - 保留中の注文を取消

  • mt5_modify_position - オープンポジションの SL/TP を変更

市場データ

  • mt5_get_symbol_info - 契約仕様を取得

  • mt5_get_tick - 現在の Bid/Ask 価格を取得

レート / ローソク足

  • mt5_get_rates_from_pos - 指定位置(0=現在のバー)から start_pos と count で OHLCV を取得

  • mt5_get_rates_range - ISO 日付範囲 date_from → date_to 内の OHLCV を取得

インジケーター

すべてのインジケーターツールは、直接データ(終値/ローソク足)または symbol + timeframe と date_from/date_to または start_pos/count による自動取得の両方をサポートします。return_last_only=true を設定すると、最新値のみを返します。

  • mt5_calc_sma - 単純移動平均線

    • パラメーター:period(デフォルト 20)

  • mt5_calc_ema - 指数移動平均線

    • パラメーター:period(デフォルト 20)

  • mt5_calc_rsi - 相対力指数

    • パラメーター:period(デフォルト 14)

  • mt5_calc_macd - MACD ライン、シグナル、ヒストグラム

    • パラメーター:fast(12)、slow(26)、signal(9)

  • mt5_calc_bbands - ボリンジャーバンド(上限/中央/下限)

    • パラメーター:period(20)、stddev(2.0)

  • mt5_calc_atr - 平均真のレンジ(ローソク足が必要)

    • パラメーター:period(14)

  • mt5_calc_stochastic - ストキャスティクスオシレーター %K/%D(ローソク足が必要)

    • パラメーター:k_period(14)、d_period(3)、smooth_k(1)

バンドルインジケーター

  • mt5_calc_bundle - 同じ取得ローソク足を使用して、1回の呼び出しで複数のインジケーターを計算

    • 引数:

      • indicators: ["sma","ema","rsi","macd","bbands","atr","stochastic"] からの名前の配列

      • オプションの params オブジェクト:インジケーターごとの上書き設定(例:{ "sma": {"period": 50}, "bbands": {"stddev": 2.5} })

      • symbol/timeframe と範囲/カウント、または直接 candles/closes をサポート

      • return_last_only:true の場合、最新値のみを返す

シグナルツール

  • mt5_signal_crossover - EMA クロスオーバーとレジームフラグ

    • パラメーター:fast(デフォルト 50)、slow(200)、lookback_bars(200)

    • 戻り値:state(above/below/equal)、crossed_up、crossed_down、age_bars、slope_fast、slope_slow、spread、spread_pct、price_above_both、price_below_both、price

  • mt5_signal_confluence - エントリーのコンフルエンススコアリング

    • インジケーターパラメーター: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)

    • しきい値:near_k_atr(0.5)、atr_expansion_ratio(1.0)、score_threshold(3)

    • 制御:direction(auto|long|short)、オプションの weights(trend/momentum/volatility/location/trigger)

    • コンポーネントフラグと long/short のスコア、および推奨方向を返す

使用例

# 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"

要件

  • Windows OS(MT5 は Windows でのみ動作)

  • MetaTrader5 ターミナルがインストールされ、実行中であること

  • Python >=3.11

  • アクティブな MT5 取引口座

アーキテクチャ

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

開発

開発モードで実行:

uv run python mt5_mcp/server.py

ライセンス

MIT

注意事項

  • 本ソフトウェアは現状のまま提供され、ソフトウェア作成者は取引による損失について一切の責任を負いません。外国為替取引は非常に変動が大きくリスクが高いため、細心の注意を払って進めてください。

  • この MCP を使用する際は、MT5 ターミナルが実行中である必要があります

  • アカウントで取引権限が有効になっていることを確認してください

  • 実際の資金を使用する前に、デモ口座でテストしてください

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables access to MetaTrader5 market data and trading functionality, including real-time quotes, historical OHLCV data, tick data, symbol information, and technical indicators for forex and other trading instruments.
    22
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI assistants to connect to MetaTrader 5 for trading, market data access, and account management through the Model Context Protocol.
    90 PyPI
    231
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI applications to interact with MetaTrader 5 terminals via WebSocket MCP protocol for trading operations and account management.
    4
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables interaction with MetaTrader 5 for market data, technical analysis, Fibonacci calculations, and trading via MCP clients such as Claude.
    MIT