Quickly integrate OAuth authentication from mcpmarket.cn into your MCP Server.
Uno OAuth MCP
Quickly integrate mcpmarket.cn OAuth authentication into your MCP Server.
✨ Features
- 🔐 Out-of-the-box - Integrate OAuth authentication with just a few lines of code
- 🎯 Dual Mode Support - FastMCP (simple) and Low-level Server (flexible)
- ⚡ High Performance - Built-in Token caching (LRU + TTL)
- 📋 Standard Compliant - Automatically generates RFC 9728/8414 well-known endpoints
📦 Installation
pip install uno-oauth-mcp
Or using uv:
uv add uno-oauth-mcp
🚀 Quick Start
Method 1: Based on FastMCP (Recommended for Beginners)
FastMCP is the official high-level wrapper with a simpler API:
from uno_oauth_mcp import UnoOAuthMCP
# Create an MCP Server with OAuth
mcp = UnoOAuthMCP(name="My Server", port=8080)
@mcp.tool()
def hello(name: str) -> str:
"""Say hello to the user"""
return f"Hello, {name}!"
@mcp.tool()
def add(a: int, b: int) -> int:
"""Calculate the sum of two numbers"""
return a + b
# Run
mcp.run(transport="streamable-http")
Method 2: Based on Low-level Server (More Flexible)
The low-level Server provides complete MCP protocol control:
import mcp.types as types
from uno_oauth_mcp import UnoOAuthServer
# Create a Server with OAuth
server = UnoOAuthServer(name="My Server", port=8080)
@server.list_tools()
async def list_tools():
return [
types.Tool(
name="hello",
description="Say hello to the user",
inputSchema={
"type": "object",
"properties": {"name": {"type": "string"}},
"required": ["name"]
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "hello":
return [types.TextContent(type="text", text=f"Hello, {arguments['name']}!")]
return []
# Run
server.run()
🆚 Comparison of Two Methods
| Feature | UnoOAuthMCP (FastMCP) | UnoOAuthServer (Low-level Server) |
|---------|----------------------|----------------------------------|
| Target Audience | Beginners, rapid development | Developers needing full control |
| API Style | Decorators + type inference | Explicit MCP type definitions |
| Tool Definition | @mcp.tool() auto-inference | Manual types.Tool construction |
| Flexibility | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| Code Amount | Less | More |
🔧 Configuration Options
# FastMCP method
mcp = UnoOAuthMCP(
name="My Server", # Server name
port=8080, # Listening port
host="0.0.0.0", # Listening address
mcpmarket_url="https://mcpmarket.cn", # Authentication server
required_scopes=["read", "write"], # OAuth scopes
cache_ttl=300, # Token cache time (seconds)
# Production environment needs to specify external access URL
# resource_server_url="https://my-mcp.example.com",
)
# Low-level Server method
server = UnoOAuthServer(
name="My Server",
port=8080,
mcp_path="/mcp", # MCP endpoint path
# ... other parameters same as above
)
🌐 Auto-registered Endpoints
The SDK automatically registers the following endpoints:
| Endpoint | Description |
|----------|-------------|
| /.well-known/oauth-protected-resource | OAuth Protected Resource Metadata (RFC 9728) |
| /.well-known/oauth-authorization-server | OAuth Authorization Server Metadata (RFC 8414) |
| /mcp | MCP protocol endpoint (requires authentication) |
| /health | Health check |
| / | Server information |
🔐 Authentication Flow
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ MCP Client │ │ Your Server │ │ mcpmarket.cn │
│(Cursor/Claude)│ │ │ │ │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
│ 1. Access MCP endpoint │
│ ─────────────────> │ │
│ │ │
│ 2. 401 + well-known │
│ <───────────────── │ │
│ │ │
│ 3. OAuth authorization │
│ ──────────────────────────────────────> │
│ │ │
│ 4. Get Token │
│ <────────────────────────────────────── │
│ │ │
│ 5. Access with Token │
│ ─────────────────> │ │
│ │ 6. Verify Token │
│ │ ─────────────────> │
│ │ 7. Verification success │
│ │ <───────────────── │
│ 8. MCP response │
│ <───────────────── │ │
📚 More Examples
Server with Resources
from uno_oauth_mcp import UnoOAuthMCP
mcp = UnoOAuthMCP(name="Resource Server")
@mcp.tool()
def get_data(key: str) -> str:
return f"Data for {key}"
@mcp.resource("config://app")
def get_config() -> str:
return '{"version": "1.0.0"}'
@mcp.resource("data://{item_id}")
def get_item(item_id: str) -> str:
return f'{{"id": "{item_id}"}}'
mcp.run(transport="streamable-http")
Using Native Server + create_oauth_starlette_app
from mcp.server.lowlevel import Server
from uno_oauth_mcp import create_oauth_starlette_app
import uvicorn
server = Server("my-server")
@server.list_tools()
async def list_tools():
return [...]
# Create Starlette app with OAuth
app = create_oauth_starlette_app(server, port=8080)
# Can add custom routes
# from starlette.routing import Route
# app.routes.append(Route("/custom", ...))
uvicorn.run(app, host="0.0.0.0", port=8080)
🔗 Related Resources
- MCPMarket - MCP Server Marketplace
- MCP Python SDK
- RFC 9728 - OAuth Protected Resource Metadata
- RFC 8414 - OAuth Authorization Server Metadata
📄 License
MIT License
Made with ❤️ by MCPMarket