Skip to main content
Glama
codezerowork

mcp-oauth2-token-provider

by codezerowork

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"
      }
    }
  }
}

环境变量

变量

必填

描述

REMOTE_MCP_URL

要代理到的远程 MCP 端点 URL

OAUTH2_TOKEN_URL

OAuth2 令牌端点(client_credentials 授权)

OAUTH2_CLIENT_ID

OAuth2 客户端 ID

OAUTH2_CLIENT_SECRET

OAuth2 客户端密钥

OAUTH2_BASIC_USERNAME

Basic 认证用户名(用于双凭证 SSO)

OAUTH2_BASIC_PASSWORD

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
  1. 启动时,验证远程 MCP 端点可达(发送 MCP initialize

  2. 如果远程不可达,则报错退出(IDE 显示 "Failed" 状态)

  3. 如果健康,通过 stdio 连接 IDE 并从远程发现工具

  4. 所有工具调用均透明代理并携带 Bearer 令牌

令牌缓存

令牌在两层中缓存:

  • 内存中 — 最快,进程重启后丢失

  • 磁盘上~/.oauth2-token-provider/token.json,重启后保留

在以下情况刷新令牌:

  • 距过期时间不足 60 秒

  • 从远程收到 401 响应

双凭证 SSO(可选)

某些 SSO 提供商要求同时具备:

  • 请求体中的 client_id + client_secret

  • 带有服务账户凭证的 Basic Auth 头

设置 OAUTH2_BASIC_USERNAMEOAUTH2_BASIC_PASSWORD 以启用此模式。

许可证

MIT

A
license - permissive license
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • MCP server for Argo RPG Platform — connects AI assistants to campaign data via OAuth2

  • MCP server for verifying EUDI/Talao wallet data via OIDC4VP (pull) for AI agents.

  • MCP Hub: AI service discovery, per-user OAuth, and multi-service workflow orchestration

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/codezerowork/mcp-oauth2-token-provider'

If you have feedback or need assistance with the MCP directory API, please join our Discord server