openclaw mcp电桥
用于OpenClaw和其他MCP客户端的智能MCP桥。
该项目连接多个MCP服务器,并通过一个接口公开它们,具有相关性过滤和可选缓存功能。
项目状态
此包目前尚未发布到npm。 通过克隆此存储库在本地使用它。
快速入门(本地)
先决条件
- Node.js
20.19+(推荐) pnpm- OpenClaw(仅当你想要插件模式时)
克隆和构建
git clone https://github.com/gabrielekarra/openclaw-mcp-bridge.git
cd openclaw-mcp-bridge
pnpm install
pnpm build使用模式
1.OpenClaw插件(本地)
从本地存储库安装插件:
openclaw plugins install .
openclaw gateway restart在中启用/配置它 ~/.openclaw/openclaw.json:
{
"plugins": {
"entries": {
"mcp-bridge": {
"enabled": true,
"config": {
"autoDiscover": true
}
}
}
}
}笔记:
- 插件密钥必须为
mcp-bridge(比赛openclaw.plugin.json). - 随着
autoDiscover: true,它从以下位置读取MCP服务器~/.mcp.json.
2.独立MCP服务器
直接运行网桥服务器:
pnpm start -- --config ./examples/bridge-config.json您也可以直接使用Node运行它:
node dist/server/index.js --config ./examples/bridge-config.json对于Claude Desktop,请将此添加到 claude_desktop_config.json:
{
"mcpServers": {
"bridge": {
"command": "node",
"args": [
"/absolute/path/to/openclaw-mcp-bridge/dist/server/index.js",
"--config",
"/absolute/path/to/openclaw-mcp-bridge/examples/bridge-config.json"
]
}
}
}操作模式
网桥支持两种操作模式(OpenClaw插件模式和独立MCP服务器模式),由一个配置键控制:
{
"mode": "smart"
}smart(默认,原始设计):使用相关性分析、排名、阈值和可选缓存。traditional:在启动时注册所有发现的MCP工具,不进行相关性过滤或延迟工具激活。
迁移说明:
- 如果您希望所有MCP工具始终可见,请使用
mode: traditional.
智能模式示例(默认)
{
"plugins": {
"entries": {
"mcp-bridge": {
"enabled": true,
"config": {
"mode": "smart",
"autoDiscover": true
}
}
}
}
}传统模式示例
{
"plugins": {
"entries": {
"mcp-bridge": {
"enabled": true,
"config": {
"mode": "traditional",
"autoDiscover": true
}
}
}
}
}独立模式示例
examples/bridge-config.json 形状:
{
"mode": "smart",
"autoDiscover": true
}{
"mode": "traditional",
"autoDiscover": true
}已注册工具(插件模式)
智能模式工具
mcp_find_tools
从连接的MCP服务器中查找可用工具。
示例:
- “查找创建GitHub问题的工具”
- “Notion有哪些可用工具?”
- “列出所有MCP工具”
行为:
- 如果
need如果存在,则按相关性对工具进行排名。 - 如果
need如果为空/缺失,则返回可用工具(为可读性而设上限)。 - 结果包括
server+name使用的值mcp_call_tool.
mcp_call_tool
调用由返回的下游工具 mcp_find_tools.
必需参数:
server(字符串)tool(字符串)
可选参数:
arguments(对象)
示例呼叫有效载荷:
{
"server": "notion",
"tool": "create_page",
"arguments": {
"title": "Roadmap"
}
}mcp_list_servers
列出已配置的MCP服务器及其发现的工具计数。
示例:
- “连接了哪些MCP服务器?”
- “显示可用服务器”
传统模式工具
- 在启动时注册每个发现的MCP工具。
- 工具名称的命名空间为
mcp__. - 每个注册的工具直接调用其底层MCP服务器工具。
独立行为总结:
mode: smart暴露find_tools加上压缩的下游工具条目。mode: traditional仅公开命名空间的下游工具(否find_tools元工具)。
流程是如何工作的
- 用户要求执行可能需要外部工具的任务。
- 客服电话
mcp_find_tools. - Bridge在MCP服务器上发现工具并对匹配进行排名。
- 客服电话
mcp_call_tool与所选server+tool. - 网桥将呼叫路由到正确的MCP服务器。
配置
自动发现来自 ~/.mcp.json
启用后,网桥从以下位置导入服务器 ~/.mcp.json.
例子:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"]
},
"notion": {
"command": "npx",
"args": ["-y", "@notionhq/mcp-server"]
}
}
}显式服务器配置
您可以提供 servers 在插件配置中明确:
{
"plugins": {
"entries": {
"mcp-bridge": {
"enabled": true,
"config": {
"autoDiscover": false,
"servers": [
{
"name": "github",
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"categories": ["code", "issues", "repos"]
}
]
}
}
}
}
}看 examples/ 用于即用型配置。
独立注释:
loadConfig()接受两种独立的桥梁形状({ mode, servers, ... })和OpenClaw插件形状(plugins.entries["mcp-bridge"].config).
配置参考
| 选项 | 类型 | 默认值 | 描述 | |
|---|---|---|---|---|
mode | `"smart" \ | "traditional"` | "smart" | 操作模式 |
servers | 阵列 | [] | 显式MCP服务器定义 | |
autoDiscover | 布尔值 | true | 从以下位置加载服务器 ~/.mcp.json | |
analyzer.maxToolsPerTurn | 编号 | 5 | 返回的最大排名工具(smart 仅模式) | |
analyzer.relevanceThreshold | 编号 | 0.3 | 最低相关性得分(smart 仅模式) | |
cache.enabled | 布尔值 | true | 启用结果缓存(smart 仅模式) | |
cache.ttlMs | 编号 | 30000 | 缓存TTL(毫秒)(smart 仅模式) | |
cache.maxEntries | 编号 | 100 | 最大缓存条目数(smart 仅模式) |
发展
pnpm install
pnpm build
pnpm test
pnpm lint故障排除
| 问题 | 可能原因 | 修复 |
|---|---|---|
plugin not found: mcp-bridge | 插件未在本地安装 | 运行 openclaw plugins install . 从repo根目录 |
| 未检测到MCP服务器 | 缺失 ~/.mcp.json 没有明确的 servers | 添加 ~/.mcp.json 或设置 servers 在插件配置中 |
| 工具与用户意图不匹配 | 查询范围太窄/阈值太高 | 范围太广 need 文本或更低 analyzer.relevanceThreshold |
| 工具已找到但未执行 | 代理尝试直接调用工具 | 调用 mcp_call_tool 随着 { server, tool, arguments } |
| 独立服务器未启动 | 节点版本错误 | 使用节点 20.19+ |
@modelcontextprotocol/ext-apps 较新Node版本的安装后警告 | 可选安装脚本警告 | 此项目无害;安装/构建可以继续 |
许可证
麻省理工学院
