mcp-oauth

mcp-oauth

FastMCP server with Bearer token authentication mounted on FastAPI, including OAuth 2.1 endpoints for dynamic client registration and metadata discovery.

Category
Visit Server

README

MCP OAuth Server Example

This project demonstrates FastMCP server with Bearer token authentication mounted on FastAPI, including OAuth 2.1 endpoints for dynamic client registration and metadata discovery.

MCP Server Setup

Requirements

  • Python 3.8+
  • See requirements.txt for all dependencies

Installation

pip install -r requirements.txt

Env

cp .env.example .env

Create an OAuth application with any OAuth provider. (I've used Clerk as an example.)
Obtain the client_id and client_secret from your provider.
Update your .env file with the appropriate environment variables:

CLERK_ISSUER=<issuer_url>
CLERK_AUDIENCE=<clerk_client_id>
CLERK_CLIENT_SECRET=<clerk_client_secret>
BASE_URL=http://localhost:8000

Running the Server

python server.py

eg.

python server.py --transport sse --host 0.0.0.0 --port 8000 --log-level info

Command Line Options

python server.py --help
  • --transport: Transport type (sse or http, default: sse)
  • --host: Host address (default: 127.0.0.1)
  • --port: Port number (default: 8000)
  • --log-level: Logging level (default: info)

Testing the Server

Method 1: MCP Inspector

The MCP Inspector provides a web-based interface to test MCP servers with OAuth authentication.

  1. Configure the server URL: Enter http://localhost:8000/mcp/sse in the MCP Inspector Configure MCP Inspector

  2. Initiate OAuth flow: Click the "Quick OAuth Flow" button to start authentication Start OAuth Flow

  3. Complete authentication: Follow the OAuth steps and grant the necessary permissions Grant Permissions

Method 2: FastMCP Python Client

Use the FastMCP Client for programmatic access with OAuth authentication.

  1. Update the client configuration: Modify the server URL in client.py to match your server endpoint
  2. Run the client:
    python client.py
    

Method 3: Claude Integration

Integrate the MCP server directly with Claude for AI assistant access.

  1. Navigate to settings: Go to Settings → Integrations → Add Integration
  2. Configure the server: Input the server configuration details Claude MCP Integration
  3. Establish connection: Click "Connect" to enable the integration

Server Endpoints

Core Endpoints

  • MCP Server: http://127.0.0.1:8000/mcp - Main MCP endpoint
  • Health Check: http://127.0.0.1:8000/mcp/health - Server health status
  • API Documentation: http://127.0.0.1:8000/docs - FastAPI auto-generated docs

OAuth 2.1 Endpoints

  • Authorization Server Metadata: http://127.0.0.1:8000/.well-known/oauth-authorization-server
  • OpenID Connect Discovery: http://127.0.0.1:8000/.well-known/openid-configuration
  • Protected Resource Metadata: http://127.0.0.1:8000/.well-known/oauth-protected-resource
  • Dynamic Client Registration: POST http://127.0.0.1:8000/register

Development Endpoints

  • Development Token: http://127.0.0.1:8000/dev/token - Generate test tokens

Environment Variables

You can configure the server using environment variables:

  • ISSUER: JWT issuer (default: https://dev.example.com)
  • AUDIENCE: JWT audience (default: my-mcp-server)
  • CLIENT_SECRET: OAuth client secret (default: auto-generated UUID)
  • BASE_URL: Base URL for the server (default: http://127.0.0.1:8000)

Example MCP Tools

  • hello(name: str) -> str: Returns a greeting message
  • add_numbers(a: int, b: int) -> int: Adds two numbers together

Both tools require valid authentication.

OAuth 2.1 Compliance

This server implements key OAuth 2.1 endpoints:

  • Authorization Server Metadata Discovery
  • Dynamic Client Registration (RFC 7591)
  • Protected Resource Metadata (RFC 8705)

Note: This is a development/demonstration server. For production use, integrate with a proper OAuth 2.1 Authorization Server or Identity Provider.

Features

  • FastMCP server mounted on FastAPI
  • Bearer token (JWT) authentication using RSA public key validation
  • OAuth 2.1 Authorization Server metadata endpoints
  • Dynamic client registration endpoint
  • OpenID Connect discovery endpoint
  • CORS middleware for cross-origin requests
  • Structured logging with loguru
  • Development token generation endpoint
  • Health check endpoint
  • Multiple MCP tools (hello, add_numbers)

References

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