modelcontextprotocol / modelcontextprotocol/java-sdk
[HTTP+SSE] Throw the Initialization Exception Immediately for Invalid SSE Endpoint Instead of After Timeout
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 3.7k
- Forks
- 1.1k
- Merge moyen
- 1 j 15 h
- PR mergées (30 j)
- 9
Description
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
- ...
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans HttpClientSseClientTransport et suivez la manière dont la requête POST d’initialisation attend messageEndpointSink et dont la requête GET SSE gère les endpoints invalides. Reproduisez les cas d’un endpoint incorrect, d’un serveur inexistant et d’une erreur d’autorisation, puis vérifiez que l’initialisation signale rapidement l’erreur du serveur avec son code d’état ou le corps de sa réponse, au lieu d’attendre le délai d’expiration de l’initialisation.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- api, networking
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100