-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathmetadata.py
More file actions
47 lines (33 loc) · 1.3 KB
/
metadata.py
File metadata and controls
47 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Handler for OAuth 2.0 Authorization Server Metadata.
Corresponds to TypeScript file: src/server/auth/handlers/metadata.ts
"""
from typing import Callable
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
from mcp.shared.auth import OAuthMetadata
def create_metadata_handler(metadata: OAuthMetadata) -> Callable:
"""
Create a handler for OAuth 2.0 Authorization Server Metadata.
Corresponds to metadataHandler in src/server/auth/handlers/metadata.ts
Args:
metadata: The metadata to return in the response
Returns:
A Starlette endpoint handler function
"""
async def metadata_handler(request: Request) -> Response:
"""
Handler for the OAuth 2.0 Authorization Server Metadata endpoint.
Args:
request: The Starlette request
Returns:
JSON response with the authorization server metadata
"""
# Convert metadata to dict and remove any None values
metadata_dict = metadata.model_dump()
clean_metadata = {k: v for k, v in metadata_dict.items() if v is not None}
return JSONResponse(
content=clean_metadata,
headers={"Cache-Control": "public, max-age=3600"}, # Cache for 1 hour
)
return metadata_handler