OAuth MCP Server
A complete OAuth 2.1 server implementation for FastMCP with PKCE support, enabling secure authentication and authorization flows. Provides authorization code exchange, token management, and refresh capabilities for building authenticated MCP applications.
README
OAuth MCP Server
A complete OAuth 2.1 server implementation for FastMCP with PKCE support.
⚠️ Security Warning
This is an advanced authentication pattern. Building a secure OAuth server requires deep expertise in authentication protocols, cryptography, and security best practices. The FastMCP documentation strongly recommends using Remote OAuth or OAuth Proxy instead unless you have compelling requirements.
See OAUTH_README.md for complete documentation.
Quick Start
Installation
# Install dependencies
uv sync
Run the Server
python main.py
The server will start on http://localhost:8000 with a demo OAuth client registered.
Test the OAuth Flow
In a separate terminal:
python oauth_client_example.py
This will demonstrate the complete OAuth 2.1 flow including:
- PKCE challenge/verifier generation
- Authorization code exchange
- Access token usage
- Token refresh
Test Dynamic Client Registration
Register new OAuth clients dynamically at runtime:
python test_dcr.py
Or use curl:
curl -X POST http://localhost:8000/oauth/register \
-H "Content-Type: application/json" \
-d '{
"redirect_uris": ["http://localhost:5000/callback"],
"client_name": "My App",
"scope": "read write"
}'
The server will respond with a client_id and client_secret that you can use immediately.
Test New OAuth Endpoints
Test all the new OAuth 2.0/2.1 endpoints:
python test_new_endpoints.py
This tests:
- OAuth Authorization Server Metadata discovery
- Token revocation (RFC 7009)
- Token introspection (RFC 7662)
- UserInfo endpoint
Demo Credentials
OAuth Client:
- Client ID:
demo_client - Client Secret:
demo_secret
Demo User:
- Username:
demo_user - Password:
demo_password
Project Structure
oauth_mcp/
├── main.py # FastMCP server with OAuth
├── oauth_provider.py # OAuth 2.1 server implementation
├── oauth_client_example.py # Complete OAuth flow demo
├── test_dcr.py # Dynamic Client Registration test
├── test_new_endpoints.py # Tests for all new OAuth endpoints
├── client.py # Original simple client (no auth)
├── OAUTH_README.md # Complete documentation
└── README.md # This file
Features
✅ Full OAuth 2.1 implementation
✅ PKCE (Proof Key for Code Exchange)
✅ Authorization code flow
✅ Token refresh with rotation
✅ Token revocation (RFC 7009)
✅ Token introspection (RFC 7662)
✅ Scope validation
✅ State parameter for CSRF protection
✅ Dynamic Client Registration (DCR) - RFC 7591
✅ OAuth Authorization Server Metadata (RFC 8414)
✅ OAuth Protected Resource Metadata (RFC 9470)
✅ UserInfo endpoint for user profile
Documentation
See OAUTH_README.md for:
- Detailed architecture
- Security considerations
- Production deployment guide
- Database schema
- Testing strategies
- Troubleshooting
References
- FastMCP OAuth Documentation
- OAuth 2.1 Specification
- PKCE Specification (RFC 7636)
- Dynamic Client Registration (RFC 7591)
License
Copyright Anysphere Inc.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。