mcp-remote-auth-example

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.

Category
Visit Server

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 + a WWW-Authenticate header 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:

  1. Unauthenticated POST /mcp → 401 + WWW-Authenticate referencing the PRM URL.
  2. GET /.well-known/oauth-protected-resource → the RFC 9728 document.
  3. A correctly audience-bound token → initialize + tools/list + tools/call whoami succeed.
  4. 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

  1. Delete src/issuer.ts and the /jwks route.
  2. Set OAUTH_ISSUER to your IdP's issuer URL and MCP_RESOURCE to your server's public canonical URI.
  3. Your IdP already serves its own JWKS from its metadata; src/auth.ts verifies against it unchanged.

License

MIT

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured