fastmcp/examples/auth/auth0_mcp/server.py
vijaydeepsinha 654335607c
Fix-issue-4284 : Add Auth0MCPProvider for Auth0 Auth for MCP (#4411)
* Add Auth0MCPProvider for Auth0 Auth for MCP

* Document Auth0 MCP provider integration

* Add Auth0MCPProvider scope and auth rejection tests

Cover permissions-based required_scopes enforcement and unauthenticated MCP 401 responses.

* fixed documentation

* Narrow Auth0 docs to integration guide only

* Fix Auth0 provider: use httpx2 instead of httpx

httpx is a dev-only transitive dependency in this repo; runtime installs
declare httpx2 exclusively. The module-level 'import httpx' in auth0.py
broke import on a clean install of fastmcp or fastmcp-slim[server].

---------

Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2026-07-18 21:15:02 -04:00

39 lines
928 B
Python

"""Auth0 Auth for MCP server example.
Required environment variables:
- AUTH0_CONFIG_URL: OIDC discovery URL for your Auth0 tenant
To run:
export AUTH0_CONFIG_URL="https://YOUR_TENANT.auth0.com/.well-known/openid-configuration"
python server.py
"""
import os
import sys
from fastmcp import FastMCP
from fastmcp.server.auth.providers.auth0 import Auth0MCPProvider
config_url = os.getenv("AUTH0_CONFIG_URL")
if not config_url:
sys.exit(
"AUTH0_CONFIG_URL must be set to your Auth0 OIDC discovery URL, "
'e.g. "https://YOUR_TENANT.auth0.com/.well-known/openid-configuration"'
)
auth = Auth0MCPProvider(
config_url=config_url,
base_url="http://127.0.0.1:8000",
)
mcp = FastMCP("Auth0 MCP Example Server", auth=auth)
@mcp.tool
def echo(message: str) -> str:
"""Echo the provided message."""
return message
if __name__ == "__main__":
mcp.run(transport="http", port=8000)