Secure MCP Auth Demo

Secure MCP Auth Demo

A teaching demo that implements JWT authentication and scope-based authorization for MCP tools, supporting role-based access to profile, notes, and admin operations.

Category
Visit Server

README

Secure MCP Auth Demo

A small, local teaching demo that uses a real MCP Streamable HTTP server with JWT bearer-token authentication and scope-based authorization.

It is intentionally separate from the LangChain and LangGraph demos in this workspace.

What it teaches

The demo models three roles:

Demo user Granted scopes
Alice Reader profile:read, notes:read
Bob Contributor Alice's scopes plus notes:write
Admin Auditor All scopes, including admin:read

The protected MCP tools are:

Tool Required scope
profile_read profile:read
notes_search notes:read
notes_create notes:write
admin_audit_log admin:read

The request path

Streamlit teaching client
  -> Authorization: Bearer <JWT>
  -> MCP Streamable HTTP server (/mcp)
  -> validate signature, exp, iss, aud
  -> read trusted sub and scope claims
  -> allow or deny the requested tool

The JWT includes sub, scope, aud, iss, iat, exp, and jti. JWT payloads are signed, not encrypted: do not place passwords, API keys, or sensitive personal information in them.

Run locally

This project uses an isolated virtual environment.

.\.venv\Scripts\python.exe server.py

In another terminal:

.\.venv\Scripts\streamlit.exe run app.py --server.port 8503

Open http://127.0.0.1:8503. Choose Alice, Bob, or Admin, inspect the issued token claims, and try each tool. For example, Alice receives HTTP 403 when trying notes_create, while Bob succeeds.

Verify

.\.venv\Scripts\python.exe -m unittest discover -s tests -v

The server also exposes MCP protected-resource metadata at:

http://127.0.0.1:8765/.well-known/oauth-protected-resource/mcp

Teaching boundary

The local app issues tokens itself so every part of the flow is easy to inspect. That is suitable for a lesson, not for a deployed service.

For production, replace auth.py's local issuer with a trusted OAuth/OIDC authorization server such as Auth0, Okta, Microsoft Entra ID, Amazon Cognito, or a company identity provider. Keep the MCP server's validation of issuer, audience, expiry, signature, and scopes.

MCP's HTTP authorization model uses bearer tokens in the Authorization header on every request, validates tokens as an OAuth resource server, and uses 401 for missing or invalid credentials and 403 for insufficient scopes. See the MCP Authorization specification.

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
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
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
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
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
E2B

E2B

Using MCP to run code via e2b.

Official
Featured