Skip to content

Commit 059b42b

Browse files
committed
more typings and add docstrings
1 parent af2d985 commit 059b42b

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

examples/example-fastmcp-mcp/src/auth0/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424

2525

2626
class Auth0Mcp:
27+
"""
28+
Auth0 integration for FastMCP servers.
29+
30+
Provides authentication middleware, authorization decorators,
31+
and OAuth2 Protected Resource metadata endpoints for MCP servers.
32+
33+
Args:
34+
name: Human-readable name for the MCP server
35+
audience: Auth0 API identifier (OAuth2 audience claim)
36+
domain: Auth0 tenant domain (e.g., 'tenant.us.auth0.com')
37+
38+
Raises:
39+
RuntimeError: If audience or domain are not provided
40+
"""
2741
def __init__(self, name: str, audience: str, domain: str, mcp_server_url: str | None = None):
2842
self.name = name
2943
self.audience = audience
@@ -77,7 +91,7 @@ def exception_handlers(self) -> dict[int | type[Exception], Callable[[Request, E
7791
Exception: self._generic_exception_handler,
7892
}
7993

80-
def _auth_error_handler(self, request: Request, exc: Exception):
94+
def _auth_error_handler(self, request: Request, exc: Exception) -> JSONResponse:
8195
"""
8296
Handle auth errors: malformed authorization requests, missing auth, invalid tokens, and insufficient scopes.
8397
"""

examples/example-fastmcp-mcp/src/tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
from mcp.server.fastmcp import Context
44

5+
from .auth0 import Auth0Mcp
56
from .auth0.authz import require_scopes
67

78

8-
def register_tools(auth0Mcp) -> None:
9+
def register_tools(auth0_mcp: Auth0Mcp) -> None:
910
"""
1011
Register all tools with the MCP server.
1112
"""
12-
mcp = auth0Mcp.mcp
13+
mcp = auth0_mcp.mcp
1314
# Register scopes used by tools for Protected Resource Metadata
14-
auth0Mcp.register_scopes(["tool:greet", "tool:whoami"])
15+
auth0_mcp.register_scopes(["tool:greet", "tool:whoami"])
1516

1617
# Tool without required scopes
1718
@mcp.tool()

0 commit comments

Comments
 (0)