Skip to main content
Glama
dearvn

tradebox-mcp

by dearvn

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: SentinelGate

クイックスタート

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 live

2 — ブローカーサーバーの代わりに、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__createOrderccxt__fetchTicker、……を利用できます。エージェント側の変更は一切ありません。


ガードレール

ルール

設定キー

動作

シンボルのホワイトリスト

allowed_symbols

リストにない注文をすべて拒否

注文サイズの上限

max_order_notional

上限を超える単一の注文を拒否(成行注文は60秒以内のティッカー価格で評価し、それ以外は「先にティッカーを取得してください」と拒否)

レート制限

max_orders_per_hour

暴走ループ防止 — バグのあるエージェントで最も典型的な、実際の障害モード(スライド式1時間ウィンドウ)

日次損失ブレーカー

max_daily_loss

メインのサーキットカートレーカー — 下の図を参照

取引時間帯

trading_hours

UTCの時間ウィンドウ内の注文のみ許可

送金

(組み込み)

デフォルトでビューの拒否。取引エージェントが資金を出金する理由はありません。有効にするには、明示的なallow_transfers: trueが必要

未知のツール

unknown_tools

どのマップも認識しないツールで、変更を伴うように見えるものは、読み取り専用と見なさず拒否

パニックボタン

tradebox stop

エージェントの実行中を含め、すべての取引ツールを即座に拒否

サーキットブレーカーのライフサイクル

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)

実際の資金で遭遇するよりも、ここで明示しておきます。

  1. 対応する下流はstdioのみ(CCXT MCPなど)。Binance Agent OS / Robinhood MCPのHTTPトランスポートは、ロードマップの最優先事項です。

  2. 日次損失ブレーカーは、プロキシを介した約定のみを認識します。約定は、注文結果と、エージェント自身が呼び出すfetch_my_trades / fetch_closed_ordersの両方から解析されます。約約定を一切取得しないエージェントでは、ブレーカーは機能しません。

  3. ポジションの追跡は推定値です。プロキシを通過した注文から構築されており、取引所の残高との照合はまだありません。

  4. ドライランの約定は即座にシミュレーションされます。実際の残高・ポジションの同時取得はそのまま実行され、シミュレーションされた取引は反映されません(すべてのシミュレーション結果には"simulated": trueが付けられます)。

  5. 日付境界はすべて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を参照してください。

ロードマップ

  1. HTTPトランスポートプロキシ → Binance Agent OS、Robinhood MCPに対応

  2. 取引所の残高と照合したポジションの上限

  3. ホスト型ダッシュボード + リアルタイムアラート — ローカルプロキシとレポートは、今後も無償・MITライセンスであり続けます

ライセンス

MIT

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    Not graded
    maintenance
    A transparent proxy and execution firewall that intercepts and audits AI agent tool calls against configurable security policies before forwarding them to downstream MCP servers. It provides safe execution environments with features like data redaction, anti-loop protection, and unified alert dispatching.
  • A
    license
    Not graded
    quality
    A
    maintenance
    Open-source MCP proxy that enforces security policies, content scanning, and audit logging between AI agents and tool servers
    25
    AGPL 3.0
  • A
    license
    Not graded
    quality
    A
    maintenance
    Security gateway for MCP tool calls. Sits between your LLM client and MCP servers, enforcing per-tool policies (allow/block/approve/read-only), logging every call, and pausing dangerous operations for human approval in terminal or Slack.
    2
    1
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Enables AI agents to operate a local financial terminal, including market data, backtesting, paper portfolio management, and news digest, through safe, gated tools over MCP.
    6
    MIT

View all related MCP servers

Related MCP Connectors

  • Security firewall for AI agents — scans MCP calls for injection, secrets, and risks.

  • MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dearvn/tradebox-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server