mcp-remote-auth-example
A minimal remote (Streamable HTTP) MCP server that is an OAuth 2.1 resource server, demonstrating the MCP authorization spec with token validation and audience checks.
README
mcp-remote-auth-example
A minimal remote (Streamable HTTP) MCP server that is an OAuth 2.1 resource server — the shape the MCP authorization spec requires for remote servers. It shows the only auth code you actually own on your server:
- Publishes Protected Resource Metadata at
/.well-known/oauth-protected-resource(RFC 9728). - Rejects unauthenticated requests with
401+ aWWW-Authenticateheader pointing at that metadata (the discovery entry point). - Validates every access token: signature, issuer, expiry, and audience (RFC 8707) — the check most walkthroughs skip.
You do not run your own OAuth server. In production you delete the local dev issuer and point the metadata at your IdP (Auth0, Okta, Keycloak, WorkOS, Entra). The dev issuer here exists only so the whole flow runs on your machine in one command.
Pinned to @modelcontextprotocol/sdk@1.29.0, TypeScript 5.9, jose 6.
One-command run
npm install
npm run demo
npm run demo boots the server and walks the four wire behaviors, printing the real request/response for each:
- Unauthenticated
POST /mcp→401+WWW-Authenticatereferencing the PRM URL. GET /.well-known/oauth-protected-resource→ the RFC 9728 document.- A correctly audience-bound token →
initialize+tools/list+tools/call whoamisucceed. - A token minted for a different resource →
401 invalid_token(the RFC 8707 audience check doing its job).
Tests
npm test
Six guard tests cover the same behaviors plus expired and malformed tokens.
What's yours vs. what's the dev stand-in
| File | Role | Keep in production? |
|---|---|---|
src/auth.ts |
The resource-server guard: PRM doc + token validation + audience check. | Yes — this is the code you own. |
src/server.ts |
Remote MCP server (Streamable HTTP) with the guard in front. | Yes. |
src/issuer.ts, /jwks |
A tiny local dev authorization server so the demo runs offline. | No — delete and use your IdP. |
src/config.ts |
resource (your server's canonical URI = the token audience) and issuer (your IdP). |
Yes — set from env. |
Going to production
- Delete
src/issuer.tsand the/jwksroute. - Set
OAUTH_ISSUERto your IdP's issuer URL andMCP_RESOURCEto your server's public canonical URI. - Your IdP already serves its own JWKS from its metadata;
src/auth.tsverifies against it unchanged.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.