Class WebMvcStreamableServerTransportProvider

java.lang.Object
io.modelcontextprotocol.server.transport.WebMvcStreamableServerTransportProvider
All Implemented Interfaces:
io.modelcontextprotocol.spec.McpServerTransportProviderBase, io.modelcontextprotocol.spec.McpStreamableServerTransportProvider

public class WebMvcStreamableServerTransportProvider extends Object implements io.modelcontextprotocol.spec.McpStreamableServerTransportProvider
Server-side implementation of the Model Context Protocol (MCP) streamable 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.

This is the non-reactive version of io.modelcontextprotocol.server.transport.WebFluxStreamableServerTransportProvider

Author:
Christian Tzolov, Dariusz Jędrzejczyk
See Also:
  • McpStreamableServerTransportProvider
  • RouterFunction
  • Field Details

    • MESSAGE_EVENT_TYPE

      public static final String MESSAGE_EVENT_TYPE
      Event type for JSON-RPC messages sent through the SSE connection.
      See Also:
    • ENDPOINT_EVENT_TYPE

      public static final String ENDPOINT_EVENT_TYPE
      Event type for sending the message endpoint URI to clients.
      See Also:
    • DEFAULT_BASE_URL

      public static final String DEFAULT_BASE_URL
      Default base URL for the message endpoint.
      See Also:
  • Method Details

    • protocolVersions

      public List<String> protocolVersions()
      Specified by:
      protocolVersions in interface io.modelcontextprotocol.spec.McpServerTransportProviderBase
    • setSessionFactory

      public void setSessionFactory(io.modelcontextprotocol.spec.McpStreamableServerSession.Factory sessionFactory)
      Specified by:
      setSessionFactory in interface io.modelcontextprotocol.spec.McpStreamableServerTransportProvider
    • notifyClients

      public reactor.core.publisher.Mono<Void> notifyClients(String method, Object params)
      Broadcasts a notification to all connected clients through their SSE connections. 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
      Specified by:
      notifyClients in interface io.modelcontextprotocol.spec.McpStreamableServerTransportProvider
      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
    • closeGracefully

      public reactor.core.publisher.Mono<Void> closeGracefully()
      Initiates a graceful shutdown of the transport.
      Specified by:
      closeGracefully in interface io.modelcontextprotocol.spec.McpServerTransportProviderBase
      Specified by:
      closeGracefully in interface io.modelcontextprotocol.spec.McpStreamableServerTransportProvider
      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()
      Returns the RouterFunction that defines the HTTP endpoints for this transport. The router function handles three endpoints:
      • GET [mcpEndpoint] - For establishing SSE connections and message replay
      • POST [mcpEndpoint] - For receiving JSON-RPC messages from clients
      • DELETE [mcpEndpoint] - For session deletion (if enabled)
      Returns:
      The configured RouterFunction for handling HTTP requests
    • builder