public class WebRxSseServerTransportProvider extends java.lang.Object implements McpServerTransportProvider
Key features:
McpServerTransportProvider
interface that allows managing
McpServerSession
instances and enabling their communication with the
McpServerTransport
abstraction.The transport sets up two main endpoints:
This implementation is thread-safe and can handle multiple concurrent client
connections. It uses ConcurrentHashMap
for session management and Project
Reactor's non-blocking APIs for message processing and delivery. and base JDK8
McpServerTransport
,
SseEvent
限定符和类型 | 类和说明 |
---|---|
static class |
WebRxSseServerTransportProvider.Builder
Builder for creating instances of
WebRxSseServerTransportProvider . |
class |
WebRxSseServerTransportProvider.WebRxMcpSessionTransport |
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
DEFAULT_SSE_ENDPOINT
Default SSE endpoint path as specified by the MCP transport specification.
|
static java.lang.String |
ENDPOINT_EVENT_TYPE
Event type for sending the message endpoint URI to clients.
|
static java.lang.String |
MESSAGE_EVENT_TYPE
Event type for JSON-RPC messages sent through the SSE connection.
|
构造器和说明 |
---|
WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
java.lang.String messageEndpoint)
Constructs a new WebFlux SSE server transport provider instance with the default
SSE endpoint.
|
WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
java.lang.String messageEndpoint,
java.lang.String sseEndpoint)
Constructs a new WebFlux SSE server transport provider instance.
|
限定符和类型 | 方法和说明 |
---|---|
static WebRxSseServerTransportProvider.Builder |
builder() |
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Initiates a graceful shutdown of all the sessions.
|
java.lang.String |
getMessageEndpoint() |
java.lang.String |
getSseEndpoint() |
void |
handleMessage(org.noear.solon.core.handle.Context ctx)
Handles incoming JSON-RPC messages from clients.
|
void |
handleSseConnection(org.noear.solon.core.handle.Context ctx)
Handles new SSE connection requests from clients.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyClients(java.lang.String method,
java.util.Map<java.lang.String,java.lang.Object> params)
Broadcasts a JSON-RPC message to all connected clients through their SSE
connections.
|
void |
sendHeartbeat() |
void |
setSessionFactory(McpServerSession.Factory sessionFactory)
Sets the session factory that will be used to create sessions for new clients.
|
void |
toHttpHandler(org.noear.solon.SolonApp app) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public static final java.lang.String MESSAGE_EVENT_TYPE
public static final java.lang.String ENDPOINT_EVENT_TYPE
public static final java.lang.String DEFAULT_SSE_ENDPOINT
public WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, java.lang.String messageEndpoint, java.lang.String sseEndpoint)
objectMapper
- The ObjectMapper to use for JSON serialization/deserialization
of MCP messages. Must not be null.messageEndpoint
- The endpoint URI where clients should send their JSON-RPC
messages. This endpoint will be communicated to clients during SSE connection
setup. Must not be null.java.lang.IllegalArgumentException
- if either parameter is nullpublic WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, java.lang.String messageEndpoint)
objectMapper
- The ObjectMapper to use for JSON serialization/deserialization
of MCP messages. Must not be null.messageEndpoint
- The endpoint URI where clients should send their JSON-RPC
messages. This endpoint will be communicated to clients during SSE connection
setup. Must not be null.java.lang.IllegalArgumentException
- if either parameter is nullpublic void sendHeartbeat()
public void toHttpHandler(org.noear.solon.SolonApp app)
public java.lang.String getSseEndpoint()
public java.lang.String getMessageEndpoint()
public void setSessionFactory(McpServerSession.Factory sessionFactory)
McpServerTransportProvider
setSessionFactory
在接口中 McpServerTransportProvider
sessionFactory
- the session factory to be used for initiating client sessionspublic reactor.core.publisher.Mono<java.lang.Void> notifyClients(java.lang.String method, java.util.Map<java.lang.String,java.lang.Object> params)
The method:
notifyClients
在接口中 McpServerTransportProvider
method
- The JSON-RPC method to send to clientsparams
- The method parameters to send to clientsMcpSession.sendNotification(String, Map)
public reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
The shutdown process:
closeGracefully
在接口中 McpServerTransportProvider
public void handleSseConnection(org.noear.solon.core.handle.Context ctx) throws java.lang.Throwable
ctx
- The incoming server contextjava.lang.Throwable
public void handleMessage(org.noear.solon.core.handle.Context ctx) throws java.lang.Throwable
The handler:
ctx
- The incoming server request context containing the JSON-RPC messagejava.lang.Throwable
public static WebRxSseServerTransportProvider.Builder builder()