modelcontextprotocol / modelcontextprotocol/php-sdk

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

オープン
#316 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

auth Client enhancement improves spec compliance
主要言語
PHP
スター
1.6k
フォーク
173
平均マージ
2日 49分
マージ済み PR(30日)
23

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

src/Client/Transport/HttpTransport.php から開始し、#315 の TokenStorageInterface 依存関係を確認します。send() と認証コーディネーターのエントリーポイントを追跡し、その後、Bearer ヘッダーの注入と、401 に対する一度だけの再認証リトライを対象とするユニットテストのカバレッジを追加します。完了条件は、リクエストが現在のエンドポイントトークンを使用し、401 レスポンスが 1 回のリトライを発生させ、AuthCoordinator の拡張ポイントがドキュメント化されていることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
api, authentication, backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。