mcp-server-auth-template
A reusable template for building MCP servers that act as OAuth 2.1 resource servers, verifying bearer tokens against Microsoft Entra ID or any standards-compliant OIDC authorization server.
README
mcp-server-auth-template
A reusable template for an MCP server that acts as an OAuth 2.1 resource server - never an authorization server - against either Microsoft Entra ID or any standards-compliant OIDC authorization server (Auth0, Keycloak, WorkOS AuthKit, ...). Targets the MCP 2026-07-28 specification.
The MCP 2026-07-28 authorization spec models every remote MCP server this way: it verifies bearer
tokens minted elsewhere, it never mints them itself. Entra ID also can't act as a full MCP
authorization server for arbitrary clients (no Dynamic Client Registration, no Client ID Metadata
Documents), so a real integration needs an adapter either way. This template is that adapter,
built once, correctly, so a new MCP server doesn't have to re-derive JWKS caching, issuer/audience
checks, and Entra's split scp/roles claim shape from scratch. See
docs/adr/0002-oauth21-resource-server.md for the full reasoning, and the companion repository,
mcp-client-auth-template, for the
client-side half of this pattern.
Auth quick start
-
Copy
.env.exampleto.envand fill in one of the two provider blocks (Entra ID or a generic OIDC authorization server). -
Run the server:
uv run uvicorn mcp_server_auth_template.entrypoints.mcp_server:create_app --factory --reload -
Protected Resource Metadata is served automatically at
/.well-known/oauth-protected-resource- point an MCP client athttp://localhost:8000/mcpand it will discover the configured authorization server from there:{ "resource": "https://mcp.example.invalid/", "authorization_servers": ["https://as.example.invalid"], "bearer_methods_supported": ["header"] }A request with no (or an invalid) bearer token gets a
401with aWWW-Authenticateheader pointing back at that same metadata document, exactly as the spec requires - the server never issues its own login page:HTTP/1.1 401 Unauthorized www-authenticate: Bearer error="invalid_token", error_description="Authentication required", resource_metadata="https://mcp.example.invalid/.well-known/oauth-protected-resource" -
Two example tools are registered:
whoamireturns the identity carried by the caller's token (client ID, subject, scopes), andhealthis a liveness check for an already-authenticated caller.
Swap MCP_SERVER_AUTH_PROVIDER between entra and generic to switch adapters -
no other code changes. See src/mcp_server_auth_template/adapters/ for the two
TokenVerifier implementations and tests/unit/test_*_token_verifier.py for how
each is tested offline with a locally-signed JWT (no network, no real IdP needed).
Authentication flow
docs/ARCHITECTURE.md has a sequence diagram of the full bearer-token round trip - the 401
challenge, Protected Resource Metadata discovery, token acquisition on the authorization server
(out of scope for this repo), and signature/issuer/audience verification on every subsequent call.
See Diagrams.
Development
uv lock --check
uv sync --frozen --all-groups --extra observability
uv run pytest
uv run python scripts/quality_gate.py
List or select gate checks with --list and --check NAME. See AGENTS.md for build, lint,
format, typecheck, test, security, architecture, MCP, and completion requirements, and
docs/DEVELOPMENT.md for the container build and local setup.
Codex loads the checked-in .codex/config.toml, .codex/hooks.json, and .agents/skills/ only
within the appropriate project/trust context. Review lifecycle hooks with /hooks before use.
License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。