feat: 支持 Bearer Token 认证配置#94
Merged
Merged
Conversation
- 新增 MCP_BEARER_TOKEN 环境变量,支持对 HTTP/SSE/StreamableHTTP 端点配置 Bearer Token 认证 - 认证请求头格式: Authorization: Bearer <token>(RFC 6750,前缀大小写不敏感) - 在 ServerConfig 中添加 bearerToken 字段,支持环境变量和命令行参数 --bearer-token - 配置读取时 trim 去除空白字符,stripQuotes 去除 Docker 环境变量中可能的引号包裹 - 在 server.ts 中添加 bearerAuthMiddleware 中间件,覆盖 /mcp、/sse、/messages 端点 - 更新 .env.example、README.md、docker-compose.yaml 文档
This was referenced May 12, 2026
This was referenced May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: 支持 Bearer Token 认证配置
功能概述
新增
MCP_BEARER_TOKEN环境变量,支持对 HTTP/SSE/StreamableHTTP 端点配置 Bearer Token 认证,适用于公网部署场景防止未授权访问。变更详情
MCP_BEARER_TOKEN,未设置时不启用认证(向后兼容)--bearer-tokenAuthorization: Bearer <token>(RFC 6750,前缀大小写不敏感)/mcp、/sse、/messages修改文件
.env.example— 新增 MCP_BEARER_TOKEN 说明src/utils/config.ts— ServerConfig 新增 bearerToken 字段、stripQuotes 方法src/server.ts— 新增 bearerAuthMiddleware 中间件README.md— 环境变量表格和 Bearer 认证配置示例docker-compose.yaml— 新增 MCP_BEARER_TOKEN 环境变量传递