第25篇-MCP集成
【Hermes Agent 从入门到精通】第 25 篇MCP 集成 — 连接外部工具生态本系列定位零基础入门从安装配置到高级架构全覆盖。无论你是开发者、运维工程师、还是技术爱好者本系列带你彻底掌握 Hermes Agent。本篇你将学到MCPModel Context Protocol的概念添加和管理 MCP 服务器内置 MCP 预设MCP 工具的自动注册实战连接 GitHub MCP 和数据库 MCP学完本篇你将能通过 MCP 协议无限扩展 Hermes 的工具能力。一、MCP 是什么1.1 概念MCPModel 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数据库 MCPSlack MCP文件系统 MCP更多 MCP...传统架构无 MCPHermes Agent内置工具集WebTerminalFileVision二、MCP 服务器类型2.1 两种类型类型通信方式适用场景stdio标准输入输出本地 MCP 服务器子进程HTTP (SSE)HTTP Server-Sent Events远程 MCP 服务器# stdio 类型本地子进程hermes mcpaddgithub--commandnpx -y modelcontextprotocol/server-github# HTTP 类型远程服务器hermes mcpaddremote-db--urlhttps://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 mcpaddgithub# 直接指定命令hermes mcpaddgithub--commandnpx -y modelcontextprotocol/server-github# 直接指定 URLhermes mcpaddjira--urlhttps://mcp.atlassian.com/sse3.2 查看hermes mcp list已配置的 MCP 服务器 Name Type Status Tools github stdio ✅ 运行中 12 tools filesystem stdio ✅ 运行中 5 tools remote-db http ❌ 连接失败 -3.3 测试连接hermes mcptestgithub✅ MCP 服务器 github 连接成功 工具列表 - search_issues 搜索 GitHub Issues - create_issue 创建 Issue - get_pr_details 获取 PR 详情 - merge_pr 合并 PR - ...3.4 配置工具选择# 交互式选择启用哪些 MCP 工具hermes mcp configure github3.5 删除hermes mcp remove github四、内置 MCP 预设Hermes 提供了一些常用 MCP 的预设配置预设名功能配置方式GitHub管理 Issues / PR / 仓库需要GITHUB_TOKENFilesystem文件系统访问指定允许的目录PostgreSQL数据库查询需要连接字符串SQLiteSQLite 数据库指定数据库文件Brave Search网页搜索需要 API KeyMemory持久化知识图谱本地运行# 用预设快速添加hermes mcpaddgithub# 自动使用预设配置五、配置示例5.1 GitHub MCP# 设置 GitHub TokenechoGITHUB_TOKENghp_xxxxxxxxxxxx~/.hermes/.env# 添加 GitHub MCPhermes mcpaddgithub--commandnpx -y modelcontextprotocol/server-github使用你帮我看看 nousresearch/hermes-agent 仓库最近的 5 个 Issue Hermes mcp: github.search_issues(repoNousResearch/hermes-agent, stateopen, limit5) 最近 5 个开放 Issue #42 - Feature: Support for custom model routing #41 - Bug: Gateway crashes on Discord reconnect ...5.2 PostgreSQL MCPhermes mcpaddpostgres\--commandnpx -y modelcontextprotocol/server-postgres\--envDATABASE_URLpostgresql://user:passlocalhost:5432/mydb使用你查询用户表中有多少条记录 Hermes mcp: postgres.query(SELECT COUNT(*) FROM users) 用户表共有 1,234 条记录。5.3 Filesystem MCPhermes mcpaddfilesystem\--commandnpx -y modelcontextprotocol/server-filesystem\--envALLOWED_DIRECTORIES/home/user/documents,/home/user/projects六、MCP 工具的自动注册6.1 工具发现当 MCP 服务器启动后Hermes 自动连接 MCP 服务器获取其提供的工具列表把工具注册到 Hermes 的工具系统中Agent 可以像使用内置工具一样使用 MCP 工具6.2 工具命名MCP 工具的名称格式mcp:服务器名.工具名mcp:github.search_issues mcp:github.create_issue mcp:postgres.query mcp:filesystem.read_file6.3 会话中重新加载如果修改了 MCP 配置/reload-mcpMCP 工具从发现到使用的完整流程外部工具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 mcpaddsecure-service\--urlhttps://mcp.internal.com/sse\--cert/path/to/client.crt\--key/path/to/client.key\--ca/path/to/ca.crt7.2 Hermes 作为 MCP 服务器Hermes 也可以作为 MCP 服务器供其他 Agent 使用hermes mcp serve其他支持 MCP 的客户端如 Claude Desktop可以连接 Hermes 作为工具提供方。本篇小结知识点核心内容MCPModel Context Protocol连接外部工具的统一协议stdio 类型本地子进程 MCPHTTP 类型远程 MCP 服务器hermes mcp add添加 MCP 服务器hermes mcp list查看已配置hermes mcp test测试连接内置预设GitHub / PostgreSQL / Filesystem 等自动注册MCP 工具自动发现并注册hermes mcp serveHermes 作为 MCP 服务器下篇预告第 26 篇人格与上下文定制怎么让 Hermes 有自己的性格下一篇学习 SOUL.md、人格设置和项目上下文文件。如果本篇内容对你有帮助欢迎点赞收藏有任何疑问欢迎在评论区交流。