[BUG] `StreamableHttpMcpTransport` registers the client's reply to a server ping as a pending operation

Author: ShxuuerCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbug

Describe the bug

StreamableHttpMcpTransport.sendMessage goes through the same execute method as sendRequest, and execute registers the message id in the pending-operations map whenever the id is not null. sendMessage is meant for messages that expect no reply, so nothing should be registered. Notifications have no id and are fine, but a reply to a server-initiated request carries an id - the server's. That reply is registered and never completed, because nothing is ever going to answer it. The two transports that share a single channel already avoid this: StdioMcpTransport passes a null id and WebSocketMcpTransport passes null as well. Only the Streamable HTTP transport registers. There are two consequences. The entry stays in the pending-operations map for the lifetime of the client. And since the client and the server number their requests independently, a server id can be equal to the id of a client request that is still in flight; the registration then overwrites that request's future, and the request can only end in a timeout.

Log and Stack trace

To Reproduce

Any server that sends a ping request to the client, which is a common keepalive, is enough. McpOperationHandler answers it through sendMessage:

java
transport.sendMessage(new McpPingResponse(messageId));

roots/list requests have the same effect.

Expected behavior

The reply should be sent and nothing should be awaited for it. The id belongs to the server's id space and is only meaningful on the wire.

Please complete the following information:

  • LangChain4j version: 1.21.0-beta31-SNAPSHOT (main)
  • LLM(s) used: not relevant
  • Java version: 17
  • Spring Boot version (if applicable): not relevant

Additional context