Skip to content

Commit b777286

Browse files
Allow parent protected resource metadata
1 parent 0c30a71 commit b777286

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

src/mcp/client/auth/oauth2.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ async def _handle_oauth_metadata_response(self, response: httpx2.Response) -> No
564564
self.context.oauth_metadata = metadata
565565

566566
async def _validate_resource_match(self, prm: ProtectedResourceMetadata) -> None:
567-
"""Validate that the PRM resource matches the server URL per RFC 9728."""
567+
"""Validate that the PRM resource permits the server URL."""
568568
prm_resource = str(prm.resource) if prm.resource else None
569569

570570
if self._validate_resource_url_callback is not None:
@@ -574,10 +574,7 @@ async def _validate_resource_match(self, prm: ProtectedResourceMetadata) -> None
574574
if not prm_resource:
575575
return # pragma: no cover
576576
default_resource = resource_url_from_server_url(self.context.server_url)
577-
if not (
578-
check_resource_allowed(requested_resource=default_resource, configured_resource=prm_resource)
579-
and check_resource_allowed(requested_resource=prm_resource, configured_resource=default_resource)
580-
):
577+
if not check_resource_allowed(requested_resource=default_resource, configured_resource=prm_resource):
581578
raise OAuthFlowError(f"Protected resource {prm_resource} does not match expected {default_resource}")
582579

583580
async def async_auth_flow(self, request: httpx2.Request) -> AsyncGenerator[httpx2.Request, httpx2.Response]:

tests/client/test_auth.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,10 @@ async def test_validate_resource_rejects_mismatched_resource(
863863

864864

865865
@pytest.mark.anyio
866-
async def test_validate_resource_rejects_parent_path_resource(
866+
async def test_validate_resource_accepts_parent_path_resource(
867867
client_metadata: OAuthClientMetadata, mock_storage: MockTokenStorage
868868
) -> None:
869-
"""Client rejects PRM resources that are a parent of the server URL."""
869+
"""Client accepts PRM resources that are a parent of the server URL."""
870870
provider = OAuthClientProvider(
871871
server_url="https://api.example.com/v1/mcp",
872872
client_metadata=client_metadata,
@@ -878,8 +878,7 @@ async def test_validate_resource_rejects_parent_path_resource(
878878
resource=AnyHttpUrl("https://api.example.com/v1"),
879879
authorization_servers=[AnyHttpUrl("https://auth.example.com")],
880880
)
881-
with pytest.raises(OAuthFlowError, match="does not match expected"):
882-
await provider._validate_resource_match(prm)
881+
await provider._validate_resource_match(prm)
883882

884883

885884
@pytest.mark.anyio

0 commit comments

Comments
 (0)