mcp-oauth代理
此存储库已存档,以支持Cloudflare MCP服务器门户,该门户实现了相同的目标。
一个轻量级的Rust代理,位于Claude的MCP连接器(需要OAuth 2.1)和使用其他身份验证方法的下游MCP服务器之间。它为Claude提供了一个兼容的OAuth 2.1接口,同时处理到下游服务的凭证转换。
这解决了什么
Claude的web界面通过“连接器”支持MCP(模型上下文协议)服务器,但只支持基于OAuth的身份验证。许多MCP服务器使用更简单的身份验证(API密钥、承载令牌)。这个代理弥合了这一差距。
支持的身份验证策略
1.通道
用户在OAuth授权流期间提供令牌/API密钥。代理直接将其作为OAuth访问令牌返回给Claude。在每个MCP请求上,代理将其转发给下游服务器,并可选择重新格式化标头。
无需存储。 最适合长期使用API密钥或个人访问令牌。
2.链接OAuth
代理通过下游服务(例如GitHub)启动真正的OAuth流。下游服务的令牌作为代理的令牌传递给Claude。Claude透明地处理刷新——代理只是将刷新请求转发到下游令牌端点。
无需存储 (无国籍)。权衡:如果轮换刷新令牌在刷新过程中丢失,用户必须重新授权。
快速开始
# Clone and build
cargo build --release
# Edit config
cp config.example.toml config.toml
# (configure your downstream MCPs — see docs/CONFIG.md)
# Generate a secret key
openssl rand -base64 32
# Put this value in config.toml as state_secret
# Run
./target/release/mcp-oauth-proxy --config config.toml
# In Claude's connector settings, add your MCP URL:
# https://your-domain.com/mcp/github
# Claude will discover OAuth endpoints automatically via .well-known安装演练:从零到工作代理
1.建造
cargo build --release或者使用Docker:
docker build -t mcp-oauth-proxy .2.配置
cp config.example.toml config.toml编辑 config.toml:
- 集
public_url到您的HTTPS域(例如。,https://mcp.example.com) - 生成一个秘密:
openssl rand -base64 32并设置state_secret - 添加一个或多个
[[downstream]]条目(参见 docs/CONFIG.md)
对于链式OAuth(例如GitHub):
- 在提供商处注册OAuth应用程序(例如。,https://github.com/settings/developers)
- 将回调URL设置为
https://your-domain.com/callback/mcp/ - 放
oauth_client_id和oauth_client_secret在配置中(或使用环境变量)
3.使用HTTPS进行部署
Claude的连接器需要HTTPS。选择以下选项之一:
选项A:在Caddy后面(自动TLS)
# Caddyfile
mcp.example.com {
reverse_proxy localhost:8080
}选项B:在nginx后面
server {
listen 443 ssl;
server_name mcp.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off; # Important for SSE
}
}选项C:Cloudflare隧道(最简单)
cloudflared tunnel --url http://localhost:8080选项D:Docker
docker run -d \
-p 8080:8080 \
-v $(pwd)/config.toml:/etc/mcp-oauth-proxy/config.toml:ro \
-e MCP_PROXY_STATE_SECRET="$(openssl rand -base64 32)" \
mcp-oauth-proxy4.联系克劳德
在Claude的连接器设置中,添加您的MCP URL:
https://mcp.example.com/mcp/github克劳德将自动:
- 通过以下方式发现OAuth端点
GET /.well-known/oauth-protected-resource/mcp/github - 将您重定向到授权(passthrough为表单,链式为OAuth提供者)
- 将授权码替换为令牌
- 开始通过代理发出MCP请求
5.健康检查
验证代理是否正在运行:
curl https://mcp.example.com/health
# Returns: OK日志记录
控制日志级别 RUST_LOG:
RUST_LOG=info ./target/release/mcp-oauth-proxy --config config.toml
RUST_LOG=debug ./target/release/mcp-oauth-proxy --config config.toml记录的事件:请求方法+路径、响应状态、下游URL(在代理上)、身份验证流事件(授权、代码发布、代码交换、刷新代理)。
从未记录:访问令牌,刷新令牌,API密钥,PKCE验证器,状态Blob。
环境变量
| 变量 | 覆盖 |
|---|---|
RUST_LOG | 日志级别(默认值: info) |
MCP_PROXY_STATE_SECRET | server.state_secret |
MCP_PROXY__CLIENT_SECRET | downstream[name].oauth_client_secret |
文档
- docs/ARCHITECTURE.md --身份验证流程、组件设计、SSE代理
- docs/API-SPEC.md文件 --所有具有请求/响应格式的HTTP端点
- docs/CONFIG.md --配置文件参考
- docs/DEVELOPMENT.md --开发指导和测试
