Hermes Agent 接入外部服务:API Key 配置 + Notion 实战

Docker 部署 Hermes Agent 后接入 Notion 等外部服务的完整指南:env_file 加载 + docker_forward_env 透传 + 为什么 MCP OAuth 在 Docker 里行不通。
Hermes Agent 接入外部服务:API Key 配置 + Notion 实战
Docker 部署 Hermes Agent 后,让它调用 Notion、微信读书、DeepSeek 等服务,必须先把 API Key 传进工具容器。这篇文章把原理和实战一并讲清楚。

架构

Hermes Docker 部署有两层容器:
  • 网关容器:跑 Hermes 主程序,负责消息路由
  • 工具容器:动态创建,实际执行 terminal、API 调用
Key 传递链路:宿主机 .env → 网关容器(加载) → 工具容器(透传)
对应两处配置:docker-compose.yml 的 env_file 负责第 1 步,config.yaml 的 docker_forward_env 负责第 2 步。

1. env_file:宿主机 → 网关

docker-compose.yml 里加:
宿主机 ~/.hermes/.env 里写入 Key:

2. docker_forward_env:网关 → 工具容器

config.yaml 的 terminal 段落下:
每条一行,缩进与 backend 对齐。原来的空列表 [] 直接替换。
重启:

案例:接入 Notion

  1. 去 notion.so/my-integrations → New Integration(类型选 Internal)→ 复制 ntn_ token
  1. 在 Notion 里,每个要访问的页面右上角 ... → Connect to → 选你的 Integration
  1. Token 写入宿主机 ~/.hermes/.env,config.yaml 的 docker_forward_env 加上 NOTION_API_KEY
  1. 重启容器,验证:echo $NOTION_API_KEY | head -c 10

为什么不用 MCP

Notion 官方 MCP Server 走 OAuth 回调 localhost。Docker 容器的 127.0.0.1 是容器自己的,宿主机浏览器点完授权,回调到不了容器。Docker 里任何 OAuth + localhost 回调都不可行。Internal Integration Token + REST API 最稳定。

常见坑

  1. 改了 config 没重启:所有 config 变更必须重启网关
  1. 只加 .env 没加 forward:Key 到了网关但传不到工具容器
  1. YAML 缩进不对:docker_forward_env 用两个空格缩进
  1. Notion 页面没 Connect:Token 对了但页面没分享,API 返回 404
  1. 不要用 write_file 写 .env:用 shell 的 echo >> 追加
上一篇
【中文全文】美国软实力的终结
下一篇
Docker 部署 Hermes Agent 文件接收配置
Loading...