modelcontextprotocol / modelcontextprotocol/java-sdk

Servlet transports block Tomcat thread

Aperta
#859 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Bug Description

All Servlet-based transports in the SDK (e.g., HttpServletStreamableServerTransportProvider, HttpServletSseServerTransportProvider, HttpServletStatelessServerTransport) call .block() on the Tomcat request thread when processing incoming HTTP requests.

Although AsyncContext is used to hold connections for SSE/streaming, the Tomcat thread remains parked until tool execution completes. As a result, the reactive/async architecture does not provide any real thread efficiency: the request thread stays blocked for the entire duration of the tool call.

With SyncToolSpecification and immediateExecution=false, the tool handler is executed on a separate thread (typically from the boundedElastic pool). This prevents blocking logic from running on the Tomcat thread itself, but the request thread still remains blocked waiting for completion.

With AsyncToolSpecification(via McpAsyncServer), handlers are expected to return fully asynchronous operations (e.g., non-blocking I/O). However, because the transport calls .block(), the HTTP request handling remains synchronous. The handler is not automatically scheduled on another thread unless the developer explicitly does so.

As a result, both SyncToolSpecification and AsyncToolSpecification ultimately block the Tomcat request thread until completion.

I’m not sure if this behavior is intentional. Based on the design of McpAsyncServer, I would expect the transport layer to release the Tomcat thread immediately and allow the reactive pipeline to complete asynchronously. (AsyncContext + subscribe).

Image Image

@pratik2294

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 con HttpServletStreamableServerTransportProvider, HttpServletSseServerTransportProvider e HttpServletStatelessServerTransport, tracciando dove le richieste in ingresso chiamano .block() e come viene utilizzato AsyncContext. Confronta i percorsi di SyncToolSpecification e AsyncToolSpecification, quindi verifica che i thread delle richieste vengano rilasciati mentre l’operazione reattiva continua e si completa correttamente.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.