mcp-oauth
FastMCP server with Bearer token authentication mounted on FastAPI, including OAuth 2.1 endpoints for dynamic client registration and metadata discovery.
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.txtfor 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 (sseorhttp, 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.
-
Configure the server URL: Enter
http://localhost:8000/mcp/ssein the MCP Inspector
-
Initiate OAuth flow: Click the "Quick OAuth Flow" button to start authentication

-
Complete authentication: Follow the OAuth steps and grant the necessary permissions

Method 2: FastMCP Python Client
Use the FastMCP Client for programmatic access with OAuth authentication.
- Update the client configuration: Modify the server URL in
client.pyto match your server endpoint - Run the client:
python client.py
Method 3: Claude Integration
Integrate the MCP server directly with Claude for AI assistant access.
- Navigate to settings: Go to Settings → Integrations → Add Integration
- Configure the server: Input the server configuration details

- 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 messageadd_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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。