Skip to content

Commit 2023262

Browse files
committed
refactor: reorganize imports and clean up whitespace in server.py
- Moved import of AnyHttpUrl to the appropriate section for clarity - Removed unnecessary duplicate import of urlparse - Cleaned up whitespace for improved code readability
1 parent 2b85dbd commit 2023262

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,10 @@ def streamable_http_app(self) -> Starlette:
937937
# Determine resource metadata URL
938938
resource_metadata_url = None
939939
if self.settings.auth and self.settings.auth.resource_server_url:
940-
from pydantic import AnyHttpUrl
941940
from urllib.parse import urlparse
942941

942+
from pydantic import AnyHttpUrl
943+
943944
# RFC 9728 §3.1: Insert /.well-known/oauth-protected-resource between host and resource path
944945
# This URL will be used in WWW-Authenticate header for client discovery
945946
parsed = urlparse(str(self.settings.auth.resource_server_url))
@@ -966,23 +967,24 @@ def streamable_http_app(self) -> Starlette:
966967

967968
# Add protected resource metadata endpoint if configured as RS
968969
if self.settings.auth and self.settings.auth.resource_server_url:
970+
from urllib.parse import urlparse
971+
969972
from mcp.server.auth.handlers.metadata import ProtectedResourceMetadataHandler
970973
from mcp.server.auth.routes import cors_middleware
971974
from mcp.shared.auth import ProtectedResourceMetadata
972-
from urllib.parse import urlparse
973975

974976
protected_resource_metadata = ProtectedResourceMetadata(
975977
resource=self.settings.auth.resource_server_url,
976978
authorization_servers=[self.settings.auth.issuer_url],
977979
scopes_supported=self.settings.auth.required_scopes,
978980
)
979-
981+
980982
# RFC 9728 §3.1: Register route at /.well-known/oauth-protected-resource + resource path
981983
parsed = urlparse(str(self.settings.auth.resource_server_url))
982984
# Handle trailing slash: if path is just "/", treat as empty
983985
resource_path = parsed.path if parsed.path != "/" else ""
984986
well_known_path = f"/.well-known/oauth-protected-resource{resource_path}"
985-
987+
986988
routes.append(
987989
Route(
988990
well_known_path,

0 commit comments

Comments
 (0)