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:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder(org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder) Create a stateful builder for creatingWebClientStreamableHttpTransportinstances.reactor.core.publisher.Mono<Void>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) reactor.core.publisher.Mono<Void>sendMessage(io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage message) voidsetExceptionHandler(Consumer<Throwable> handler) <T> TunmarshalFrom(Object data, io.modelcontextprotocol.json.TypeRef<T> typeRef) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.modelcontextprotocol.spec.McpTransport
close
-
Method Details
-
protocolVersions
- Specified by:
protocolVersionsin interfaceio.modelcontextprotocol.spec.McpTransport
-
builder
public static WebClientStreamableHttpTransport.Builder builder(org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder) Create a stateful builder for creatingWebClientStreamableHttpTransportinstances.- Parameters:
webClientBuilder- theWebClient.Builderto use- Returns:
- a builder which will create an instance of
WebClientStreamableHttpTransportonceWebClientStreamableHttpTransport.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:
connectin interfaceio.modelcontextprotocol.spec.McpClientTransport
-
setExceptionHandler
- Specified by:
setExceptionHandlerin interfaceio.modelcontextprotocol.spec.McpClientTransport
-
closeGracefully
- Specified by:
closeGracefullyin interfaceio.modelcontextprotocol.spec.McpTransport
-
sendMessage
public reactor.core.publisher.Mono<Void> sendMessage(io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage message) - Specified by:
sendMessagein interfaceio.modelcontextprotocol.spec.McpTransport
-
unmarshalFrom
- Specified by:
unmarshalFromin interfaceio.modelcontextprotocol.spec.McpTransport
-