Class HttpServletSseServerTransportProvider
- All Implemented Interfaces:
McpServerTransportProvider,McpServerTransportProviderBase,jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
The transport handles two types of endpoints:
- SSE endpoint (/sse) - Establishes a long-lived connection for server-to-client events
- Message endpoint (configurable) - Handles client-to-server message requests
Features:
- Asynchronous message handling using Servlet 6.0 async support
- Session management for multiple client connections
- Graceful shutdown support
- Error handling and response formatting
- Author:
- Christian Tzolov, Alexandros Pappas
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated.Builder for creating instances of HttpServletSseServerTransportProvider. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.static 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.static final StringDeprecated.Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Deprecated.Creates a new Builder instance for configuring and creating instances of HttpServletSseServerTransportProvider.reactor.core.publisher.Mono<Void>Deprecated.Initiates a graceful shutdown of the transport.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>notifyClient(String sessionId, String method, Object params) Deprecated.Sends a notification to a specific client session.reactor.core.publisher.Mono<Void>notifyClients(String method, Object params) Deprecated.Broadcasts a notification to all connected clients.Deprecated.Returns the protocol version supported by this transport provider.voidsetSessionFactory(McpServerSession.Factory sessionFactory) Deprecated.Sets the session factory for creating new sessions.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, logMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.modelcontextprotocol.spec.McpServerTransportProviderBase
close
-
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:
-
SESSION_ID
Deprecated.- See Also:
-
DEFAULT_BASE_URL
Deprecated.- See Also:
-
-
Method Details
-
protocolVersions
Deprecated.Description copied from interface:McpServerTransportProviderBaseReturns the protocol version supported by this transport provider.- Specified by:
protocolVersionsin interfaceMcpServerTransportProviderBase- Returns:
- the protocol version as a string
-
setSessionFactory
Deprecated.Sets the session factory for creating new sessions.- Specified by:
setSessionFactoryin interfaceMcpServerTransportProvider- Parameters:
sessionFactory- The session factory to use
-
notifyClients
Deprecated.Broadcasts a notification to all connected clients.- Specified by:
notifyClientsin interfaceMcpServerTransportProviderBase- Parameters:
method- The method name for the notificationparams- The parameters for the notification- Returns:
- A Mono that completes when the broadcast attempt is finished
- See Also:
-
notifyClient
public reactor.core.publisher.Mono<Void> notifyClient(String sessionId, String method, Object params) Deprecated.Description copied from interface:McpServerTransportProviderBaseSends a notification to a specific client session. Transport providers that support resource subscriptions must override this method to enable per-session notifications. The default implementation returns an error indicating that this operation is not supported.- Specified by:
notifyClientin interfaceMcpServerTransportProviderBase- Parameters:
sessionId- the id of the session to notifymethod- the name of the notification method to be called on the clientparams- parameters to be sent with the notification- Returns:
- a Mono that completes when the notification has been sent, or empty if the session is not found
-
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 session handler, 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
-
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 interfaceMcpServerTransportProviderBase- 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
-
builder
Deprecated.Creates a new Builder instance for configuring and creating instances of HttpServletSseServerTransportProvider.- Returns:
- A new Builder instance
-
HttpServletStreamableServerTransportProviderorHttpServletStatelessServerTransport.