Class WebMvcSseServerTransportProvider

java.lang.Object
org.springframework.ai.mcp.server.webmvc.transport.WebMvcSseServerTransportProvider
All Implemented Interfaces:
io.modelcontextprotocol.spec.McpServerTransportProvider, io.modelcontextprotocol.spec.McpServerTransportProviderBase

@Deprecated(since="2.0.0", forRemoval=true) public final class WebMvcSseServerTransportProvider extends Object implements io.modelcontextprotocol.spec.McpServerTransportProvider
Deprecated, for removal: This API element is subject to removal in a future version.
The SSE transport has been deprecated in the 2025-03-26 version of the spec, and should not be used anymore. We keep it for backwards compatibility.
Server-side implementation of the Model Context Protocol (MCP) transport layer using HTTP with Server-Sent Events (SSE) through Spring WebMVC. This implementation provides a bridge between synchronous WebMVC operations and reactive programming patterns to maintain compatibility with the reactive transport interface.

Key features:

  • Implements bidirectional communication using HTTP POST for client-to-server messages and SSE for server-to-client messages
  • Manages client sessions with unique IDs for reliable message delivery
  • Supports graceful shutdown with proper session cleanup
  • Provides JSON-RPC message handling through configured endpoints
  • Includes built-in error handling and logging

The transport operates on two main endpoints:

  • /sse - The SSE endpoint where clients establish their event stream connection
  • A configurable message endpoint where clients send their JSON-RPC messages via HTTP POST

This implementation uses ConcurrentHashMap to safely manage multiple client sessions in a thread-safe manner. Each client session is assigned a unique ID and maintains its own SSE connection.

Author:
Christian Tzolov, Alexandros Pappas
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Deprecated, for removal: This API element is subject to removal in a future version.
    Builder for creating instances of WebMvcSseServerTransportProvider.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Default SSE endpoint path as specified by the MCP transport specification.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Event type for sending the message endpoint URI to clients.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Event type for JSON-RPC messages sent through the SSE connection.
    static final String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Creates a new Builder instance for configuring and creating instances of WebMvcSseServerTransportProvider.
    reactor.core.publisher.Mono<Void>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Initiates a graceful shutdown of the transport.
    org.springframework.web.servlet.function.RouterFunction<org.springframework.web.servlet.function.ServerResponse>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns the RouterFunction that defines the HTTP endpoints for this transport.
    reactor.core.publisher.Mono<Void>
    notifyClient(String sessionId, String method, Object params)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    reactor.core.publisher.Mono<Void>
    notifyClients(String method, Object params)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Broadcasts a notification to all connected clients through their SSE connections.
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    setSessionFactory(io.modelcontextprotocol.spec.McpServerSession.Factory sessionFactory)
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    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

    • MESSAGE_EVENT_TYPE

      public static final String MESSAGE_EVENT_TYPE
      Deprecated, for removal: This API element is subject to removal in a future version.
      Event type for JSON-RPC messages sent through the SSE connection.
      See Also:
    • ENDPOINT_EVENT_TYPE

      public static final String ENDPOINT_EVENT_TYPE
      Deprecated, for removal: This API element is subject to removal in a future version.
      Event type for sending the message endpoint URI to clients.
      See Also:
    • SESSION_ID

      public static final String SESSION_ID
      Deprecated, for removal: This API element is subject to removal in a future version.
      See Also:
    • DEFAULT_SSE_ENDPOINT

      public static final String DEFAULT_SSE_ENDPOINT
      Deprecated, for removal: This API element is subject to removal in a future version.
      Default SSE endpoint path as specified by the MCP transport specification.
      See Also:
    • DEFAULT_MESSAGE_ENDPOINT

      public static final String DEFAULT_MESSAGE_ENDPOINT
      Deprecated, for removal: This API element is subject to removal in a future version.
      See Also:
  • Method Details

    • protocolVersions

      public List<String> protocolVersions()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      protocolVersions in interface io.modelcontextprotocol.spec.McpServerTransportProviderBase
    • setSessionFactory

      public void setSessionFactory(io.modelcontextprotocol.spec.McpServerSession.Factory sessionFactory)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      setSessionFactory in interface io.modelcontextprotocol.spec.McpServerTransportProvider
    • notifyClients

      public reactor.core.publisher.Mono<Void> notifyClients(String method, Object params)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Broadcasts a notification to all connected clients through their SSE connections. The message is serialized to JSON and sent as an SSE event with type "message". If any errors occur during sending to a particular client, they are logged but don't prevent sending to other clients.
      Specified by:
      notifyClients in interface io.modelcontextprotocol.spec.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
    • notifyClient

      public reactor.core.publisher.Mono<Void> notifyClient(String sessionId, String method, Object params)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      notifyClient in interface io.modelcontextprotocol.spec.McpServerTransportProviderBase
    • closeGracefully

      public reactor.core.publisher.Mono<Void> closeGracefully()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Initiates a graceful shutdown of the transport. This method:
      • Sets the closing flag to prevent new connections
      • Closes all active SSE connections
      • Removes all session records
      Specified by:
      closeGracefully in interface io.modelcontextprotocol.spec.McpServerTransportProviderBase
      Returns:
      A Mono that completes when all cleanup operations are finished
    • getRouterFunction

      public org.springframework.web.servlet.function.RouterFunction<org.springframework.web.servlet.function.ServerResponse> getRouterFunction()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the RouterFunction that defines the HTTP endpoints for this transport. The router function handles two endpoints:
      • GET /sse - For establishing SSE connections
      • POST [messageEndpoint] - For receiving JSON-RPC messages from clients
      Returns:
      The configured RouterFunction for handling HTTP requests
    • builder

      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a new Builder instance for configuring and creating instances of WebMvcSseServerTransportProvider.
      Returns:
      A new Builder instance