MCP Server
将你的 ClawButler 实例暴露为 MCP(Model Context Protocol)服务器,让 Claude、Cursor、Windsurf 等 AI 助手直接管理你的 Agent。
当前状态#
工作原理#
MCP Server 是 AI 助手与 ClawButler API 之间的轻量协议桥梁。它将自然语言意图转换为结构化的 API 调用,让你可以通过任何 MCP 兼容客户端管理 Agent 舰队。
┌──────────────────┐ stdio / HTTP ┌─────────────────┐ REST API ┌──────────────────┐
│ AI 助手 │ ◄──────────────────► │ MCP Server │ ◄─────────────► │ ClawButler API │
│ (Claude 等) │ MCP 协议 │ (clawbutler- │ Bearer Token │ (FastAPI) │
│ │ │ mcp) │ │ │
└──────────────────┘ └─────────────────┘ └──────────────────┘安装与配置#
MCP Server 是一个独立的 Python 包,连接到你的 ClawButler API。安装后配置你的 AI 助手即可使用。
# 从 PyPI 安装
pip install clawbutler-mcp
# 或使用 uvx 直接运行(零安装)
uvx clawbutler-mcp
# 设置环境变量
# 自动化场景优先使用组织级 service token
export CLAWBUTLER_API_URL=https://your-instance.clawbutler.cc
export CLAWBUTLER_TOKEN=cb_srv_your_service_tokenIDE 配置#
Claude Desktop
添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"clawbutler": {
"command": "uvx",
"args": ["clawbutler-mcp"],
"env": {
"CLAWBUTLER_API_URL": "https://your-instance.clawbutler.cc",
"CLAWBUTLER_TOKEN": "your-token"
}
}
}
}Claude Code
添加到项目的 .mcp.json:
{
"mcpServers": {
"clawbutler": {
"command": "uvx",
"args": ["clawbutler-mcp"],
"env": {
"CLAWBUTLER_API_URL": "https://your-instance.clawbutler.cc",
"CLAWBUTLER_TOKEN": "your-token"
}
}
}
}Cursor
添加到 ~/.cursor/mcp.json(全局)或 .cursor/mcp.json(项目级):
{
"mcpServers": {
"clawbutler": {
"command": "uvx",
"args": ["clawbutler-mcp"],
"env": {
"CLAWBUTLER_API_URL": "https://your-instance.clawbutler.cc",
"CLAWBUTLER_TOKEN": "your-token"
}
}
}
}Windsurf
添加到 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"clawbutler": {
"command": "uvx",
"args": ["clawbutler-mcp"],
"env": {
"CLAWBUTLER_API_URL": "https://your-instance.clawbutler.cc",
"CLAWBUTLER_TOKEN": "your-token"
}
}
}
}Streamable HTTP(远程部署)
容器化或远程部署时,使用 HTTP 传输模式:
clawbutler-mcp --transport http --port 8080可用工具#
当前工具覆盖治理主线。点击任意工具查看参数详情。
Agent 管理(7 个工具)
list_agents, get_agent, get_agent_governance_view, enable_agent, disable_agent, set_agent_lifecycle, get_agent_config
包含 Agent 操作、生命周期切换、治理摘要和配置查看。
成本与预算(4 个工具)
get_cost_summary, get_cost_by_agent, get_cost_trend, list_budgets
支持日期范围成本追踪、按 Agent 拆分、趋势分析和预算监控。
配置安全(5 个工具)
list_config_snapshots, take_config_snapshot, diff_config_snapshots, preview_rollback, execute_rollback
配置安全能力,包含浏览快照、手动保存点、语义 diff、dry-run 回滚和正式回滚。
审计与活动(3 个工具)
search_audit_events, get_audit_event, get_recent_activity
提供多维筛选的审计搜索和最近活动流,适合调查取证。
连接器(4 个工具)
list_connectors, get_connector_detail, test_connector, diagnose_connector
网关连接器管理,支持列表、详情、连通性测试与诊断。
智能分析(4 个工具)
get_root_cause_analysis, get_reliability_scores, get_agent_reliability, get_value_comparison
智能分析面,覆盖根因分析、可靠性评分和价值对比。
运维操作(6 个工具)
get_killswitch_status, activate_killswitch, deactivate_killswitch, check_health, get_trust_status, get_dashboard
运维操作面,覆盖 Kill Switch、健康检查、信任状态与仪表盘摘要。
Runbook 自动化(4 个工具)
list_runbooks, get_runbook, execute_runbook, get_runbook_run
Runbook 自动化能力,支持浏览、带参数执行以及单次运行追踪。
治理预览(4 个工具)
preview_policy_decision, get_runtime_host_card, preview_task_grant, record_governance_evidence
预览策略与 task grant 判定、复用稳定 RuntimeHostCard,并在不开放更大写面的前提下补治理证据。
运行时主机(9 个工具)
list_runtime_hosts, get_runtime_host_detail, get_runtime_host_governance_view, discover_runtime_host, batch_add_runtime_host_instances, sync_runtime_host_sessions, get_runtime_host_managed_state, list_runtime_host_managed_sessions, list_runtime_host_managed_permissions
对已配对机器做 Hermes / Claude Code / Codex / OpenClaw 发现、治理预览、批量接入连接器、同步 attach-mode 会话,并查看托管状态 / 会话 / 待审批请求。
工具参数参考#
当前 MCP surface 的参数参考。点击工具名展开参数。标记 * 的参数为必填。
Agent 管理
成本与预算
配置安全
审计与活动
连接器
智能分析
运维操作
Runbook 自动化
治理预览
运行时主机
输出示例#
工具返回格式化的 Markdown 字符串。以下是 AI 助手实际收到的输出示例:
list_agents"列出我所有的 Agent"- **coordinator** (id: aaa-bbb-…) [on] health=healthy platform=openclaw
- **researcher** (id: fff-ggg-…) [off] health=error platform=openclaw
- **writer** (id: ccc-ddd-…) [on] health=warning platform=codexget_cost_summary"最近一周的成本是多少?"**Cost Summary** (2026-03-10 → 2026-03-17)
- Total cost: $42.5678
- Input tokens: 1,234,567
- Output tokens: 654,321
- Records: 150diff_config_snapshots"对比 agent coordinator 的配置版本 3 和 4"**Config Diff** v3 → v4
Summary: Model changed
- [modified] `model.primary`: claude-sonnet-4-5 → claude-sonnet-4-6
- [added] `tools.web_search`: — → enabled
- [removed] `skills.deprecated_skill`: active → —check_health"运行健康检查"**Health Check**
- Status: ready
- Version: 0.1.0
- Dependencies:
- postgres: ok
- valkey: ok
- Worker: running (mode=embedded)get_dashboard"显示仪表盘"**Dashboard Summary**
- Agents: 12 online / 14 total
- Today's cost: $8.4321
- Events today: 67
- Pending approvals: 2
- Unread notifications: 5MCP 资源#
资源提供只读快照,AI 助手可以在调用工具之前将其作为上下文使用。
clawbutler://dashboard仪表盘摘要 — Agent 数量、今日成本、事件、待审批。
clawbutler://agentsAgent 列表(ID、名称、状态、平台)。
clawbutler://cost/today今日成本快照。
clawbutler://health系统就绪状态和依赖健康。
使用示例#
晨间运维检查
让 AI 助手为你做一个 Agent 舰队的晨间简报。
"检查一下我的 ClawButler 仪表盘 — 多少 Agent 在线,
今天的成本是多少,有没有待审批的?"成本追查
不离开编辑器,直接深入分析成本异常。
"显示最近 7 天按 Agent 的成本明细。
哪个 Agent 花费最高?"应急响应
AI 辅助的事故响应 — Kill Switch 加审计追踪。
"Agent coordinator 行为异常。
检查它的健康状态,然后激活 Kill Switch,
原因填'行为异常 — 调查中'。"配置回滚
审查并回滚一个错误的配置变更。
"列出 agent coordinator 最近 5 个配置快照。
对比版本 3 和 4 的 diff,然后预览回滚到版本 3。"审计追查
搜索审计事件,追踪谁在什么时候做了什么变更。
"搜索最近 3 天 risk_level=high 的审计事件。
显示最新一条的完整详情。"连接器诊断
诊断网关连接问题。
"列出我的连接器。OpenClaw 网关似乎变慢了 —
对它运行一次诊断,告诉我什么问题。"Runtime Host 发现与托管检查
在已配对机器上发现 Hermes / Claude Code / Codex / OpenClaw 实例,只接入需要治理的实例,把 attach-mode 会话投影到 ClawButler,并继续查看托管会话摘要与待审批请求。
"列出我的 Runtime Hosts。对已配对的 MacBook 执行发现,
把 Codex 和 Claude Code 实例添加成 connectors,
然后同步最近的 attach-mode 会话供调查使用,
再显示 Codex 实例的托管会话,
并列出待处理的托管审批请求。"覆盖对比#
MCP 已支持
- - Agent 增删改查和启停
- - 成本汇总、按 Agent 明细、趋势、预算
- - 配置快照、手动保存点、语义 diff、回滚
- - 审计事件搜索和活动流
- - 连接器列表、测试、诊断
- - 智能分析(根因分析、可靠性、价值)
- - Kill Switch(激活 / 解除)
- - 健康检查和信任状态
- - 仪表盘 KPI
- - Runbook 执行和追踪
- - 策略决策预览、RuntimeHostCard 查询、task grant 预览和治理证据写入
- - Runtime Host 的 list/detail/discover/batch-add/sync,以及 managed state/session/permission inspection,用于 Hermes / Claude Code / Codex / OpenClaw 的 attach-mode 接入与只读托管检查
后续版本(V2)
- - 用户注册 / 组织管理 / RBAC
- - Evidence 列表 / 详情工作流
- - 模板画廊完整生命周期
- - 轻量 Reports 页面与订阅管理
- - 通知管理
- - Hermes / Claude Code / Codex Runtime Host 的 provider-native 审批、成本归因、时间线和托管控制
- - 破坏性操作(Kill Switch、回滚)在 tool description 中明确标注,AI 助手会在执行前确认。
- - 认证仍使用和 CLI / API 一样的 Bearer Header。自动化应优先使用最小权限的组织级 service token,例如 read、read_connectors、operate_governance、operate_approvals、operate_runbooks。
- - 读多写少的设计 — 大部分工具是读操作;写操作需要显式参数。
- - MCP 可以预览 task grant rollout 并补治理证据,但不会直接签发 runtime_host_task_grant;真正的签发仍留在 API / CLI 执行链路。
- - Runtime Host 同步当前仍是 attach-mode 投影能力,而 MCP 里的 managed state / session / permission 也刻意保持只读;这都不等价于 Hermes / Claude Code / Codex 的 provider-native 治理闭环,service token 的写权限覆盖也保持最小。
常见问题#
「Tool not found」或 IDE 中不显示工具
确认 clawbutler-mcp 已安装且命令路径正确。运行 `uvx clawbutler-mcp --help` 验证。检查 IDE 的 MCP 日志是否有连接错误。
401 Unauthorized / 认证错误
确认 CLAWBUTLER_TOKEN 设置正确。长期自动化建议通过 API 或 `ap service-token create` 创建组织级 service token;短期交互式场景仍可继续使用普通用户 access token。
连接被拒绝 / 超时
检查 CLAWBUTLER_API_URL 指向正在运行的 ClawButler 实例。自部署环境需确保 MCP Server 运行的机器可以访问到 API。
工具可以调用但返回空数据
通常是因为 API 返回了空数组 — 你的实例可能还没有配置 Agent/成本/连接器。先试 get_dashboard 验证连通性。
如何在 Docker / 远程服务器中使用?
使用 HTTP 传输:`clawbutler-mcp --transport http --port 8080`。这会启动一个 Streamable HTTP 服务,任何 MCP 客户端都可以通过网络连接。
安全建议#
- - 不要将 Token 提交到版本控制。如果 .mcp.json 包含凭据,请将其添加到 .gitignore。
- - 使用环境变量或密钥管理器存储 Token — 避免在配置文件中硬编码。
- - MCP Server 继承其使用的 Token 权限。自动化应优先使用最小权限的组织级 service token。
- - 共享环境中,优先使用 HTTP 传输 + 网络级访问控制(VPN、防火墙规则),而非公开暴露。