Skip to content

[Client] Implement Protected Resource Metadata discovery (RFC 9728) #317

Description

@soyuka

Context

Per the MCP authorization spec (2025-06-18+), an unauthenticated client receiving a 401 MUST parse WWW-Authenticate: Bearer resource_metadata="<url>", fetch the indicated /.well-known/oauth-protected-resource document, and use it to locate the authorization server.

Scope

  • Mcp\Client\Auth\ProtectedResourceMetadataDiscoverer:
    • Parse WWW-Authenticate for resource_metadata.
    • GET the URL, parse JSON.
    • Resolve authorization_servers[], bearer_methods_supported, scopes_supported, resource (audience).
  • Validate resource matches the MCP server origin (defense-in-depth for auth/resource-mismatch, already passing).

Conformance scenarios unblocked

auth/metadata-default, auth/metadata-var1, auth/metadata-var2, auth/metadata-var3, auth/basic-cimd.

Dependencies

Blocked by: #316 (Bearer injection plumbs the 401 hook).

Acceptance

  • Unit + integration tests against fixtures from the conformance fixtures dir.
  • Conformance: 4 baseline scenarios above pass.

cc @soyuka

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientIssues & PRs related to the Client componentP1Significant bug affecting many users, highly requested featureauthIssues and PRs related to Authentication / OAuthenhancementRequest for a new feature that's not currently supportedimproves spec complianceImproves consistency with other SDKs such as TyepScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions