Class WebClientStreamableHttpTransport

java.lang.Object
io.modelcontextprotocol.client.transport.WebClientStreamableHttpTransport
All Implemented Interfaces:
io.modelcontextprotocol.spec.McpClientTransport, io.modelcontextprotocol.spec.McpTransport

public class WebClientStreamableHttpTransport extends Object implements io.modelcontextprotocol.spec.McpClientTransport
An implementation of the Streamable HTTP protocol as defined by the 2025-03-26 version of the MCP specification.

The transport is capable of resumability and reconnects. It reacts to transport-level session invalidation and will propagate appropriate exceptions to the higher level abstraction layer when needed in order to allow proper state management. The implementation handles servers that are stateful and provide session meta information, but can also communicate with stateless servers that do not provide a session identifier and do not support SSE streams.

This implementation does not handle backwards compatibility with the "HTTP with SSE" transport. In order to communicate over the phased-out 2024-11-05 protocol, use HttpClientSseClientTransport or WebFluxSseClientTransport.

Author:
Dariusz Jędrzejczyk
See Also:
  • Method Details

    • protocolVersions

      public List<String> protocolVersions()
      Specified by:
      protocolVersions in interface io.modelcontextprotocol.spec.McpTransport
    • builder

      public static WebClientStreamableHttpTransport.Builder builder(org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder)
      Create a stateful builder for creating WebClientStreamableHttpTransport instances.
      Parameters:
      webClientBuilder - the WebClient.Builder to use
      Returns:
      a builder which will create an instance of WebClientStreamableHttpTransport once WebClientStreamableHttpTransport.Builder.build() is called
    • connect

      public reactor.core.publisher.Mono<Void> connect(Function<reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage>> handler)
      Specified by:
      connect in interface io.modelcontextprotocol.spec.McpClientTransport
    • setExceptionHandler

      public void setExceptionHandler(Consumer<Throwable> handler)
      Specified by:
      setExceptionHandler in interface io.modelcontextprotocol.spec.McpClientTransport
    • closeGracefully

      public reactor.core.publisher.Mono<Void> closeGracefully()
      Specified by:
      closeGracefully in interface io.modelcontextprotocol.spec.McpTransport
    • sendMessage

      public reactor.core.publisher.Mono<Void> sendMessage(io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage message)
      Specified by:
      sendMessage in interface io.modelcontextprotocol.spec.McpTransport
    • unmarshalFrom

      public <T> T unmarshalFrom(Object data, io.modelcontextprotocol.json.TypeRef<T> typeRef)
      Specified by:
      unmarshalFrom in interface io.modelcontextprotocol.spec.McpTransport