🔧 MCP 工具编排是什么?
MCP(Model Context Protocol)工具编排是 OpenClaw 的高级特性,让 Agent 能够:动态发现工具、多服务协同、智能路由到最优工具。相比简单的工具调用,编排提供了:
- 动态加载 - 运行时根据任务需求加载不同 MCP 服务
- 工具链组合 - 将多个 MCP 工具串联成流水线
- 智能路由 - 根据参数自动选择最合适的工具版本
- 容错降级 - 主工具失效时自动切换到备用工具
💡 核心价值:企业微信 + 飞书 + GitHub + 数据库,四大 MCP 服务统一编排,一个 Agent 搞定所有企业自动化需求。
🚀 配置多 MCP 服务
1. Gateway 配置多个 MCP 服务
# gateway.yaml
mcp:
servers:
- name: wecom
url: "http://localhost:3001/mcp"
auth_token: "${WECOM_MCP_TOKEN}"
timeout: 30s
tools: ["contact", "message", "doc"]
- name: feishu
url: "http://localhost:3002/mcp"
auth_token: "${FEISHU_TOKEN}"
timeout: 30s
tools: ["doc", "wiki", "bitable"]
- name: github
url: "https://api.github.com/mcp"
auth_token: "${GITHUB_TOKEN}"
timeout: 45s
tools: ["repo", "pr", "issue"]
2. 工具路由配置
让 OpenClaw 根据任务自动选择工具:
# tool-routing.yaml
routes:
- pattern: ".*企业微信.*|.*wecom.*"
server: wecom
tool: message/send
- pattern: ".*飞书文档.*|.*feishu doc.*"
server: feishu
tool: doc/write
- pattern: ".*GitHub.*|.*PR.*"
server: github
tool: pr/create
# 兜底路由
- pattern: ".*"
server: wecom
fallback: true
💡 动态工具发现
场景:用户说「给张三发消息」
1. OpenClaw 分析意图 → 需要「发送消息」工具
2. 查询 tool-routing.yaml → 匹配到 wecom/message/send
3. 检查 wecom MCP 服务状态 → 健康
4. 调用 wecom_mcp call message send '{"to": "张三", "text": "..."}'
5. 返回结果给 Agent
工具链组合示例
# 复杂任务:从 GitHub 拉取数据 → 写入飞书表格 → 企业微信通知
tool_chain:
- step: 1
server: github
tool: repo/list
output: "repos"
- step: 2
server: feishu
tool: bitable/create_record
input: "${repos}" # 引用上一步输出
- step: 3
server: wecom
tool: message/send
input: "表格已更新,共 ${repos.length} 条记录"
📝 实战:企业自动化工作流
完整案例:每日代码审查报告
# Agent 任务
"每天 18:00 自动执行:
1. 从 GitHub 获取当天所有 PR
2. 分析代码质量(调用 code-review skill)
3. 结果写入飞书多维表格
4. 企业微信群发送摘要通知"
# OpenClaw 配置
cron:
- name: "daily-code-review"
schedule: "0 18 * * *"
workflow:
- github: pr/list (today)
- skill: code-review (analyze each PR)
- feishu: bitable/create_record (write results)
- wecom: message/send (notify group)
💡 最佳实践
- 服务健康检查 - 每个 MCP 服务配置
health_check端点,失败时自动摘除 - 超时分级 - 查询类 5s,写入类 30s,大文件 60s
- 认证管理 - 用环境变量存储 Token,避免硬编码
- 工具缓存 - 对不常变的工具列表启用缓存,减少发现延迟
- 错误隔离 - 单个 MCP 服务故障不影响其他服务调用
⚠️ 注意事项
常见问题:
- MCP 服务需单独部署,OpenClaw 不负责启动这些服务
- 工具名称冲突时,按 routes 配置的顺序优先匹配
- 动态加载会增加首次调用延迟(约 500ms-2s)
- 部分 MCP 服务不支持 streaming,需确认后再配置