public class StdioClientTransport extends Object implements McpClientTransport
| Constructor and Description |
|---|
StdioClientTransport(ServerParameters params)
Creates a new StdioClientTransport with the specified parameters and default
ObjectMapper.
|
StdioClientTransport(ServerParameters params,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Creates a new StdioClientTransport with the specified parameters and ObjectMapper.
|
| Modifier and Type | Method and Description |
|---|---|
void |
awaitForExit()
Waits for the server process to exit.
|
reactor.core.publisher.Mono<Void> |
closeGracefully()
Gracefully closes the transport by destroying the process and disposing of the
schedulers.
|
reactor.core.publisher.Mono<Void> |
connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
Starts the server process and initializes the message processing streams.
|
reactor.core.publisher.Sinks.Many<String> |
getErrorSink() |
protected ProcessBuilder |
getProcessBuilder()
Creates and returns a new ProcessBuilder instance.
|
protected void |
handleOutbound(Function<reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>,reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>> outboundConsumer) |
reactor.core.publisher.Mono<Void> |
sendMessage(McpSchema.JSONRPCMessage message)
Sends a message to the peer asynchronously.
|
void |
setStdErrorHandler(Consumer<String> errorHandler)
Sets the handler for processing transport-level errors.
|
<T> T |
unmarshalFrom(Object data,
com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Unmarshals the given data into an object of the specified type.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclosepublic StdioClientTransport(ServerParameters params)
params - The parameters for configuring the server processpublic StdioClientTransport(ServerParameters params, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
params - The parameters for configuring the server processobjectMapper - The ObjectMapper to use for JSON serialization/deserializationpublic reactor.core.publisher.Mono<Void> connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
connect in interface McpClientTransportconnect in interface McpTransportRuntimeException - if the process fails to start or if the process streams
are nullprotected ProcessBuilder getProcessBuilder()
public void setStdErrorHandler(Consumer<String> errorHandler)
The provided handler will be called when errors occur during transport operations, such as connection failures or protocol violations.
errorHandler - a consumer that processes error messagespublic void awaitForExit()
RuntimeException - if the process is interrupted while waitingpublic reactor.core.publisher.Mono<Void> sendMessage(McpSchema.JSONRPCMessage message)
McpTransportThis method handles the transmission of messages to the server in an asynchronous manner. Messages are sent in JSON-RPC format as specified by the MCP protocol.
sendMessage in interface McpTransportmessage - the McpSchema.JSONRPCMessage to be sent to the serverMono that completes when the message has been sentprotected void handleOutbound(Function<reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>,reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>> outboundConsumer)
public reactor.core.publisher.Mono<Void> closeGracefully()
closeGracefully in interface McpTransportpublic reactor.core.publisher.Sinks.Many<String> getErrorSink()
public <T> T unmarshalFrom(Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
McpTransportunmarshalFrom in interface McpTransportT - the type of the object to unmarshaldata - the data to unmarshaltypeRef - the type reference for the object to unmarshalCopyright © 2025. All rights reserved.