mcp-oauth2-token-provider
mcp-oauth2-token-provider
一个通用的 MCP(Model Context Protocol)服务器,充当 AI IDE 与远程 MCP 端点之间的认证代理。内部处理 OAuth2 client_credentials 令牌生成,并透明地将 Bearer 令牌注入所有代理请求。
功能特性
透明 OAuth2 代理 — 获取、缓存并自动刷新令牌
动态工具发现 — 无硬编码工具模式;从远程 MCP 端点发现工具
401 自动重试 — 如果令牌在会话中途过期,刷新并重试一次
启动健康检查 — 在连接前验证远程 MCP 可达;快速失败并给出清晰错误信息
令牌持久化 — 将令牌缓存到磁盘
~/.oauth2-token-provider/token.json,以便在进程重启后继续使用代码零配置 — 所有设置均通过环境变量完成
支持 SSE 和 JSON 响应 — 同时处理远程的 Streamable HTTP 和纯 JSON-RPC
Related MCP server: MCP OAuth Proxy
安装
npx mcp-oauth2-token-provider或全局安装:
npm install -g mcp-oauth2-token-provider在 Kiro / VS Code MCP 中使用
添加到您的 .kiro/settings/mcp.json(或等效文件):
{
"mcpServers": {
"my-remote-server": {
"command": "npx",
"args": ["mcp-oauth2-token-provider"],
"env": {
"REMOTE_MCP_URL": "https://your-server.com/mcp",
"OAUTH2_TOKEN_URL": "https://your-sso.com/token.oauth2",
"OAUTH2_CLIENT_ID": "your-client-id",
"OAUTH2_CLIENT_SECRET": "your-client-secret"
}
}
}
}环境变量
变量 | 必填 | 描述 |
| 是 | 要代理到的远程 MCP 端点 URL |
| 是 | OAuth2 令牌端点(client_credentials 授权) |
| 是 | OAuth2 客户端 ID |
| 是 | OAuth2 客户端密钥 |
| 否 | Basic 认证用户名(用于双凭证 SSO) |
| 否 | Basic 认证密码(用于双凭证 SSO) |
工作原理
AI IDE ←stdio→ [mcp-oauth2-token-provider] ←HTTP+Bearer→ [Remote MCP Server]
│
├─ Acquires OAuth2 token (client_credentials)
├─ Caches in memory + ~/.oauth2-token-provider/token.json
├─ Injects Bearer header on every request
├─ Auto-refreshes on expiry (60s safety margin)
└─ Retries once on 401 with fresh token启动时,验证远程 MCP 端点可达(发送 MCP
initialize)如果远程不可达,则报错退出(IDE 显示 "Failed" 状态)
如果健康,通过 stdio 连接 IDE 并从远程发现工具
所有工具调用均透明代理并携带 Bearer 令牌
令牌缓存
令牌在两层中缓存:
内存中 — 最快,进程重启后丢失
磁盘上 —
~/.oauth2-token-provider/token.json,重启后保留
在以下情况刷新令牌:
距过期时间不足 60 秒
从远程收到 401 响应
双凭证 SSO(可选)
某些 SSO 提供商要求同时具备:
请求体中的
client_id+client_secret带有服务账户凭证的 Basic Auth 头
设置 OAUTH2_BASIC_USERNAME 和 OAUTH2_BASIC_PASSWORD 以启用此模式。
许可证
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Governed MCP gateway: one endpoint for your tools, with credential custody and audit log.
Connect MCP clients to 2,000+ AI models without managing provider API keys.
MCP server that lets AI assistants use all OneSchema features exposed via the public API.
Security & DLP proxy for MCP: tool-poisoning scans, PII redaction on tool args/results. Beta.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProxies MCP requests from Cursor IDE to a custom HTTP server, enabling custom tool integrations.8 npm1ISC
- AlicenseNot gradedqualityDmaintenanceActs as a secure OAuth 2.0/2.1 proxy gateway for MCP servers, enabling integration with Claude and ChatGPT platforms.20 npmMIT
- AlicenseNot gradedqualityDmaintenanceAuthenticating reverse proxy for MCP servers providing credential isolation, OAuth2 token management, and composite tool aggregation.BSD Zero Clause
- AlicenseNot gradedqualityCmaintenanceProvides a Streamable HTTP MCP proxy for VS Code Copilot and Claude Code, using JWT client assertion to securely access NetSuite APIs.MIT