MCP(Model Context Protocol)是 2026 年最火的 AI 工具协议。本文教你用 OpenClaw + Hermes 接入 MCP Server,实现 AI 智能体自动调用工具。

什么是 MCP?

传统方式: 每个工具都要单独写 API 调用代码

def search_web(query): ...
def read_file(path): ...
# 10个工具 = 10套代码

MCP 方式: 统一协议,工具自描述

tools = mcp_server.list_tools()
# AI 自动知道每个工具的参数和用法
response = ai.chat(messages, tools=tools)
特性 传统方式 MCP 方式
工具接入 手动编码 自描述
新工具接入 改代码 加配置

OpenClaw + Hermes 架构

用户 → OpenClaw Gateway → Hermes(AI 智能体)→ MCP Server → 工具执行

配置实战

stdio 模式(本地工具):

{
  "mcpServers": {
    "filesystem": {
      "command": "node",
      "args": ["mcp-filesystem/dist/index.js"]
    }
  }
}

HTTP 模式(远程服务):

{
  "mcpServers": {
    "atmapi": {
      "url": "http://localhost:9100/mcp",
      "headers": {"Authorization": "Bearer KEY"}
    }
  }
}

Hermes 智能体配置:

{
  "agents": {
    "assistant": {
      "model": "deepseek-chat",
      "tools": ["filesystem", "atmapi", "browser"]
    }
  }
}

使用示例

  • 文件操作:“读取 config.json” → AI 自动调用 read_file
  • API 调用:“翻译 Hello World” → AI 自动调用 translate
  • 浏览器:“打开百度截图” → AI 自动调用 navigate + screenshot

调试技巧

  • 查看工具:openclaw mcp list
  • 测试调用:openclaw mcp test filesystem read_file
  • 查看日志:openclaw logs --tail 50

atmAPI 提供官方 MCP Server:

{"url": "http://api.aitomoney.online/mcp"}

更多推荐