modelcontextprotocol / modelcontextprotocol/java-sdk
[HTTP+SSE] Throw the Initialization Exception Immediately for Invalid SSE Endpoint Instead of After Timeout
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 3.7k
- Forks
- 1.1k
- Ø Merge
- 1 T. 15 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
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
- ...
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in HttpClientSseClientTransport und verfolge, wie die Initialisierungs-POST-Anfrage auf messageEndpointSink wartet und wie die SSE-GET-Anfrage mit ungültigen Endpunkten umgeht. Reproduziere die Fälle eines falschen Endpunkts, eines nicht vorhandenen Servers und eines Autorisierungsfehlers und überprüfe anschließend, dass die Initialisierung den Serverfehler umgehend mit seinem Statuscode oder Antworttext meldet, statt auf das Initialisierungs-Timeout zu warten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- api, networking
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100