modelcontextprotocol / modelcontextprotocol/php-sdk
[Client] Inject Bearer token into HttpTransport requests + handle 401 re-auth
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.6k
- Forks
- 173
- Avg merge
- 2d 49m
- Merged PRs (30d)
- 23
Description
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
TokenStorageInterfacekeyed by endpoint URL. - Add
Authorization: Bearer <token>header onsend()when a token is present. - On
401, parseWWW-Authenticateheader, invoke auth coordinator, retry once.
- Read current token from
- Introduce
Mcp\Client\Auth\AuthCoordinatorto 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Client/Transport/HttpTransport.php and review the TokenStorageInterface dependency from #315. Trace send() and the authentication coordinator entry point, then add unit coverage for Bearer header injection and one-time 401 re-auth retry. Done means requests use the current endpoint token, 401 responses trigger one retry, and the AuthCoordinator extension point is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, authentication, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100