public class WebRxSseServerTransportProvider extends 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| Modifier and Type | Class and Description |
|---|---|
static class |
WebRxSseServerTransportProvider.Builder
Builder for creating instances of
WebRxSseServerTransportProvider. |
class |
WebRxSseServerTransportProvider.WebRxMcpSessionTransport |
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_SSE_ENDPOINT
Default SSE endpoint path as specified by the MCP transport specification.
|
static String |
ENDPOINT_EVENT_TYPE
Event type for sending the message endpoint URI to clients.
|
static String |
MESSAGE_EVENT_TYPE
Event type for JSON-RPC messages sent through the SSE connection.
|
| Constructor and Description |
|---|
WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
String messageEndpoint)
Constructs a new WebFlux SSE server transport provider instance with the default
SSE endpoint.
|
WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
String messageEndpoint,
String sseEndpoint)
Constructs a new WebFlux SSE server transport provider instance.
|
| Modifier and Type | Method and Description |
|---|---|
static WebRxSseServerTransportProvider.Builder |
builder() |
reactor.core.publisher.Mono<Void> |
closeGracefully()
Initiates a graceful shutdown of all the sessions.
|
String |
getMessageEndpoint() |
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<Void> |
notifyClients(String method,
Map<String,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, waitclosepublic static final String MESSAGE_EVENT_TYPE
public static final String ENDPOINT_EVENT_TYPE
public static final String DEFAULT_SSE_ENDPOINT
public WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
String messageEndpoint,
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.IllegalArgumentException - if either parameter is nullpublic WebRxSseServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
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.IllegalArgumentException - if either parameter is nullpublic void sendHeartbeat()
public void toHttpHandler(org.noear.solon.SolonApp app)
public String getSseEndpoint()
public String getMessageEndpoint()
public void setSessionFactory(McpServerSession.Factory sessionFactory)
McpServerTransportProvidersetSessionFactory in interface McpServerTransportProvidersessionFactory - the session factory to be used for initiating client sessionspublic reactor.core.publisher.Mono<Void> notifyClients(String method, Map<String,Object> params)
The method:
notifyClients in interface McpServerTransportProvidermethod - The JSON-RPC method to send to clientsparams - The method parameters to send to clientsMcpSession.sendNotification(String, Map)public reactor.core.publisher.Mono<Void> closeGracefully()
The shutdown process:
closeGracefully in interface McpServerTransportProviderpublic void handleSseConnection(org.noear.solon.core.handle.Context ctx)
throws Throwable
ctx - The incoming server contextThrowablepublic void handleMessage(org.noear.solon.core.handle.Context ctx)
throws Throwable
The handler:
ctx - The incoming server request context containing the JSON-RPC messageThrowablepublic static WebRxSseServerTransportProvider.Builder builder()
Copyright © 2025. All rights reserved.