使用说明
openclaw mcp电桥
MCP(模型上下文协议)客户端插件 龙虾 它通过以下方式将代理连接到远程MCP服务器 流式HTTP 与满 OAuth 2.1 身份验证。
特性
- 可流式HTTP传输 --符合MCP 2025-03-26规范(POST/GET/DELETE+SSE)
- stdio传输 --基于子进程的服务器,使用换行符分隔的JSON-RPC
- 传统SSE运输 --向后兼容的HTTP+SSE(2024-11-05规范)
- OAuth 2.1身份验证 --PKCE(S256)、动态客户端注册、RFC 9728保护的资源元数据、RFC 8414身份验证服务器发现
- API密钥验证 --不需要OAuth的服务器的简单承载令牌替代方案
- 多服务器管理 --使用自动工具命名空间同时连接到多个MCP服务器(
server__tool) - 会话管理 —
Mcp-Session-Id跟踪,会话到期时自动重新初始化 - SSE可恢复性 —
Last-Event-ID断流重新连接 - 动态工具发现 --以可配置的间隔定期重新发现服务器工具
- 热配置重新加载 --无需重新启动即可添加/删除/更新服务器
需求
- Node.js>=22
- OpenClaw>=2025.1.0
安装
npm install openclaw-mcp-bridge
配置
注: 配置键为
plugin-mcp-client(插件ID),而不是npm包名称。
添加到您的 openclaw.json:
{
"plugins": {
"entries": {
"plugin-mcp-client": {
"enabled": true,
"config": {
"servers": {
"tavily": {
"url": "https://mcp.tavily.com/mcp",
"apiKey": "tvly-..."
},
"github": {
"url": "https://mcp.github.com/sse",
"auth": {
"clientId": "your-client-id"
}
},
"local-tools": {
"url": "stdio://local",
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
}
},
"debug": false
}
}
}
}
}
服务器选项
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
url |
string |
-- | MCP服务器端点URL |
transport |
"http" | "stdio" |
"http" |
运输类型 |
command |
string |
-- | stdio传输命令 |
args |
string[] |
-- | stdio命令的参数 |
env |
Record<string, string> |
-- | stdio子进程的环境变量 |
apiKey |
string |
-- | 静态承载令牌 |
auth |
object |
-- | OAuth 2.1配置(见下文) |
auth.clientId |
string |
-- | 预先注册的OAuth客户端ID |
auth.clientSecret |
string |
-- | OAuth客户端机密(机密客户端) |
auth.authorizationServerUrl |
string |
-- | 覆盖身份验证服务器URL |
auth.scopes |
string[] |
-- | 要请求的自定义范围 |
toolPrefix |
string |
服务器名称 | 工具的命名空间前缀 |
connectTimeoutMs |
number |
10000 |
连接超时(ms) |
requestTimeoutMs |
number |
30000 |
每次请求超时(ms) |
enabled |
boolean |
true |
启用/禁用此服务器 |
全局选项
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
toolDiscoveryInterval |
number |
300000 |
每N毫秒重新发现一次工具 |
maxConcurrentServers |
number |
20 |
最大同时连接数 |
debug |
boolean |
false |
启用调试日志记录 |
用法
配置后,MCP工具将显示为具有命名空间名称的常规代理工具:
tavily__search
github__create_issue
local-tools__read_file
斜杠命令
| 命令 | 描述 |
|---|---|
/mcp servers |
列出所有已配置的服务器及其状态 |
/mcp tools |
列出所有发现的工具 |
/mcp connect <server> |
连接到特定服务器 |
/mcp disconnect <server> |
断开与服务器的连接 |
/mcp auth <server> |
触发OAuth身份验证流程 |
建筑
┌──────────────────────────────────────────────┐
│ OpenClaw Gateway │
│ │
│ Skill (SKILL.md) ──▶ Plugin (Tool Ext) │
│ │ │
│ ┌───────────────┼──────────┐ │
│ ▼ ▼ ▼ │
│ MCPManager AuthManager ToolRegistry│
│ │ │ │
└──────────┼───────────────┼───────────────────┘
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ MCP Servers │ │ Auth Server │
└─────────────┘ └─────────────┘
发展
# Install dependencies
pnpm install
# Build
pnpm build
# Run tests
pnpm test
# Watch mode
pnpm test:watch
# Coverage
pnpm test:coverage
# Type check
pnpm lint
项目结构
src/
index.ts Plugin entry point
config-schema.ts TypeBox configuration schema
types.ts JSON-RPC 2.0 + MCP type definitions
jsonrpc.ts JSON-RPC encode/decode/validate
manager/
mcp-manager.ts Multi-server connection lifecycle
tool-registry.ts Dynamic tool registration + namespacing
transport/
streamable-http.ts Streamable HTTP transport (POST/GET/DELETE + SSE)
sse-parser.ts Server-Sent Events stream parser
stdio.ts stdio transport (subprocess)
legacy-sse.ts Backwards-compat HTTP+SSE
auth/
auth-manager.ts OAuth 2.1 orchestrator
discovery.ts Protected Resource + Auth Server metadata
pkce.ts PKCE S256 code challenge generation
client-registration.ts Dynamic Client Registration
token-store.ts Encrypted token persistence
callback-server.ts Local HTTP server for OAuth redirects
commands/
mcp-manage.ts /mcp subcommand handler
skills/
mcp/
SKILL.md Agent-facing skill definition
许可证
麻省理工学院
