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 reactor.core.publisher.Sinks.One<java.lang.String> |
messageEndpointSink
Sink for managing the message endpoint URI provided by the server.
|
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper
ObjectMapper for serializing outbound messages and deserializing inbound messages.
|
构造器和说明 |
---|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder)
Constructs a new SseClientTransport with the specified WebClient builder.
|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Constructs a new SseClientTransport with the specified WebClient builder and
ObjectMapper.
|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder,
com.fasterxml.jackson.databind.ObjectMapper objectMapper,
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,
com.fasterxml.jackson.core.type.TypeReference<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, wait
setExceptionHandler
close
protected com.fasterxml.jackson.databind.ObjectMapper objectMapper
protected final reactor.core.publisher.Sinks.One<java.lang.String> messageEndpointSink
public WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder)
webClientBuilder
- the WebClient.Builder to use for creating the WebClient
instancejava.lang.IllegalArgumentException
- if webClientBuilder is nullpublic WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
webClientBuilder
- the WebClient.Builder to use for creating the WebClient
instanceobjectMapper
- the ObjectMapper to use for JSON processingjava.lang.IllegalArgumentException
- if either parameter is nullpublic WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webClientBuilder, com.fasterxml.jackson.databind.ObjectMapper objectMapper, java.lang.String sseEndpoint)
webClientBuilder
- the WebClient.Builder to use for creating the WebClient
instanceobjectMapper
- 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
在接口中 McpTransport
public 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
在接口中 McpClientTransport
handler
- a function that processes incoming JSON-RPC messages and returns
responsesMcpError
- if there's an error processing SSE events or if an unrecognized
event type is receivedpublic 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
在接口中 McpTransport
message
- 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
在接口中 McpTransport
public <T> T unmarshalFrom(java.lang.Object data, com.fasterxml.jackson.core.type.TypeReference<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
在接口中 McpTransport
T
- the target type to convert the data intodata
- the source object to converttypeRef
- the TypeReference 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 WebClient.Builder to use for creating the WebClient
instance