ワンクリックで
mcp-builderadd-auth
Add OAuth authentication to your MCP server using Auth0 or custom providers
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Add OAuth authentication to your MCP server using Auth0 or custom providers
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Scaffold a new MCP server with your chosen pattern (basic, tool-heavy, widget-enabled, or database-backed)
Test your MCP server with MCP Inspector and verify tool functionality
Scaffold a complete MCP App with visual UI tools (TypeScript + React + Tailwind)
Add a resource to your MCP server for agent context (schemas, templates, reference data)
Add a new tool to your MCP server using "true task" design principles
Generate deployment configuration for Cloud Run, Render, or Fly.io
| name | mcp-builder:add-auth |
| description | Add OAuth authentication to your MCP server using Auth0 or custom providers |
You are helping the user add authentication to their MCP server using the MCP Authorization Specification.
MCP supports OAuth 2.1 with PKCE for authentication. This enables:
Add authentication when:
The spec requires:
| Provider | Best For | Complexity |
|---|---|---|
| Auth0 | Quick setup, managed service | Low |
| Supabase Auth | Already using Supabase | Low |
| Custom OAuth | Full control, enterprise | High |
Create Auth0 Application
Configure Allowed Callbacks
Allowed Callback URLs: https://your-server.com/callback
Allowed Logout URLs: https://your-server.com
Create API in Auth0
https://your-server.com/apiread:tasks, write:tasks, delete:tasksPython (FastMCP):
from fastapi import Request, HTTPException
from fastapi.responses import JSONResponse
import httpx
import jwt
AUTH0_DOMAIN = os.environ["AUTH0_DOMAIN"]
AUTH0_AUDIENCE = os.environ["AUTH0_AUDIENCE"]
# Protected Resource Metadata
@mcp.custom_route("/.well-known/oauth-protected-resource", methods=["GET"])
async def protected_resource_metadata(request: Request):
return JSONResponse({
"resource": AUTH0_AUDIENCE,
"authorization_servers": [f"https://{AUTH0_DOMAIN}/"],
"scopes_supported": ["read:tasks", "write:tasks", "delete:tasks"],
"bearer_methods_supported": ["header"],
})
# Token verification middleware
async def verify_token(request: Request) -> dict:
auth_header = request.headers.get("Authorization", "")
if not auth_header.startswith("Bearer "):
raise HTTPException(
status_code=401,
headers={"WWW-Authenticate": f'Bearer realm="{AUTH0_AUDIENCE}"'}
)
token = auth_header[7:]
# Get JWKS
jwks_url = f"https://{AUTH0_DOMAIN}/.well-known/jwks.json"
async with httpx.AsyncClient() as client:
jwks = (await client.get(jwks_url)).json()
# Verify token
try:
payload = jwt.decode(
token,
jwks,
algorithms=["RS256"],
audience=AUTH0_AUDIENCE,
issuer=f"https://{AUTH0_DOMAIN}/"
)
return payload
except jwt.InvalidTokenError as e:
raise HTTPException(status_code=401, detail=str(e))
# Get user from token in tool handlers
def get_user_id(request: Request) -> str:
"""Extract user ID from verified token."""
token_payload = request.state.token_payload
return token_payload.get("sub")
Implement tool-level permissions:
TOOL_SCOPES = {
"search-tasks": ["read:tasks"],
"create-task": ["write:tasks"],
"delete-task": ["delete:tasks"],
}
async def check_scope(request: Request, tool_name: str):
"""Verify user has required scope for tool."""
required_scopes = TOOL_SCOPES.get(tool_name, [])
token_scopes = request.state.token_payload.get("scope", "").split()
for scope in required_scopes:
if scope not in token_scopes:
raise HTTPException(
status_code=403,
detail=f"Missing required scope: {scope}"
)
Filter data by authenticated user:
@mcp.tool()
async def search_tasks(query: str, request: Request) -> str:
"""Search tasks for the authenticated user."""
user_id = get_user_id(request)
# Query only this user's tasks
results = await db.fetch(
"SELECT * FROM tasks WHERE user_id = $1 AND subject ILIKE $2",
user_id, f"%{query}%"
)
return json.dumps(results)
# .env
AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_AUDIENCE=https://your-server.com/api
AUTH0_CLIENT_ID=your-client-id
AUTH0_CLIENT_SECRET=your-client-secret
Get test token from Auth0:
curl --request POST \
--url https://YOUR_DOMAIN/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET","audience":"YOUR_API_AUDIENCE","grant_type":"client_credentials"}'
Test authenticated request:
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/mcp
{
"auth": {
"provider": "auth0",
"domain": "your-tenant.auth0.com",
"scopes": ["read:tasks", "write:tasks", "delete:tasks"]
}
}