Class HttpServletSseServerTransportProvider

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
io.modelcontextprotocol.server.transport.HttpServletSseServerTransportProvider
All Implemented Interfaces:
McpServerTransportProvider, McpServerTransportProviderBase, jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

@Deprecated @WebServlet(asyncSupported=true) public class HttpServletSseServerTransportProvider extends jakarta.servlet.http.HttpServlet implements McpServerTransportProvider
Deprecated.
This SSE transport is deprecated. Use Streamable HTTP instead, with HttpServletStreamableServerTransportProvider or HttpServletStatelessServerTransport.
A Servlet-based implementation of the MCP HTTP with Server-Sent Events (SSE) transport specification. This implementation provides similar functionality to WebFluxSseServerTransportProvider but uses the traditional Servlet API instead of WebFlux.

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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Deprecated.
    Builder for creating instances of HttpServletSseServerTransportProvider.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated.
     
    static final String
    Deprecated.
     
    static final String
    Deprecated.
    Default endpoint path for SSE connections
    static final String
    Deprecated.
    Event type for endpoint information
    static final String
    Deprecated.
     
    static final String
    Deprecated.
    Event type for regular messages
    static final String
    Deprecated.
     
    static final String
    Deprecated.
     

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    void
    Deprecated.
    Cleans up resources when the servlet is being destroyed.
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Deprecated.
    Handles GET requests to establish SSE connections.
    protected void
    doPost(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.
    void
    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, service

    Methods inherited from class jakarta.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.modelcontextprotocol.spec.McpServerTransportProviderBase

    close
  • Field Details

  • Method Details

    • protocolVersions

      public List<String> protocolVersions()
      Deprecated.
      Description copied from interface: McpServerTransportProviderBase
      Returns the protocol version supported by this transport provider.
      Specified by:
      protocolVersions in interface McpServerTransportProviderBase
      Returns:
      the protocol version as a string
    • setSessionFactory

      public void setSessionFactory(McpServerSession.Factory sessionFactory)
      Deprecated.
      Sets the session factory for creating new sessions.
      Specified by:
      setSessionFactory in interface McpServerTransportProvider
      Parameters:
      sessionFactory - The session factory to use
    • notifyClients

      public reactor.core.publisher.Mono<Void> notifyClients(String method, Object params)
      Deprecated.
      Broadcasts a notification to all connected clients.
      Specified by:
      notifyClients in interface McpServerTransportProviderBase
      Parameters:
      method - The method name for the notification
      params - 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: McpServerTransportProviderBase
      Sends 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:
      notifyClient in interface McpServerTransportProviderBase
      Parameters:
      sessionId - the id of the session to notify
      method - the name of the notification method to be called on the client
      params - 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:
      doGet in class jakarta.servlet.http.HttpServlet
      Parameters:
      request - The HTTP servlet request
      response - The HTTP servlet response
      Throws:
      jakarta.servlet.ServletException - If a servlet-specific error occurs
      IOException - 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:
      doPost in class jakarta.servlet.http.HttpServlet
      Parameters:
      request - The HTTP servlet request
      response - The HTTP servlet response
      Throws:
      jakarta.servlet.ServletException - If a servlet-specific error occurs
      IOException - If an I/O error occurs
    • closeGracefully

      public reactor.core.publisher.Mono<Void> 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:
      closeGracefully in interface McpServerTransportProviderBase
      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:
      destroy in interface jakarta.servlet.Servlet
      Overrides:
      destroy in class jakarta.servlet.GenericServlet
    • builder

      Deprecated.
      Creates a new Builder instance for configuring and creating instances of HttpServletSseServerTransportProvider.
      Returns:
      A new Builder instance