modelcontextprotocol / modelcontextprotocol/java-sdk
[HTTP+SSE] Throw the Initialization Exception Immediately for Invalid SSE Endpoint Instead of After Timeout
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 9
説明
Problem
Currently, when the SSE Endpoint is misconfigured, the client waits until the initialization timeout (e.g., 60s) before throwing an generic initialization exception. This causes unnecessary delays and makes debugging difficult.
Examples settings:
- If MCP Server SSE Endpoint is: http://localhost:8080/sse
- When MCP Client is configured:
- SSE Endpoint: http://localhost:8080/incorrect-sse
- Request timeout: 60s
- Initialization timeout: 60s
Behavior:
-
Calling Client.initialize() waits 60s before throwing an exception. The test code and exception are shown in the figure below:
-
Same issue occurs when:
-
The base URL points to a non-existent server. The test code and exception are shown in the figure below:
-
Access Token is misconfigured and the server requires authorization.
-
Expected Behavior
- Initialization exception should be thrown immediately when the server responds with an error (e.g., 404, 401, access denied), instead of waiting for the timeout.
- Exception should include status code and/or response body from the SSE endpoint to help diagnose configuration errors.
Technical Details
I checked the code, and the timeout issue occurs in the HttpClientSseClientTransport class when assigning the messageEndpointSink member variable. The initialization POST request keeps waiting for messageEndpointSink to be assigned. However, when the SSE Endpoint is incorrectly specified, the GET request never successfully returns the message endpoint, causing the initialization POST request to hang until the timeout occurs.
Affected Versions
- SDK 0.11.2
- SDK 0.12.1
- ...
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
HttpClientSseClientTransport から始めて、初期化 POST リクエストが messageEndpointSink を待機する仕組みと、SSE GET リクエストが無効なエンドポイントを処理する仕組みを追跡します。誤ったエンドポイント、存在しないサーバー、認証エラーのケースを再現し、初期化が初期化タイムアウトまで待機するのではなく、ステータスコードまたはレスポンスボディを伴うサーバーエラーを速やかに報告することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- api, networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100