【Hermes Agent 从入门到精通】第 25 篇:MCP 集成 — 连接外部工具生态

本系列定位:零基础入门,从安装配置到高级架构全覆盖。无论你是开发者、运维工程师、还是技术爱好者,本系列带你彻底掌握 Hermes Agent。


本篇你将学到

  • MCP(Model Context Protocol)的概念
  • 添加和管理 MCP 服务器
  • 内置 MCP 预设
  • MCP 工具的自动注册
  • 实战:连接 GitHub MCP 和数据库 MCP

学完本篇,你将能通过 MCP 协议无限扩展 Hermes 的工具能力。


一、MCP 是什么

1.1 概念

MCP(Model Context Protocol)是 Anthropic 提出的开放标准——一种让 AI Agent 连接外部工具和数据源的统一协议。

没有 MCP:
  Hermes 内置工具:web / terminal / file / vision / ...
  → 工具是固定的,不能随意扩展

有 MCP:
  Hermes 内置工具 + MCP 服务器提供的工具
  → GitHub MCP → 管理 Issues/PR
  → 数据库 MCP → 直接查询 SQL
  → Slack MCP → 发送消息
  → 文件系统 MCP → 访问特定目录
  → 任何 MCP 服务器...

1.2 MCP 的价值

  • 无限扩展:社区有数百个 MCP 服务器可用
  • 统一协议:一个标准连接所有工具
  • 即插即用:配置一个 MCP 服务器,Hermes 自动发现并注册其工具

下面是 MCP 架构与传统内置工具架构的对比:

升级

MCP 架构

Hermes Agent

内置工具集

MCP 协议层

GitHub MCP

数据库 MCP

Slack MCP

文件系统 MCP

更多 MCP...

传统架构(无 MCP)

Hermes Agent

内置工具集

Web

Terminal

File

Vision

二、MCP 服务器类型

2.1 两种类型

类型通信方式适用场景
stdio标准输入输出本地 MCP 服务器(子进程)
HTTP (SSE)HTTP + Server-Sent Events远程 MCP 服务器
# stdio 类型:本地子进程
hermes mcp add github --command "npx -y @modelcontextprotocol/server-github"

# HTTP 类型:远程服务器
hermes mcp add remote-db --url "https://mcp.example.com/sse"

选择 MCP 服务器类型的决策流程如下:

本地机器

远程服务器

选择 MCP 服务器类型

MCP 服务器
运行在哪里?

stdio 类型
标准输入输出
子进程通信

HTTP (SSE) 类型
HTTP + Server-Sent Events
网络通信

hermes mcp add github
--command 'npx -y ...'

hermes mcp add remote-db
--url 'https://.../sse'

✅ MCP 服务器就绪

三、管理 MCP 服务器

3.1 添加

# 交互式添加
hermes mcp add github

# 直接指定命令
hermes mcp add github --command "npx -y @modelcontextprotocol/server-github"

# 直接指定 URL
hermes mcp add jira --url "https://mcp.atlassian.com/sse"

3.2 查看

hermes mcp list
已配置的 MCP 服务器:
  Name         Type    Status    Tools
  github       stdio   ✅ 运行中  12 tools
  filesystem   stdio   ✅ 运行中  5 tools
  remote-db    http    ❌ 连接失败  -

3.3 测试连接

hermes mcp test github
✅ MCP 服务器 'github' 连接成功
   工具列表:
   - search_issues      搜索 GitHub Issues
   - create_issue       创建 Issue
   - get_pr_details     获取 PR 详情
   - merge_pr           合并 PR
   - ...

3.4 配置工具选择

# 交互式选择启用哪些 MCP 工具
hermes mcp configure github

3.5 删除

hermes mcp remove github

四、内置 MCP 预设

Hermes 提供了一些常用 MCP 的预设配置:

预设名功能配置方式
GitHub管理 Issues / PR / 仓库需要 GITHUB_TOKEN
Filesystem文件系统访问指定允许的目录
PostgreSQL数据库查询需要连接字符串
SQLiteSQLite 数据库指定数据库文件
Brave Search网页搜索需要 API Key
Memory持久化知识图谱本地运行
# 用预设快速添加
hermes mcp add github        # 自动使用预设配置

