MCP 接入 LLM¶
让 Claude / GPT / Cursor / Continue 等 LLM 客户端拿到 19 个富途工具(行情 + 账户 + 交易)。
两种模式¶
- LLM 客户端启动
futu-mcp作为子进程 - stdin/stdout 传协议帧
- 一个 LLM 客户端独占一个 futu-mcp 进程
- 最简单,大多数 LLM 客户端默认这么接
futu-mcp作为独立服务监听端口- 多个 LLM 客户端可以连同一个 server
- 每个请求可以带自己的
Authorization: Bearer <token>(v1.1+),audit / 限额各记各的 - 适合团队共享 + 多租户
1. 前置:有一把带 trade:simulate 的 key¶
先按 API Key 授权配置 生成一把:
./futucli gen-key \
--id claude-bot \
--scopes qot:read,acc:read,trade:simulate \
--allowed-markets HK,US \
--max-order-value 50000 \
--max-orders-per-minute 3
把明文(fc_xxxx...)记下。
2. stdio 模式接入 Claude Desktop¶
编辑 Claude Desktop 配置(macOS:~/Library/Application Support/Claude/claude_desktop_config.json):
claude_desktop_config.json
{
"mcpServers": {
"futu": {
"command": "/usr/local/bin/futu-mcp",
"args": [
"--gateway", "127.0.0.1:11111",
"--keys-file", "/home/you/.config/futu/keys.json"
],
"env": {
"FUTU_MCP_API_KEY": "fc_8a3f2b9c1e5d7a4b8c2f9e1d3a5b7c9f"
}
}
}
}
重启 Claude Desktop,新开对话,左下角会出现 "futu" 工具图标。你可以问:
"帮我查一下腾讯控股和苹果的最新报价"
Claude 会调 futu_get_quote / futu_get_snapshot 等工具,把结果整理给你。
3. stdio 模式接入 Cursor / VS Code Continue¶
Cursor:编辑 ~/.cursor/mcp.json:
{
"mcpServers": {
"futu": {
"command": "futu-mcp",
"args": ["--gateway", "127.0.0.1:11111", "--keys-file", "/path/to/keys.json"],
"env": { "FUTU_MCP_API_KEY": "fc_xxxx..." }
}
}
}
Continue:~/.continue/config.json 的 experimental.modelContextProtocolServers 数组里加同样一项。
4. HTTP 模式(多 LLM 共享)¶
# 在服务端启一个 HTTP MCP server
./futu-mcp --gateway 127.0.0.1:11111 \
--keys-file /etc/futu/keys.json \
--http-listen 0.0.0.0:38765 \
--audit-log /var/log/futu-mcp-audit.jsonl
客户端配置改成指向 HTTP endpoint(具体看客户端支持):
{
"mcpServers": {
"futu": {
"type": "http",
"url": "http://<server>:38765/mcp",
"headers": {
"Authorization": "Bearer fc_bot_a_xxxx..."
}
}
}
}
多租户:每个 LLM 客户端带自己的 Bearer token → audit / 限额按各自 key 分开记。
- Bot A:
Authorization: Bearer fc_bot_a_xxx→ 用 bot_a 的 scope / 限额 - Bot B:
Authorization: Bearer fc_bot_b_xxx→ 用 bot_b 的 - /metrics:
curl http://<server>:38765/metrics(无需 token)
5. 工具清单¶
摘要:
| 分类 | 工具 | scope |
|---|---|---|
| 行情 | futu_get_quote / futu_get_kline / futu_get_orderbook / futu_get_ticker / futu_get_rt / futu_get_snapshot / futu_get_static / futu_get_broker / futu_ping |
qot:read |
| 板块 | futu_list_plates / futu_plate_stocks |
qot:read |
| 账户 | futu_list_accounts / futu_get_funds / futu_get_positions / futu_get_orders / futu_get_deals |
acc:read |
| 交易 | futu_place_order / futu_modify_order / futu_cancel_order |
trade:real or trade:simulate |
6. 安全提示¶
- 先用
trade:simulate走一周再切trade:real - 开审计 + 低阈值限额:
--max-order-value 10000 --max-daily-value 50000 --max-orders-per-minute 3 - unlock_trade 不给 LLM:解锁交易走
futucli unlock-trade手动,密码永不经过 LLM - 配
--audit-log:所有 LLM 调用的交易动作都被记录到 JSONL,可事后追溯
排错¶
| 症状 | 可能原因 |
|---|---|
| Claude 看不到工具 | 配置 JSON 语法错 / binary 路径错 / keys.json 无读权限 |
| 调用返回 "missing scope" | key 没开对应 scope,futucli list-keys 确认 |
| 调用返回 "limit check failed: rate limit" | 速率超了,等 60 秒或加 --max-orders-per-minute |
| HTTP 模式 401 | Bearer header 没传,或 token 拼错 |
| MCP 显示 "gateway not connected" | futu-opend 没启,或 --gateway 地址错 |