tradebox-mcp
tradebox-mcp
AI 交易代理的通知数据器 + 熔断器。
交易所开始允许 AI 代理进行交易——而它们承认自己看不到代理到底在 思考 什么。tradebox 是一个本地代理,位于你的 LLM(Claude、Cursor 或任何 MCP 主机)和任何经纪商 MCP 服务之间。它会记录每笔工具调用 以及代理收到决策过程,并且会交易*到达交易所之前拦截任何超出你限制的订单。
零代理改动 —— 将 MCP 主机指向 tradebox 而不是经纪商服务器,代理所见工具完全一样。
本地优先 —— API 密钥直接进入经纪商子进程。tradebox 从不解析、记录或传输它们,并且自身零网络调用。
拒绝 ≠ 死机 —— 被拦截的订单会以自然语言工具结果的形式返回,代理可以读取并调整适应,而不是收到让代理陷入重试循环的协议错误。
工作原理
tradebox 在两端采用 MCP:对它对应的主机,它是一个 服务器;对每一个它启动的经纪商 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 live2. 将 MCP 主机指向 tradebox,而不是经纪商服务器(以 claude_desktop_config.json 或 .cursor/mcp.json 为例):
{
"mcpServers": {
"trading": {
"command": "npx",
"args": ["-y", "tradebox-mcp", "run", "--config", "~/.tradebox/config.yaml"]
}
}
}3. (可选但推荐) 在智能体的系统提示词中加入一行,让黑匣子记录得的不只是动作,还有推理过程:
*在每次做出交易决定之前,调用一次
log_reasoning工具,说明这么做。
只需第一步,代理看到的依旧是常见的 ccxt__createOrder、ct:__fetchTicker…… 代理端不需要任何改动。
安全护栏
护栏 | 配置项 | 作用 |
代码白名单 |
| 拒绝你的列表之外的任何订单 |
单笔订单金额上限 |
| 拒绝超过上限的单笔订单(市价单按不超过 60 秒前的 ticker 价格估值,否则以“李获得行情”为由拒绝) |
频率限制 |
| 失控循环断路器——代理线程最常见是挂起死循环的真实故障模式(滑动 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 均返回一致的答复,所有模拟结果都会打上 "simulated": true 标记。先用试运行模式跑代理一周,阅读报告,再拨动正式开关。
黑匣子(Blackbox)
每一次调用,无论放行或拒绝,都会追加到 ~/.tradebox/logs/YYYY-MM-DD.jsonl,一行为一个 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 downstream 即(CCXT MCP 和同类型);对 Binance Agent OS / Robinhood MCP 的 HTTP 传输支持路线图上的优先事项。
每日亏损熔断只能看到在 proxy 中经过的单。 成交素材会同时从 order 结果代理以及代理自身的
fetch_my_trades/fetch_closed_orders调用中解析。如果一个代理从不取回它的成交价,那么熔断器就形同虚设。持仓跟踪是近似值,它根据经过代理的订单推发力;暂时没有旗下有余额核对。
试运行的撮合是即时模拟的。 真实持仓/余额读取原样透传,不会反映模拟的交易结果(但每条模拟结果都带着
"simulated": true)。所有日期边界以 UTC 为准。 同一时间只运行一个代理,构成一条实例。
如何贡献规则
像一个文件像一个环动 indicator——欢迎 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 开源
License
MIT
This server cannot be installed
Maintenance
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
- FlicenseNot gradedqualityNot gradedmaintenanceA 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.

SentinelGateofficial
AlicenseNot gradedqualityAmaintenanceOpen-source MCP proxy that enforces security policies, content scanning, and audit logging between AI agents and tool servers25AGPL 3.0- AlicenseNot gradedqualityAmaintenanceSecurity 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.21MIT
- AlicenseAqualityAmaintenanceEnables AI agents to operate a local financial terminal, including market data, backtesting, paper portfolio management, and news digest, through safe, gated tools over MCP.6MIT
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.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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