五、配置示例

5.1 GitHub MCP

# 设置 GitHub Token
echo 'GITHUB_TOKEN=ghp_xxxxxxxxxxxx' >> ~/.hermes/.env

# 添加 GitHub MCP
hermes mcp add github --command "npx -y @modelcontextprotocol/server-github"

使用:

你:"帮我看看 nousresearch/hermes-agent 仓库最近的 5 个 Issue"

Hermes:
  🔧 mcp: github.search_issues(repo="NousResearch/hermes-agent", state="open", limit=5)

  📋 最近 5 个开放 Issue:
  #42 - Feature: Support for custom model routing
  #41 - Bug: Gateway crashes on Discord reconnect
  ...

5.2 PostgreSQL MCP

hermes mcp add postgres \
  --command "npx -y @modelcontextprotocol/server-postgres" \
  --env "DATABASE_URL=postgresql://user:pass@localhost:5432/mydb"

使用:

你:"查询用户表中有多少条记录"

Hermes:
  🔧 mcp: postgres.query("SELECT COUNT(*) FROM users")

  📊 用户表共有 1,234 条记录。

5.3 Filesystem MCP

hermes mcp add filesystem \
  --command "npx -y @modelcontextprotocol/server-filesystem" \
  --env "ALLOWED_DIRECTORIES=/home/user/documents,/home/user/projects"

六、MCP 工具的自动注册

6.1 工具发现

当 MCP 服务器启动后,Hermes 自动:

  1. 连接 MCP 服务器
  2. 获取其提供的工具列表
  3. 把工具注册到 Hermes 的工具系统中
  4. Agent 可以像使用内置工具一样使用 MCP 工具

6.2 工具命名

MCP 工具的名称格式:mcp:服务器名.工具名

mcp:github.search_issues
mcp:github.create_issue
mcp:postgres.query
mcp:filesystem.read_file

6.3 会话中重新加载

如果修改了 MCP 配置:

/reload-mcp

MCP 工具从发现到使用的完整流程:

外部工具 MCP 服务器 MCP 协议层 Hermes Agent 外部工具 MCP 服务器 MCP 协议层 Hermes Agent 工具命名:mcp:服务器名.工具名 配置变更时执行 /reload-mcp 启动 / 连接 MCP 服务器 建立连接(stdio / HTTP) 返回工具列表 注册工具到工具系统 用户发出指令 调用 mcp:github.search_issues 转发工具调用请求 执行实际操作 返回结果 返回执行结果 返回结果给 Agent 整合结果回复用户

七、MCP 高级配置

7.1 mTLS / 客户端证书

对于需要证书认证的 MCP 服务器:

hermes mcp add secure-service \
  --url "https://mcp.internal.com/sse" \
  --cert "/path/to/client.crt" \
  --key "/path/to/client.key" \
  --ca "/path/to/ca.crt"

7.2 Hermes 作为 MCP 服务器

Hermes 也可以作为 MCP 服务器供其他 Agent 使用:

hermes mcp serve

其他支持 MCP 的客户端(如 Claude Desktop)可以连接 Hermes 作为工具提供方。


本篇小结

知识点核心内容
MCPModel Context Protocol,连接外部工具的统一协议
stdio 类型本地子进程 MCP
HTTP 类型远程 MCP 服务器
hermes mcp add添加 MCP 服务器
hermes mcp list查看已配置
hermes mcp test测试连接
内置预设GitHub / PostgreSQL / Filesystem 等
自动注册MCP 工具自动发现并注册
hermes mcp serveHermes 作为 MCP 服务器

下篇预告

第 26 篇:人格与上下文定制

怎么让 Hermes 有自己的性格?下一篇学习 SOUL.md、人格设置和项目上下文文件。


如果本篇内容对你有帮助,欢迎点赞收藏!有任何疑问,欢迎在评论区交流。

Logo

小龙虾开发者社区是 CSDN 旗下专注 OpenClaw 生态的官方阵地,聚焦技能开发、插件实践与部署教程,为开发者提供可直接落地的方案、工具与交流平台,助力高效构建与落地 AI 应用

更多推荐