跳到主要内容

上游认证

AISIX 代表调用方连接上游 MCP Server。调用方使用调用方 API Key 认证到 AISIX;AISIX 再使用 MCP Server 资源上配置的凭证认证到上游。

auth_type用法需要的字段
none上游 MCP Server 不要求认证。
bearer发送 Authorization: Bearer <secret>secret
api_key发送 x-api-key: <secret>secret
oauth2通过客户端凭证流程获取 access token 后访问上游。client_idtoken_urlsecret,可选 scopes

secret 字段是只写字段:AISIX 会保存该凭证,但不会在读取响应中返回明文。轮换凭证时,请使用新的 secret 更新 MCP Server 资源。

Bearer Token

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/mcp_servers" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
-d '{
"display_name": "github",
"url": "https://mcp.example.com/mcp",
"auth_type": "bearer",
"secret": "YOUR_UPSTREAM_TOKEN"
}'

AISIX 会在转发到上游 MCP Server 时发送 Authorization: Bearer YOUR_UPSTREAM_TOKEN

API Key

使用 api_key 时,AISIX 会把 secret 放入 x-api-key 请求头。

{
"display_name": "internal-tools",
"url": "https://tools.example.com/mcp",
"auth_type": "api_key",
"secret": "YOUR_UPSTREAM_API_KEY"
}

OAuth2 客户端凭证

使用 oauth2 时,AISIX 会从 token_url 获取 access token,并用该 token 调用上游 MCP Server。

{
"display_name": "catalog",
"url": "https://catalog.example.com/mcp",
"auth_type": "oauth2",
"client_id": "aisix-mcp",
"token_url": "https://auth.example.com/oauth/token",
"secret": "YOUR_CLIENT_SECRET",
"scopes": ["catalog.read"]
}

请确保网关运行环境可以访问 token endpoint 和上游 MCP endpoint。AISIX 会签发并缓存自己的 access token,调用方 API Key 不会参与上游 OAuth2 流程,也不会被转发给上游。

轮换上游凭证

轮换 MCP 上游凭证时,请更新对应 MCP Server 资源。更新请求会替换资源,因此需要包含要保留的字段,例如 display_nameurlauth_type 和访问配置。更新完成后,让 MCP 客户端重新列出工具并调用一个允许的工具,确认新凭证可用。