Class StdioServerTransportProvider

java.lang.Object
io.modelcontextprotocol.server.transport.StdioServerTransportProvider
All Implemented Interfaces:
McpServerTransportProvider, McpServerTransportProviderBase

public class StdioServerTransportProvider extends Object implements McpServerTransportProvider
Implementation of the MCP Stdio transport provider for servers that communicates using standard input/output streams. Messages are exchanged as newline-delimited JSON-RPC messages over stdin/stdout, with errors and debug information sent to stderr.
Author:
Christian Tzolov
  • Constructor Details

    • StdioServerTransportProvider

      public StdioServerTransportProvider(McpJsonMapper jsonMapper)
      Creates a new StdioServerTransportProvider with the specified ObjectMapper and System streams.
      Parameters:
      jsonMapper - The JsonMapper to use for JSON serialization/deserialization
    • StdioServerTransportProvider

      public StdioServerTransportProvider(McpJsonMapper jsonMapper, InputStream inputStream, OutputStream outputStream)
      Creates a new StdioServerTransportProvider with the specified ObjectMapper and streams.
      Parameters:
      jsonMapper - The JsonMapper to use for JSON serialization/deserialization
      inputStream - The input stream to read from
      outputStream - The output stream to write to
  • Method Details

    • setSessionFactory

      public void setSessionFactory(McpServerSession.Factory sessionFactory)
      Description copied from interface: McpServerTransportProvider
      Sets the session factory that will be used to create sessions for new clients. An implementation of the MCP server MUST call this method before any MCP interactions take place.
      Specified by:
      setSessionFactory in interface McpServerTransportProvider
      Parameters:
      sessionFactory - the session factory to be used for initiating client sessions
    • notifyClients

      public reactor.core.publisher.Mono<Void> notifyClients(String method, Object params)
      Description copied from interface: McpServerTransportProviderBase
      Sends a notification to all connected clients.
      Specified by:
      notifyClients in interface McpServerTransportProviderBase
      Parameters:
      method - the name of the notification method to be called on the clients
      params - parameters to be sent with the notification
      Returns:
      a Mono that completes when the notification has been broadcast
      See Also:
    • notifyClient

      public reactor.core.publisher.Mono<Void> notifyClient(String sessionId, String method, Object params)
      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
    • closeGracefully

      public reactor.core.publisher.Mono<Void> closeGracefully()
      Description copied from interface: McpServerTransportProviderBase
      Gracefully closes all the transports with connected clients and releases any associated resources asynchronously.
      Specified by:
      closeGracefully in interface McpServerTransportProviderBase
      Returns:
      a reactor.core.publisher.Mono<Void> that completes when the connections have been closed.