Class StdioServerTransportProvider
java.lang.Object
io.modelcontextprotocol.server.transport.StdioServerTransportProvider
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCreates a new StdioServerTransportProvider with a default ObjectMapper and System streams.StdioServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a new StdioServerTransportProvider with the specified ObjectMapper and System streams.StdioServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, InputStream inputStream, OutputStream outputStream) Creates a new StdioServerTransportProvider with the specified ObjectMapper and streams. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>Gracefully closes all the transports with connected clients and releases any associated resources asynchronously.reactor.core.publisher.Mono<Void>notifyClients(String method, Object params) Sends a notification to all connected clients.voidsetSessionFactory(McpServerSession.Factory sessionFactory) Sets the session factory that will be used to create sessions for new clients.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.modelcontextprotocol.spec.McpServerTransportProvider
close
-
Constructor Details
-
StdioServerTransportProvider
public StdioServerTransportProvider()Creates a new StdioServerTransportProvider with a default ObjectMapper and System streams. -
StdioServerTransportProvider
public StdioServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a new StdioServerTransportProvider with the specified ObjectMapper and System streams.- Parameters:
objectMapper- The ObjectMapper to use for JSON serialization/deserialization
-
StdioServerTransportProvider
public StdioServerTransportProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, InputStream inputStream, OutputStream outputStream) Creates a new StdioServerTransportProvider with the specified ObjectMapper and streams.- Parameters:
objectMapper- The ObjectMapper to use for JSON serialization/deserializationinputStream- The input stream to read fromoutputStream- The output stream to write to
-
-
Method Details
-
setSessionFactory
Description copied from interface:McpServerTransportProviderSets 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:
setSessionFactoryin interfaceMcpServerTransportProvider- Parameters:
sessionFactory- the session factory to be used for initiating client sessions
-
notifyClients
Description copied from interface:McpServerTransportProviderSends a notification to all connected clients.- Specified by:
notifyClientsin interfaceMcpServerTransportProvider- Parameters:
method- the name of the notification method to be called on the clientsparams- parameters to be sent with the notification- Returns:
- a Mono that completes when the notification has been broadcast
- See Also:
-
closeGracefully
Description copied from interface:McpServerTransportProviderGracefully closes all the transports with connected clients and releases any associated resources asynchronously.- Specified by:
closeGracefullyin interfaceMcpServerTransportProvider- Returns:
- a
reactor.core.publisher.Mono<Void>that completes when the connections have been closed.
-