MT5 MCP Server
Enables interaction with MetaTrader 5 for market data, technical analysis, Fibonacci calculations, and trading via MCP clients such as Claude.
README
MT5 MCP サーバー
MetaTrader 5 (MT5) と接続し、MCP クライアント(Claude Code / Claude Desktop 等)から マーケットデータ取得・テクニカル分析・フィボナッチ算出・売買発注を行える MCP サーバー。
仕様は docs/specification.md を参照。
必要環境
- Windows 10/11(MT5 Python API は Windows 専用)
- Python 3.12+
- MT5 ターミナルがインストール・ログイン済みであること
- 発注を使う場合: MT5 で「ツール → オプション → エキスパートアドバイザー → アルゴリズム取引を許可」を有効化
セットアップ
cd C:\Users\jun\mt5-mcp
py -m pip install -r requirements.txt
copy .env.example .env # 必要に応じて編集
MT5 が既にログイン済みなら .env の認証情報は省略可能です。
起動
py -m mt5_mcp.server
動作確認(発注なし)
py scripts\smoke_test.py USDJPY
全ツールが [OK] になれば正常です。
MCP クライアントへの登録
claude_desktop_config.json などに以下を追加:
{
"mcpServers": {
"mt5": {
"command": "py",
"args": ["-m", "mt5_mcp.server"],
"cwd": "C:\\Users\\jun\\mt5-mcp"
}
}
}
注意(発注の有効化): 発注の有効/無効は
.envのMT5_TRADE_ENABLEDで決まります。 ただし OS/クライアントの環境変数が.envより優先されます(load_dotenvの既定動作)。 上記 JSON のenvに"MT5_TRADE_ENABLED": "false"を書くと、.envをtrueにしても読み取り専用になります。 発注を有効にしたい場合はenvでこの変数を指定しない(=.envに従う)か、明示的に"true"を渡してください。 サーバ起動ログに発注ツールを登録しました (MT5_TRADE_ENABLED=true)が出れば有効です。 実際の状態は/healthzのtrade_enabledでも確認できます。
リモート公開(Cloudflare トンネル)
MCP を HTTP で公開し、Cloudflare クイックトンネル経由で claude.ai / Cowork 等から接続できます。
サーバ起動とトンネルを 1つのスクリプトで立ち上げます。cloudflared が PATH 上に必要です。
claude.ai / Cowork に登録する場合(-Cowork モード)
claude.ai のカスタムコネクタは静的 Bearer トークンに非対応で、認証は OAuth のみです。
そのためトークン必須で起動すると、claude.ai が 401 を「OAuth が必要」と解釈してOAuth 認証画面を出します。
これを避けるため、認証なし+推測困難な秘密パスで公開する -Cowork モードを使います:
.\start-remote.ps1 -Cowork
- Bearer 認証を無効化(401 を出さない=OAuth 要求が出ない)
- パス未指定なら
/mcp-<ランダム>の秘密パスを自動生成 - 表示された コネクタ URL(
https://<random>.trycloudflare.com/mcp-<random>)をそのまま claude.ai / Cowork のカスタムコネクタに登録(認証は「なし」のまま)
⚠️ セキュリティ:
-Coworkモードはトークンが無いため、URL(ホスト名+秘密パス)を知る者は誰でも接続でき、MT5_TRADE_ENABLED=trueなら実発注も可能です。URL は絶対に共有しないでください。トンネルを再起動すると URL は変わります。閲覧のみで十分なら.envのMT5_TRADE_ENABLED=falseを推奨します。
Bearer トークンで保護する場合(既定モード/curl・Claude Code 等向け)
ヘッダーを送れるクライアント用。Authorization: Bearer <token> で認証します:
$env:MT5_MCP_TOKEN = "<長いランダム文字列>" # 省略時は自動生成
.\start-remote.ps1
ローカル動作確認(トンネルなし・healthz/認証チェック)
powershell -ExecutionPolicy Bypass -File scripts\test_http.ps1
提供ツール(全27ツール)
| カテゴリ | ツール |
|---|---|
| 接続/口座 | mt5_health_check, mt5_account_info, mt5_terminal_info |
| マーケット | mt5_symbols_list, mt5_symbol_info, mt5_quote, mt5_market_depth |
| ヒストリカル | mt5_ohlcv, mt5_ticks |
| 照会 | mt5_positions, mt5_orders, mt5_history_deals, mt5_history_orders |
| 指標 | mt5_indicator, mt5_indicators_batch(SMA/EMA/RSI/MACD/BB/ATR/Stochastic/ADX) |
| フィボナッチ | mt5_swing_points, mt5_fib_retracement, mt5_fib_expansion |
| 複合分析 | mt5_market_snapshot, mt5_analyze, mt5_confluence |
| 発注 ⚠️ | mt5_order_send, mt5_position_close, mt5_position_modify, mt5_order_modify, mt5_order_cancel, mt5_close_all |
発注系は MT5_TRADE_ENABLED=true のときのみ登録されます。
安全機構(発注ガード)
- マスタースイッチ:
MT5_TRADE_ENABLED=false(既定)では発注ツール自体を登録しない - 二段階確認:
confirm=trueの無い発注はorder_checkによるドライラン(プレビュー)に変換 - ロット上限:
MT5_MAX_LOT超過を拒否 - シンボルホワイトリスト:
MT5_ALLOWED_SYMBOLS - スリッページ上限:
MT5_MAX_SLIPPAGEを強制適用 - 監査ログ: 全発注操作を
~/.mt5_mcp/trade_audit.logに記録
⚠️ 発注機能は必ずデモ口座で十分に検証してから本番口座で使用してください。
ライセンス / 注意
本ソフトウェアは MIT License のもとで公開されています。
本ソフトウェアは無保証です。自動売買・発注に伴う損失について作者は責任を負いません。
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.