tradebox-mcp
tradebox-mcp
AIトレードエージェント向けのフライトレコーダーとサーキットブレーカー。
取引所はAIエージェントにトレードを認め始めていますが、エージェントが何を考えているかは見えていないと認めています。tradeboxは、あなたのLLM(Claude、Cursor、または任意のMCPホスト)と、任意のブローカーMCPサーバーの間に配置するローカルプロキシです。すべてのツール呼び出しとエージェントの推論を記録し、あなたの制限を超える注文を、取引所に届く前にブロックします。
エージェントの変更はゼロ — MCPホストの接続先をブローカーサーバーの代わりにtradeboxへ向けるだけ。エージェントにはまったく同じツールが見えます。
ローカルファースト — あなたのAPIキーはブローカーの子プロセスにそのまま渡ります。tradeboxがそれらをパース・ログ記録・送信することはなく、自分自身でのネットワーク呼び出しはゼロです。
拒否 ≠ クラッシュ — ブロックされた注文は、プロトコルエラーとしてリトライループに送られるようではなく、エージェントが読んで対応できる平易な言葉のツール結果として返ります。
仕組み
tradeboxは両側でMCPを話します。あなたのホストに対してはサーバー、ス執行した各ブローカーサーバーに対してはクライアントとして機能します。
flowchart LR
subgraph HOST["Your machine"]
A["MCP host<br/>(Claude Desktop / Cursor)"]
subgraph TB["tradebox-mcp"]
G["Guardrail engine<br/>(allow / deny)"]
R["Recorder<br/>(JSONL blackbox)"]
end
C["CCXT MCP server<br/>(child process)"]
L[("~/.tradebox/logs/<br/>YYYY-MM-DD.jsonl")]
end
X["Exchange<br/>(Binance, …)"]
A -- "stdio (JSON-RPC / MCP)" --> G
G -- "allowed calls only" --> C
G -.-> R
R -.-> L
C -- "HTTPS (your API keys<br/>never leave this hop)" --> Xすべてのtools/callは同じパイプラインを通過します:
sequenceDiagram
participant Agent as Agent (LLM)
participant TB as tradebox
participant Broker as CCXT MCP
participant Ex as Exchange
Note over Agent,Ex: ✅ order within limits
Agent->>TB: createOrder BTC/USDT, $150
TB->>TB: classify → trade.place<br/>guardrails → ALLOW
TB->>Broker: forward
Broker->>Ex: place order
Ex-->>Broker: filled
Broker-->>TB: result
TB->>TB: log call + result (JSONL)
TB-->>Agent: result
Note over Agent,Ex: ⛔ order over the limit
Agent->>TB: createOrder DOGE/USDT, $520
TB->>TB: classify → trade.place<br/>guardrails → DENY (allowed_symbols)
TB->>TB: log the denial
TB-->>Agent: "Order denied: DOGE/USDT is not<br/>in allowed_symbols (BTC/USDT, ETH/USDT)."
Note over Agent: agent reads the reason<br/>and adjusts — no crash loopルールが拒否した注文はブローカープロセスに一切届きません。拒否は、APIキーが関与する直前のプロセスで行われます。
Related MCP server: PitBridge
クイックスタート
1 — 設定ファイルを作成する(キーはあなたのマシンに残ります。chmod 600を設定しておきましょう):
mkdir -p ~/.tradebox
cp config.example.yaml ~/.tradebox/config.yaml
chmod 600 ~/.tradebox/config.yaml# ~/.tradebox/config.yaml (minimal)
downstreams:
ccxt:
command: npx
args: ["-y", "@lazydino/ccxt-mcp", "--config", "~/.tradebox/ccxt-accounts.json"]
# ccxt-accounts.json holds your exchange keys (see config.example.yaml).
# Use a read + trade key. NEVER enable withdrawals on it.
guardrails:
allowed_symbols: ["BTC/USDT", "ETH/USDT"]
max_order_notional: 200 # $ per single order
max_orders_per_hour: 6
max_daily_loss: 100 # trips the circuit breaker (UTC day)
dry_run: true # ON by default — flip to false to go live2 — ブローカーサーバーの代わりに、MCPホストの接続先をtradeboxへ向ける(claude_desktop_config.jsonまたは.cursor/mcp.json):
{
"mcpServers": {
"trading": {
"command": "npx",
"args": ["-y", "tradebox-mcp", "run", "--config", "~/.tradebox/config.yaml"]
}
}
}3 —(任意ですが推奨)エージェントのシステムプロンプトに1行追加する。ブラックボックスがアクションだけでなく推論も記録するように:
取引の判断をする前に、
log_reasoningツールを呼び出し、これから行うこととその理由を短く説明してください。
これだけです。エージェントは、今までどおりccxt__createOrder、ccxt__fetchTicker、……を利用できます。エージェント側の変更は一切ありません。
ガードレール
ルール | 設定キー | 動作 |
シンボルのホワイトリスト |
| リストにない注文をすべて拒否 |
注文サイズの上限 |
| 上限を超える単一の注文を拒否(成行注文は60秒以内のティッカー価格で評価し、それ以外は「先にティッカーを取得してください」と拒否) |
レート制限 |
| 暴走ループ防止 — バグのあるエージェントで最も典型的な、実際の障害モード(スライド式1時間ウィンドウ) |
日次損失ブレーカー |
| メインのサーキットカートレーカー — 下の図を参照 |
取引時間帯 |
| UTCの時間ウィンドウ内の注文のみ許可 |
送金 | (組み込み) | デフォルトでビューの拒否。取引エージェントが資金を出金する理由はありません。有効にするには、明示的な |
未知のツール |
| どのマップも認識しないツールで、変更を伴うように見えるものは、読み取り専用と見なさず拒否 |
パニックボタン |
| エージェントの実行中を含め、すべての取引ツールを即座に拒否 |
サーキットブレーカーのライフサイクル
stateDiagram-v2
[*] --> Trading
Trading --> Locked : realized daily PnL ≤ −max_daily_loss
Trading --> Locked : operator runs "tradebox stop"
Locked --> Trading : operator runs "tradebox resume"
Locked --> Locked : every trade.* call → denied<br/>(reads still pass through)
note right of Locked
The lock survives restarts —
state is a projection of the log,
so a crash never resets the breaker.
end noteドライラン:実際の資金を渡す前にエージェントを監査する
dry_run: true(デフォルト)は、プロキシ上で取引をすべてブロックし、実際の取引であるかのようにログに記録し、シミュレーションの約定を返します。tradeboxはシミュレーションの一貫性を保つため、実際は存在しない注文簿を持ちていて、シミュレーションされた注文IDを削除や取得する場合でも、一貫した回答が返ります。また、シミュレーション結果にはすべてタグーが付けられます。
1週間ドライランでエージェントを実行し、レポートを読んで、それからスイッチを切り替えましょう。
ブラックボックス
許可された呼び出しも拒否された呼び出しも、すべて~/.tradebox/logs/YYYY-MM-DD.jsonlに追記され、1行に1つのJSONイベントが記録されます:
{"ts":"2026-08-25T12:00:00.123Z","event":"tool_call","server":"ccxt","tool":"createOrder","category":"trade.place","args":{"symbol":"BTC/USDT","side":"buy","type":"limit","amount":0.02,"price":58900},"decision":"allow","latency_ms":840,"result":{"order_id":"123","filled":0.02,"avg_price":58895}}
{"ts":"2026-08-25T12:05:01.000Z","event":"tool_call","server":"ccxt","tool":"createOrder","category":"trade.place","args":{"symbol":"DOGE/USDT","side":"buy","amount":50000},"decision":"deny","rule":"allowed_symbols","latency_ms":2}
{"ts":"2026-08-25T12:05:04.500Z","event":"reasoning","text":"DOGE blocked. Holding BTC, waiting for the 58K retest."}
{"ts":"2026-08-25T13:00:00.000Z","event":"guardrail_trip","rule":"max_daily_loss","value":-102.5,"limit":-100,"action":"trading_locked"}シークレットはログに記録されません。下流のenvブロックはレコーダーから見えず、key|secret|token|passwordのような名前を持つフィールドはマスク処理されます。
ドリフトレポート — テストしたエージェントは、まだそのエージェントですか?
$ tradebox report --window 7d
AGENT BEHAVIOR REPORT 2026-08-18 → 2026-08-25
──────────────────────────────────────────────────────────
baseline (7d) last 24h Δ
orders/day 4.2 11 ×2.6 ⚠
avg order notional $145 $410 ×2.8 ⚠
symbols traded BTC 82% · ETH 18% +SOL 37% ⚠ new symbol
avg hold time 3.1 h 22 min ÷8.5 ⚠
denied calls 0 7 max_order_notional ×5
realized PnL +$83 −$61
──────────────────────────────────────────────────────────
⚠ BEHAVIORAL DRIFT: the agent is behaving differently than
it did 7 days ago. Model update? Prompt change? Check
before it costs you.オフラインで動作し、ローカルのJSONLのみを読み取り、ネットワークには接続しません。
CLI
tradebox run --config <path> start the proxy (spawned by your MCP host)
tradebox report [--window 7d] behavior + drift report from local logs
tradebox stop PANIC — deny all trading immediately
tradebox resume clear the panic / daily-loss lock正直な制限事項(v0.1)
実際の資金で遭遇するよりも、ここで明示しておきます。
対応する下流はstdioのみ(CCXT MCPなど)。Binance Agent OS / Robinhood MCPのHTTPトランスポートは、ロードマップの最優先事項です。
日次損失ブレーカーは、プロキシを介した約定のみを認識します。約定は、注文結果と、エージェント自身が呼び出す
fetch_my_trades/fetch_closed_ordersの両方から解析されます。約約定を一切取得しないエージェントでは、ブレーカーは機能しません。ポジションの追跡は推定値です。プロキシを通過した注文から構築されており、取引所の残高との照合はまだありません。
ドライランの約定は即座にシミュレーションされます。実際の残高・ポジションの同時取得はそのまま実行され、シミュレーションされた取引は反映されません(すべてのシミュレーション結果には
"simulated": trueが付けられます)。日付境界はすべてUTCです。プロキシのインスタンスは一度に1つだけです。
ルールの貢献方法
1ファイル、1インターフェース — PRを歓迎します:
export interface GuardrailRule {
name: string;
// return null to pass; return a string to deny (the reason is sent to the LLM)
check(call: ClassifiedToolCall, state: SessionState, cfg: Config): string | null;
}src/guardrails/rules/に配置し、れengine.ts`に登録し、テストを追加してください。アーキテクチャの設計判断とその理由は、docs/DESIGN.mdを参照してください。
ロードマップ
HTTPトランスポートプロキシ → Binance Agent OS、Robinhood MCPに対応
取引所の残高と照合したポジションの上限
ホスト型ダッシュボード + リアルタイムアラート — ローカルプロキシとレポートは、今後も無償・MITライセンスであり続けます
ライセンス
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Trading MCP server for AI agents, with live market data, account reads and controlled execution.
Guardrails for trading agents. Built-in risk management, 100+ tools for strategy R&D, 12+ venues.
AgentGuard — 20-tool AI safety MCP: policy preflight, risk scoring, audit logging, rate limits.
Free, read-only directory of 114 AI trading tools: broker MCP servers, market data APIs, bots and backtesters. Sourced facts on who can place orders and what safeguards exist; search, compare and check order gating for every broker MCP.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceSits in front of any MCP server to enforce allow/ask/block policies on tool calls, paths, shell commands, and network domains, with local approval prompts and an audit log.MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with a NinjaTrader 8 futures account through MCP, with deterministic guardrails and hard risk limits enforced locally that the agent cannot bypass.1Apache 2.0
- AlicenseAqualityBmaintenanceEnables AI agents to place and manage Hyperliquid trades through MCP with position, leverage, daily-loss, market, and stop-loss limits enforced outside the model, plus paper trading and an auditable decision log.9176 npmMIT
- AlicenseNot gradedqualityCmaintenanceA transparent MCP stdio proxy that sits between an agent client and a real MCP server, intercepting tools/call requests to enforce runtime guardrails derived from the same YAML rules used for CI regression testing. It blocks forbidden, out-of-whitelist, looping, or non-idempotent tool invocations with JSON-RPC errors and writes every decision to an audit log.1MIT