MCP客户端插件

OpenClaw插件,提供对MCP(Model Context Protocol)服务器的原生客户端支持,使代理能够直接使用MCP服务器的工具。

  • by protolabs42
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 protolabs42/openclaw-plugin-mcp

使用说明

openclaw插件mcp

本地MCP(模型上下文协议)客户端支持 开爪。连接到任何MCP服务器,并从您的OpenClaw代理本地使用其工具。

安装

在本地克隆并链接(尚未发布到npm):

git clone https://github.com/protolabs42/openclaw-plugin-mcp
cd openclaw-plugin-mcp
npm install
openclaw plugins install -l .

然后重新启动网关。插件将显示为 装载的 在 openclaw plugins list.

快速开始

  1. 安装插件(见上文)
  2. 从内置目录中添加MCP服务器:
openclaw mcp add context7 --from-catalog
  1. 重新启动网关
  2. 您的代理现在可以本地访问context7的工具(mcp_context7_resolve_library_id, mcp_context7_query_docs)

配置

在您的OpenClaw配置中进行配置(~/.openclaw/openclaw.json):

{
  plugins: {
    entries: {
      "openclaw-plugin-mcp": {
        enabled: true,
        config: {
          servers: {
            // Stdio transport (local servers)
            context7: {
              command: "npx",
              args: ["-y", "@upstash/context7-mcp@latest"],
              trust: "trusted"
            },
            // HTTP transport (remote servers)
            remote: {
              url: "https://mcp.example.com",
              headers: { "Authorization": "Bearer ..." },
              trust: "untrusted"
            },
            // SSE transport (legacy remote)
            legacy: {
              url: "https://old.example.com/sse",
              transport: "sse",
              trust: "sanitize"
            }
          },
          defaults: {
            trust: "untrusted",
            timeout: 30000,
            retries: 2,
            maxResultChars: 50000
          }
        }
      }
    }
  }
}

运输自动检测

  • 有 command ->stdio(生成本地进程)
  • 有 url ->HTTP(流式HTTP传输)
  • 集 transport: "sse" 明确用于旧式SSE服务器

信任级别

级别 行为
trusted 结果直接传递给代理
untrusted 结果前缀为警告(默认)
sanitize HTML/脚本被剥离,图像被删除,数据URI被清理

工具筛选

限制服务器中公开的工具:

{
  "web-scraper": {
    command: "npx",
    args: ["-y", "mcp-scraper"],
    trust: "sanitize",
    toolFilter: {
      deny: ["write_file", "delete_file"]  // Block dangerous tools
    }
  }
}

CLI命令

openclaw mcp list              # List servers + connection status
openclaw mcp catalog           # Browse built-in server catalog
openclaw mcp add <name>        # Add a server (--from-catalog, --command, --url)
openclaw mcp remove <name>     # Remove a server
openclaw mcp tools [server]    # List available MCP tools
openclaw mcp status            # Connection summary

内置目录

预配置的流行MCP服务器:

名称 类别 描述
context7 文档 任何库的最新文档
文件系统 文件系统 读/写本地文件
内存 内存 知识图持久化
github 开发者 github API访问
勇敢搜索 搜索 通过勇敢进行网络搜索
松弛 通信 松弛工作区访问
postgres 数据库 PostgreSQL访问
sqlite 数据库 sqlite访问
木偶师 浏览器 浏览器自动化
fetch web 以Markdown格式获取网页
顺序思考 推理 结构化问题解决
exa 搜索 人工智能网络搜索

运作原理

  1. 插件在同步工具工厂中注册为OpenClaw扩展
  2. 网关启动时,服务连接到所有配置的MCP服务器
  3. 通过MCP发现工具 tools/list
  4. 将每个MCP工具连接为OpenClaw代理工具(mcp_{server}_{tool})
  5. 当代理调用工具时,请求被代理到MCP服务器
  6. 结果在返回代理之前通过安全层进行处理

建筑

OpenClaw Gateway
    |
    +-- openclaw-plugin-mcp
         |
         +-- McpServerManager (lifecycle, connection pool)
         |    +-- McpClientWrapper (stdio)  --> context7
         |    +-- McpClientWrapper (http)   --> remote server
         |    +-- McpClientWrapper (sse)    --> legacy server
         |
         +-- Tool Bridge (MCP tools --> OpenClaw AgentTool)
         |    +-- Schema passthrough + normalization
         |    +-- Result conversion + security policy
         |
         +-- Gateway RPC (mcp.list, mcp.status, mcp.tools)
         +-- CLI Commands (openclaw mcp ...)

发展

git clone https://github.com/protolabs42/openclaw-plugin-mcp
cd openclaw-plugin-mcp
npm install
npm test

# Link for local development
openclaw plugins install -l .

许可证

麻省理工学院