|
1 | 1 | from dataclasses import dataclass |
2 | | -from typing import Any |
3 | 2 |
|
4 | 3 | from pydantic import AnyUrl |
5 | 4 | from starlette.routing import Route, Router |
|
11 | 10 | from mcp.server.auth.handlers.token import TokenHandler |
12 | 11 | from mcp.server.auth.middleware.client_auth import ClientAuthenticator |
13 | 12 | from mcp.server.auth.provider import OAuthServerProvider |
| 13 | +from mcp.shared.auth import OAuthMetadata |
14 | 14 |
|
15 | 15 |
|
16 | 16 | @dataclass |
@@ -139,29 +139,29 @@ def build_metadata( |
139 | 139 | service_documentation_url: AnyUrl | None, |
140 | 140 | client_registration_options: ClientRegistrationOptions, |
141 | 141 | revocation_options: RevocationOptions, |
142 | | -) -> dict[str, Any]: |
| 142 | +) -> OAuthMetadata: |
143 | 143 | issuer_url_str = str(issuer_url).rstrip("/") |
144 | 144 | # Create metadata |
145 | | - metadata = { |
146 | | - "issuer": issuer_url_str, |
147 | | - "service_documentation": str(service_documentation_url).rstrip("/") |
| 145 | + metadata = OAuthMetadata( |
| 146 | + issuer=issuer_url_str, |
| 147 | + service_documentation=str(service_documentation_url).rstrip("/") |
148 | 148 | if service_documentation_url |
149 | 149 | else None, |
150 | | - "authorization_endpoint": f"{issuer_url_str}{AUTHORIZATION_PATH}", |
151 | | - "response_types_supported": ["code"], |
152 | | - "code_challenge_methods_supported": ["S256"], |
153 | | - "token_endpoint": f"{issuer_url_str}{TOKEN_PATH}", |
154 | | - "token_endpoint_auth_methods_supported": ["client_secret_post"], |
155 | | - "grant_types_supported": ["authorization_code", "refresh_token"], |
156 | | - } |
| 150 | + authorization_endpoint=f"{issuer_url_str}{AUTHORIZATION_PATH}", |
| 151 | + response_types_supported=["code"], |
| 152 | + code_challenge_methods_supported=["S256"], |
| 153 | + token_endpoint=f"{issuer_url_str}{TOKEN_PATH}", |
| 154 | + token_endpoint_auth_methods_supported=["client_secret_post"], |
| 155 | + grant_types_supported=["authorization_code", "refresh_token"], |
| 156 | + ) |
157 | 157 |
|
158 | 158 | # Add registration endpoint if supported |
159 | 159 | if client_registration_options.enabled: |
160 | | - metadata["registration_endpoint"] = f"{issuer_url_str}{REGISTRATION_PATH}" |
| 160 | + metadata.registration_endpoint = f"{issuer_url_str}{REGISTRATION_PATH}" |
161 | 161 |
|
162 | 162 | # Add revocation endpoint if supported |
163 | 163 | if revocation_options.enabled: |
164 | | - metadata["revocation_endpoint"] = f"{issuer_url_str}{REVOCATION_PATH}" |
165 | | - metadata["revocation_endpoint_auth_methods_supported"] = ["client_secret_post"] |
| 164 | + metadata.revocation_endpoint = f"{issuer_url_str}{REVOCATION_PATH}" |
| 165 | + metadata.revocation_endpoint_auth_methods_supported = ["client_secret_post"] |
166 | 166 |
|
167 | 167 | return metadata |
0 commit comments