public class WebRxStreamableHttpTransport extends Object implements McpClientTransport
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
WebRxSseClientTransport.
| Modifier and Type | Class and Description |
|---|---|
static class |
WebRxStreamableHttpTransport.Builder
Builder for
WebRxStreamableHttpTransport. |
| Modifier and Type | Method and Description |
|---|---|
static WebRxStreamableHttpTransport.Builder |
builder(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder)
Create a stateful builder for creating
WebRxStreamableHttpTransport
instances. |
reactor.core.publisher.Mono<Void> |
closeGracefully()
Closes the transport connection and releases any associated resources
asynchronously.
|
reactor.core.publisher.Mono<Void> |
connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
Used to register the incoming messages' handler and potentially (eagerly) connect
to the server.
|
List<String> |
protocolVersions() |
reactor.core.publisher.Mono<Void> |
sendMessage(McpSchema.JSONRPCMessage message)
Sends a message to the peer asynchronously.
|
void |
setExceptionHandler(Consumer<Throwable> handler)
Sets the exception handler for exceptions raised on the transport layer.
|
<T> T |
unmarshalFrom(Object data,
com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Unmarshals the given data into an object of the specified type.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclosepublic List<String> protocolVersions()
protocolVersions in interface McpTransportpublic static WebRxStreamableHttpTransport.Builder builder(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder)
WebRxStreamableHttpTransport
instances.webClientBuilder - the HttpUtilsBuilder to useWebRxStreamableHttpTransport once WebRxStreamableHttpTransport.Builder.build() is calledpublic reactor.core.publisher.Mono<Void> connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
McpClientTransportconnect in interface McpClientTransporthandler - a transformer for incoming messagesMono that terminates upon successful client setup. It can mean
establishing a connection (which can be later disposed) but it doesn't have to,
depending on the transport type. The successful termination of the returned
Mono simply means the client can now be used. An error can be retried
according to the application requirements.public void setExceptionHandler(Consumer<Throwable> handler)
McpClientTransportsetExceptionHandler in interface McpClientTransporthandler - Allows reacting to transport level exceptions by the higher layerspublic reactor.core.publisher.Mono<Void> closeGracefully()
McpTransportcloseGracefully in interface McpTransportMono that completes when the connection has been closed.public reactor.core.publisher.Mono<Void> sendMessage(McpSchema.JSONRPCMessage message)
McpTransportThis method handles the transmission of messages to the server in an asynchronous manner. Messages are sent in JSON-RPC format as specified by the MCP protocol.
sendMessage in interface McpTransportmessage - the McpSchema.JSONRPCMessage to be sent to the serverMono that completes when the message has been sentpublic <T> T unmarshalFrom(Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
McpTransportunmarshalFrom in interface McpTransportT - the type of the object to unmarshaldata - the data to unmarshaltypeRef - the type reference for the object to unmarshalCopyright © 2025. All rights reserved.