
MCP Server Auth Template
io.github.brunoviccoPublished by GitHub account brunoviccov0.7.0Updated Oct 24, 2026
OAuth 2.1/OIDC resource-server reference for secure MCP authorization
Overview
A reference OAuth 2.1/OIDC resource server that exposes MCP tools behind strict token verification and per-principal authorization.
- What you can do
- This is a production-oriented reference implementation of an MCP resource server that validates OAuth 2.1/OIDC access tokens before dispatching tools. It publishes RFC 9728 protected-resource metadata, binds tokens to an exact audience via RFC 8707, and fails closed on issuer, signature, expiry, algorithm and caller-type checks. It ships example tools such as whoami and health, filters tools/list per principal, and returns 403 insufficient_scope for progressive scope step-up. It supports Microsoft Entra ID and generic OIDC adapters, and emits metadata-only OpenTelemetry traces.
- When to use it
- Use it when the hard part is not exposing an MCP tool but exposing it without weakening identity, authorization, transport and observability boundaries. It suits teams that need a working reference for Entra ID or generic OIDC resource-server behavior, or that want to verify token validation, scope challenges and stateless MCP behavior end to end.
- Requirements
- Runs as a local process or container. Source use needs Python 3.13 or 3.14 and uv; the published OCI image runs with Docker over streamable-http. Required environment variables include MCP_SERVER_AUTH_PROVIDER and MCP_SERVER_RESOURCE_SERVER_URL; the entra profile also needs MCP_SERVER_ENTRA_APPLICATION_ID_URI, MCP_SERVER_ENTRA_AUDIENCE and MCP_SERVER_ENTRA_TENANT_ID, and the generic profile needs MCP_SERVER_GENERIC_AUDIENCE and MCP_SERVER_GENERIC_ISSUER_URL. An OIDC authorization server and…
Installation
In SourceWeft
- Open MCP Server Auth Template in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
mcp-server-auth-template
[quality] [compatibility] [release] [python] [license]
A production-oriented OAuth 2.1 resource-server reference for remote MCP: Microsoft Entra ID and generic OIDC, exact token/resource validation, fail-closed authorization, progressive scope challenges, stateless MCP
2026-07-28, and metadata-only OpenTelemetry evidence.
Use this repository when the hard part is not "how do I expose an MCP tool?" but how do I expose
it without weakening identity, authorization, transport, and observability boundaries. The server
pairs with mcp-client-auth-template for
an executable end-to-end reference using synthetic identities and no production credentials.
What this repository proves
The paired executable path validates real resource-server behavior rather than configuration claims:
- ✅ RFC 9728 Protected Resource Metadata is published by the resource server
- ✅ RFC 8707 resource binding becomes an exact JWT audience boundary
- ✅ issuer, signature, expiry, algorithm/key compatibility and caller type fail closed
- ✅ delegated scopes and Entra application roles remain distinct authorization concepts
- ✅
403 insufficient_scopeis returned before dispatch for progressive authorization - ✅ wrong-audience tokens are rejected with
401, with an explicit token-resource policy that does not depend on MCP SDK defaults - ✅
tools/listis filtered per principal and carries only boundedprivatecache hints - ✅ protected tools stay hidden from anonymous catalog discovery
- ✅ MCP
2026-07-28stays stateless and does not mintMcp-Session-Id - ✅ generic OIDC and Microsoft Entra ID share one application boundary without provider leakage
- ✅ W3C trace context reaches the server while OAuth/MCP sensitive values stay out of telemetry
- ✅ release artifacts, container evidence, SBOMs and provenance are validated by executable gates
For a requirement-by-requirement view of the paired OAuth/MCP behavior, including explicit evidence gaps and discussion topics for the MCP Authorization Interest Group / Tool Scopes Working Group, see the Authorization Implementer Report.
Architecture
The authorization server owns login, consent, client registration and token issuance. This repository owns the protected resource: transport admission, metadata publication, access-token verification, request-scoped principal construction, tool authorization and dispatch.
For layer boundaries and the detailed authorization sequence, see Architecture.
5-minute verification
The companion client owns the executable cross-repository reference flow. With both repositories cloned as siblings, verify this server directly from source:
The flow starts the real server from this checkout plus a deterministic local OIDC provider and
proves CIMD-first Authorization Code + PKCE, authenticated whoami, bounded scope step-up,
wrong-audience rejection and stateless MCP behavior.
For the observable published-image proof:
The observable flow verifies one distributed trace across client and server, positive Collector receipt, Tempo retrieval, Grafana provisioning and telemetry privacy assertions.
See Verification guide for the exact evidence boundary.
Visual proof
The terminal proof below is captured from the source-level paired reference flow:
The trace screenshots are captured from a successful observable run and focus on
mcp-server-auth-template spans:
[Server distributed trace detail]
Authentication profiles
Set MCP_SERVER_AUTH_PROVIDER=entra or generic to switch adapters. The example whoami tool
returns the verified caller identity; health requires the additional mcp:tools:health scope and
demonstrates a pre-dispatch 403 insufficient_scope challenge.
Quick start
Prerequisites: Python 3.13 or 3.14 and
uv.
Configure either the Entra or generic-OIDC block in .env, then point an MCP client at
http://localhost:8000/mcp.
For production-style execution:
See Production operations before exposing the service outside loopback.
Official MCP Registry
The server is published in the Official MCP Registry as:
io.github.brunovicco/[email protected]
server.json describes the public GHCR image as an OCI package using the real
streamable-http transport; it does not claim a hosted remotes endpoint. Publication is gated by
the secure release pipeline and a dedicated Registry workflow that validates the immutable image,
ownership metadata, and persisted Registry responses before publication.
See Official MCP Registry and the Authorization Implementer Report.
Security properties
The implementation is deliberately fail closed:
- exact issuer and audience validation, bounded clock checks, algorithm/key compatibility and cached JWKS refresh;
- an explicit
validate_token_resource=Falsepolicy: provider audiences (Entra API client ID,api://identifiers) are enforced by the token verifier, never by SDK URL string equality (ADR-0027); - principal-dependent discovery results are never shareable across authorization contexts (ADR-0028);
- hardened discovery/JWKS egress against unsafe schemes, redirects, compression, oversized bodies, private/reserved destinations, mixed DNS answers and DNS rebinding;
- Host, Origin, header, envelope, body-size and concurrency admission before authentication and tool dispatch;
- delegated and application identities remain distinct; extension negotiation never grants authorization by itself;
- bearer tokens and decoded claims remain request-local and are never logged or persisted;
- tracing excludes credentials, arbitrary headers and URLs, MCP arguments/results, bodies, baggage and exception text.
This is a transparent reference implementation, not a security certification. Read
Privacy and data handling and the architecture decisions under
docs/adr/ before adapting the boundary.
MCP 2026-07-28
Baseline: MCP specification 2026-07-28 and MCP Python SDK >=2.2,<3.
The paired templates exercise the modern stateless profile as executable behavior:
server/discoverand per-request_metacarry protocol version, client identity and capabilities without the legacyinitialize/initializedhandshake;- modern requests use
MCP-Protocol-Version,Mcp-MethodandMcp-Name; - responses do not mint
Mcp-Session-Id; - Protected Resource Metadata drives authorization-server discovery;
- RFC 8707
resourcebinds the access token audience exactly; server/discoverandtools/listcarry SEP-2549 cache hints (ttlMs=30000,cacheScope=private);- runtime
403 insufficient_scopepreserves prior grants and permits only one bounded replay of the undispatched operation; - machine-to-machine access is opt-in through
io.modelcontextprotocol/oauth-client-credentials.
See Compatibility and the companion client's cross-repository E2E evidence.
Observability
a2a-otel-kit continues W3C trace context at the MCP ASGI boundary. Export remains network-silent
unless A2A_OTEL_ENABLED=true and a complete OTLP traces endpoint are configured. Spans are
metadata-only and sit inside hardened HTTP admission but outside authentication and tool dispatch.
See LLM and application observability.
Engineering evidence
- deterministic quality gate covering lint, format, strict Mypy, architecture, tests/coverage, Bandit, dependency audit, supply-chain controls, governance and vendored contract validation;
- SHA-pinned GitHub Actions with read-only permissions by default and isolated release authorities;
- CycloneDX source/runtime inventories, complete vulnerability evidence and fail-closed exception policy;
- allowlisted byte-reproducible Python release artifacts with SHA-256 manifests and GitHub build provenance;
- policy-approved GHCR publication with immutable digest, provenance and SBOM attestations;
- Python 3.13/3.14 against MCP SDK 2.2.0 and latest compatible 2.x, with MCP SDK deprecation warnings promoted to test failures so MCP 3 breakage surfaces early;
- offline JWT fixtures using local keys and synthetic identities;
- ADRs documenting security, protocol, operations, compatibility, observability and supply-chain decisions.
Demo vs production
The reference settings prove boundaries; they are not production defaults.
Repository structure
Local editor and coding-agent state is intentionally excluded from the public repository.
Documentation
Testing and quality
The quality gate is the definition of done. It covers lint, format, architecture, strict typing, tests/coverage, Bandit, dependency audit, supply-chain controls, governance and vendored contract validation.
Scope and production adoption
This repository is a reference template, not a hosted identity service. A concrete deployment must
still provide TLS termination, immutable image publishing, secret delivery, provider-specific
registration, network policy, capacity planning, monitoring ownership and live IdP validation.
Checked-in .invalid and all-zero values are placeholders and fail production preflight.
License
Source: README.md at commit 8b1d6d9
Tools
0Version history
2- v0.7.0LatestSep 23, 2026
- v0.6.2Sep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts