Skip to content

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

Closed

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

Activity

  1. added
    ClientIssues & PRs related to the Client component
    P1Significant bug affecting many users, highly requested feature
    authIssues and PRs related to Authentication / OAuth
    improves spec complianceImproves consistency with other SDKs such as TyepScript
    enhancementRequest for a new feature that's not currently supported
    on May 19, 2026
  2. removed
    P1Significant bug affecting many users, highly requested feature
    on Aug 19, 2026
  3. chr-hertel commented on Nov 10, 2026

    @chr-hertel
    Member

    Solved with #663 and #666 - will be part of v0.10.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientIssues & PRs related to the Client componentauthIssues 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