Skip to content

Commit 297eded

Browse files
committed
fix: normalize trailing slashes in PRM resource validation
Pydantic AnyHttpUrl adds a trailing slash to root URLs (e.g. "https://example.com/") while resource_url_from_server_url may return without one. This caused check_resource_allowed to reject valid root-URL servers due to path length mismatch.
1 parent f966fab commit 297eded

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/mcp/client/auth/oauth2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ def _validate_resource_match(self, prm: ProtectedResourceMetadata) -> None:
482482
return
483483
default_resource = resource_url_from_server_url(self.context.server_url)
484484
prm_resource = str(prm.resource)
485+
# Normalize: Pydantic AnyHttpUrl adds trailing slash to root URLs
486+
# (e.g. "https://example.com/") while resource_url_from_server_url may not.
487+
if not default_resource.endswith("/"):
488+
default_resource += "/"
489+
if not prm_resource.endswith("/"):
490+
prm_resource += "/"
485491
if not check_resource_allowed(requested_resource=default_resource, configured_resource=prm_resource):
486492
raise OAuthFlowError(f"Protected resource {prm_resource} does not match expected {default_resource}")
487493

0 commit comments

Comments
 (0)