Skip to content

[Client] Inject Bearer token into HttpTransport requests + handle 401 re-auth #316

@soyuka

Description

@soyuka

Context

Once an access token is acquired (via any OAuth grant), every outbound JSON-RPC request on HttpTransport must carry Authorization: Bearer <token>. On a 401 Unauthorized mid-session, the transport must trigger a re-auth attempt and retry the failed request exactly once.

Scope

  • src/Client/Transport/HttpTransport.php:
    • Read current token from TokenStorageInterface keyed by endpoint URL.
    • Add Authorization: Bearer <token> header on send() when a token is present.
    • On 401, parse WWW-Authenticate header, invoke auth coordinator, retry once.
  • Introduce Mcp\Client\Auth\AuthCoordinator to orchestrate discovery → registration → token acquisition. (Implementation details land in dependent issues.)

Conformance scenarios unblocked

All auth/* scenarios depend on this wiring.

Dependencies

Blocked by: #315 (TokenStorageInterface).

Acceptance

  • Unit tests for header injection + 401 retry behavior.
  • Documented extension point for AuthCoordinator.

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions