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. and base JDK8
serialization/deserialization of messages.限定符和类型 | 类和说明 |
---|---|
static class |
WebRxSseClientTransport.Builder
Builder for
WebRxSseClientTransport . |
限定符和类型 | 字段和说明 |
---|---|
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper
JSON object mapper for message serialization/deserialization
|
构造器和说明 |
---|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webBuilder)
Creates a new transport instance with default HTTP client and object mapper.
|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webBuilder,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Creates a new transport instance with custom HTTP client builder and object mapper.
|
WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webBuilder,
java.lang.String sseEndpoint,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Creates a new transport instance with custom HTTP client builder and object mapper.
|
限定符和类型 | 方法和说明 |
---|---|
static WebRxSseClientTransport.Builder |
builder(org.noear.solon.net.http.HttpUtilsBuilder webBuilder)
Creates a new builder for
WebRxSseClientTransport . |
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Gracefully closes the transport connection.
|
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 the SSE connection with the server and sets up message handling.
|
reactor.core.publisher.Mono<java.lang.Void> |
sendMessage(McpSchema.JSONRPCMessage message)
Sends a JSON-RPC message to the server.
|
<T> T |
unmarshalFrom(java.lang.Object data,
com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Unmarshals data to the specified type using the configured object mapper.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
protected com.fasterxml.jackson.databind.ObjectMapper objectMapper
public WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webBuilder)
webBuilder
- the HttpUtilsBuilder to use for creating the HttpUtils instancepublic WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webBuilder, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
webBuilder
- the HttpUtilsBuilder to use for creating the HttpUtils instanceobjectMapper
- the object mapper for JSON serialization/deserializationjava.lang.IllegalArgumentException
- if objectMapper or clientBuilder is nullpublic WebRxSseClientTransport(org.noear.solon.net.http.HttpUtilsBuilder webBuilder, java.lang.String sseEndpoint, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
webBuilder
- the HttpUtilsBuilder to use for creating the HttpUtils instancesseEndpoint
- the SSE endpoint pathobjectMapper
- the object mapper for JSON serialization/deserializationjava.lang.IllegalArgumentException
- if objectMapper or clientBuilder is nullpublic static WebRxSseClientTransport.Builder builder(org.noear.solon.net.http.HttpUtilsBuilder webBuilder)
WebRxSseClientTransport
.webBuilder
- the HttpUtilsBuilder to use for creating the HttpUtils instancepublic 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)
This method:
connect
在接口中 McpClientTransport
connect
在接口中 McpTransport
handler
- the function to process received JSON-RPC messagespublic reactor.core.publisher.Mono<java.lang.Void> sendMessage(McpSchema.JSONRPCMessage message)
This method waits for the message endpoint to be discovered before sending the message. The message is serialized to JSON and sent as an HTTP POST request.
sendMessage
在接口中 McpTransport
message
- the JSON-RPC message to sendMcpError
- if the message endpoint is not available or the wait times outpublic reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
Sets the closing flag and cancels any pending connection future. This prevents new messages from being sent and allows ongoing operations to complete.
closeGracefully
在接口中 McpTransport
public <T> T unmarshalFrom(java.lang.Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
unmarshalFrom
在接口中 McpTransport
T
- the target typedata
- the data to unmarshaltypeRef
- the type reference for the target type