modelcontextprotocol / modelcontextprotocol/java-sdk

[HTTP+SSE] Throw the Initialization Exception Immediately for Invalid SSE Endpoint Instead of After Timeout

Aperta
#546 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P2
Lingua principale
Java
Stelle
3.7k
Fork
1.1k
Merge medio
1g 15h
PR unite (30g)
9

Descrizione

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:
    Image

  • Same issue occurs when:

    • The base URL points to a non-existent server. The test code and exception are shown in the figure below:
      Image

    • 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
  • ...

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da HttpClientSseClientTransport e traccia il modo in cui la richiesta POST di inizializzazione attende messageEndpointSink e il modo in cui la richiesta GET SSE gestisce gli endpoint non validi. Riproduci i casi di un endpoint errato, di un server inesistente e di un errore di autorizzazione, quindi verifica che l'inizializzazione segnali tempestivamente l'errore del server con il relativo codice di stato o corpo della risposta, invece di attendere il timeout dell'inizializzazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
api, networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.