Class HttpServletSseServerTransport
- All Implemented Interfaces:
McpTransport,ServerMcpTransport,jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
- Author:
- Christian Tzolov, Alexandros Pappas
- See Also:
-
ServerMcpTransportHttpServlet- Serialized Form
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.static final StringDeprecated.Default endpoint path for SSE connectionsstatic final StringDeprecated.Event type for endpoint informationstatic final StringDeprecated.static final StringDeprecated.Event type for regular messagesstatic final StringDeprecated.Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
ConstructorsConstructorDescriptionHttpServletSseServerTransport(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String messageEndpoint) Deprecated.Creates a new HttpServletSseServerTransport instance with the default SSE endpoint.HttpServletSseServerTransport(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String messageEndpoint, String sseEndpoint) Deprecated.Creates a new HttpServletSseServerTransport instance with a custom SSE endpoint. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Deprecated.Closes the transport.reactor.core.publisher.Mono<Void>Deprecated.Initiates a graceful shutdown of the transport.reactor.core.publisher.Mono<Void>connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>, reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler) Deprecated.Sets up the message handler for processing client requests.voiddestroy()Deprecated.Cleans up resources when the servlet is being destroyed.protected voiddoGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Deprecated.Handles GET requests to establish SSE connections.protected voiddoPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Deprecated.Handles POST requests for client messages.reactor.core.publisher.Mono<Void>sendMessage(McpSchema.JSONRPCMessage message) Deprecated.Broadcasts a message to all connected clients.<T> TunmarshalFrom(Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.Unmarshals data from one type to another using the object mapper.Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPatch, doPut, doTrace, getLastModified, init, isSensitiveHeader, service, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
UTF_8
Deprecated.- See Also:
-
APPLICATION_JSON
Deprecated.- See Also:
-
FAILED_TO_SEND_ERROR_RESPONSE
Deprecated.- See Also:
-
DEFAULT_SSE_ENDPOINT
Deprecated.Default endpoint path for SSE connections- See Also:
-
MESSAGE_EVENT_TYPE
Deprecated.Event type for regular messages- See Also:
-
ENDPOINT_EVENT_TYPE
Deprecated.Event type for endpoint information- See Also:
-
-
Constructor Details
-
HttpServletSseServerTransport
public HttpServletSseServerTransport(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String messageEndpoint, String sseEndpoint) Deprecated.Creates a new HttpServletSseServerTransport instance with a custom SSE endpoint.- Parameters:
objectMapper- The JSON object mapper to use for message serialization/deserializationmessageEndpoint- The endpoint path where clients will send their messagessseEndpoint- The endpoint path where clients will establish SSE connections
-
HttpServletSseServerTransport
public HttpServletSseServerTransport(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String messageEndpoint) Deprecated.Creates a new HttpServletSseServerTransport instance with the default SSE endpoint.- Parameters:
objectMapper- The JSON object mapper to use for message serialization/deserializationmessageEndpoint- The endpoint path where clients will send their messages
-
-
Method Details
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Deprecated.Handles GET requests to establish SSE connections.This method sets up a new SSE connection when a client connects to the SSE endpoint. It configures the response headers for SSE, creates a new session, and sends the initial endpoint information to the client.
- Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Parameters:
request- The HTTP servlet requestresponse- The HTTP servlet response- Throws:
jakarta.servlet.ServletException- If a servlet-specific error occursIOException- If an I/O error occurs
-
doPost
protected void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Deprecated.Handles POST requests for client messages.This method processes incoming messages from clients, routes them through the connect handler if configured, and sends back the appropriate response. It handles error cases and formats error responses according to the MCP specification.
- Overrides:
doPostin classjakarta.servlet.http.HttpServlet- Parameters:
request- The HTTP servlet requestresponse- The HTTP servlet response- Throws:
jakarta.servlet.ServletException- If a servlet-specific error occursIOException- If an I/O error occurs
-
connect
public reactor.core.publisher.Mono<Void> connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>, reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler) Deprecated.Sets up the message handler for processing client requests.- Specified by:
connectin interfaceMcpTransport- Parameters:
handler- The function to process incoming messages and produce responses- Returns:
- A Mono that completes when the handler is set up
-
sendMessage
Deprecated.Broadcasts a message to all connected clients.This method serializes the message and sends it to all active client sessions. If a client is disconnected, its session is removed.
- Specified by:
sendMessagein interfaceMcpTransport- Parameters:
message- The message to broadcast- Returns:
- A Mono that completes when the message has been sent to all clients
-
close
public void close()Deprecated.Closes the transport.This implementation delegates to the super class's close method.
- Specified by:
closein interfaceMcpTransport
-
unmarshalFrom
Deprecated.Unmarshals data from one type to another using the object mapper.- Specified by:
unmarshalFromin interfaceMcpTransport- Type Parameters:
T- The target type- Parameters:
data- The source datatypeRef- The type reference for the target type- Returns:
- The unmarshaled data
-
closeGracefully
Deprecated.Initiates a graceful shutdown of the transport.This method marks the transport as closing and closes all active client sessions. New connection attempts will be rejected during shutdown.
- Specified by:
closeGracefullyin interfaceMcpTransport- Returns:
- A Mono that completes when all sessions have been closed
-
destroy
public void destroy()Deprecated.Cleans up resources when the servlet is being destroyed.This method ensures a graceful shutdown by closing all client connections before calling the parent's destroy method.
- Specified by:
destroyin interfacejakarta.servlet.Servlet- Overrides:
destroyin classjakarta.servlet.GenericServlet
-
HttpServletSseServerTransportProvider.The transport handles two types of endpoints:
Features: