public class WebRxSseClientTransport extends java.lang.Object implements McpClientTransport
McpTransport that follows the MCP HTTP with SSE
transport specification.
This transport establishes a bidirectional communication channel where:
The message flow follows these steps:
HttpUtilsBuilder for HTTP communications and supports JSON
serialization/deserialization of messages.| 限定符和类型 | 类和说明 |
|---|---|
static class |
WebRxSseClientTransport.Builder
Builder for
WebRxSseClientTransport. |
| 限定符和类型 | 字段和说明 |
|---|---|
protected McpJsonMapper |
jsonMapper
ObjectMapper for serializing outbound messages and deserializing inbound messages.
|
protected reactor.core.publisher.Sinks.One<java.lang.String> |
messageEndpointSink
Sink for managing the message endpoint URI provided by the server.
|
| 构造器和说明 |
|---|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder,
McpJsonMapper jsonMapper)
Constructs a new SseClientTransport with the specified WebClient builder and
ObjectMapper.
|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder,
McpJsonMapper jsonMapper,
java.lang.String sseEndpoint)
Constructs a new SseClientTransport with the specified WebClient builder and
ObjectMapper.
|
| 限定符和类型 | 方法和说明 |
|---|---|
static WebRxSseClientTransport.Builder |
builder(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder)
Creates a new builder for
WebRxSseClientTransport. |
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Implements graceful shutdown of the transport.
|
reactor.core.publisher.Mono<java.lang.Void> |
connect(java.util.function.Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
Establishes a connection to the MCP server using Server-Sent Events (SSE).
|
protected reactor.core.publisher.Flux<org.noear.solon.net.http.textstream.ServerSentEvent> |
eventStream()
Initializes and starts the inbound SSE event processing.
|
java.util.List<java.lang.String> |
protocolVersions() |
reactor.core.publisher.Mono<java.lang.Void> |
sendMessage(McpSchema.JSONRPCMessage message)
Sends a JSON-RPC message to the server using the endpoint provided during
connection.
|
<T> T |
unmarshalFrom(java.lang.Object data,
TypeRef<T> typeRef)
Unmarshalls data from a generic Object into the specified type using the configured
ObjectMapper.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetExceptionHandlercloseprotected McpJsonMapper jsonMapper
protected final reactor.core.publisher.Sinks.One<java.lang.String> messageEndpointSink
public WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder,
McpJsonMapper jsonMapper)
webClientBuilder - the HttpUtilsBuilder to use for creating the WebClient
instancejsonMapper - the ObjectMapper to use for JSON processingjava.lang.IllegalArgumentException - if either parameter is nullpublic WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder,
McpJsonMapper jsonMapper,
java.lang.String sseEndpoint)
webClientBuilder - the HttpUtilsBuilder to use for creating the WebClient
instancejsonMapper - the ObjectMapper to use for JSON processingsseEndpoint - the SSE endpoint URI to use for establishing the connectionjava.lang.IllegalArgumentException - if either parameter is nullpublic java.util.List<java.lang.String> protocolVersions()
protocolVersions 在接口中 McpTransportpublic reactor.core.publisher.Mono<java.lang.Void> connect(java.util.function.Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
The connection process follows these steps:
The connection is considered established only after receiving the endpoint event from the server.
connect 在接口中 McpClientTransporthandler - a function that processes incoming JSON-RPC messages and returns
responsespublic reactor.core.publisher.Mono<java.lang.Void> sendMessage(McpSchema.JSONRPCMessage message)
Messages are sent via HTTP POST requests to the server-provided endpoint URI. The message is serialized to JSON before transmission. If the transport is in the process of closing, the message send operation is skipped gracefully.
sendMessage 在接口中 McpTransportmessage - the JSON-RPC message to sendjava.lang.RuntimeException - if message serialization failsprotected reactor.core.publisher.Flux<org.noear.solon.net.http.textstream.ServerSentEvent> eventStream()
public reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
closeGracefully 在接口中 McpTransportpublic <T> T unmarshalFrom(java.lang.Object data,
TypeRef<T> typeRef)
This method is particularly useful when working with JSON-RPC parameters or result objects that need to be converted to specific Java types. It leverages Jackson's type conversion capabilities to handle complex object structures.
unmarshalFrom 在接口中 McpTransportT - the target type to convert the data intodata - the source object to converttypeRef - the TypeRef describing the target typejava.lang.IllegalArgumentException - if the conversion cannot be performedpublic static WebRxSseClientTransport.Builder builder(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder)
WebRxSseClientTransport.webClientBuilder - the HttpUtilsBuilder to use for creating the WebClient
instance