public class StdioClientTransport extends java.lang.Object implements McpClientTransport
| 构造器和说明 |
|---|
StdioClientTransport(ServerParameters params,
McpJsonMapper jsonMapper)
Creates a new StdioClientTransport with the specified parameters and JsonMapper.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
awaitForExit()
Waits for the server process to exit.
|
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Gracefully closes the transport by destroying the process and disposing of the
schedulers.
|
reactor.core.publisher.Mono<java.lang.Void> |
connect(java.util.function.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<java.lang.String> |
getErrorSink() |
protected java.lang.ProcessBuilder |
getProcessBuilder()
Creates and returns a new ProcessBuilder instance.
|
protected void |
handleOutbound(java.util.function.Function<reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>,reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>> outboundConsumer) |
reactor.core.publisher.Mono<java.lang.Void> |
sendMessage(McpSchema.JSONRPCMessage message)
Sends a message to the peer asynchronously.
|
void |
setStdErrorHandler(java.util.function.Consumer<java.lang.String> errorHandler)
Sets the handler for processing transport-level errors.
|
<T> T |
unmarshalFrom(java.lang.Object data,
TypeRef<T> typeRef)
Unmarshals the given data into an object of the specified type.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetExceptionHandlerclose, protocolVersionspublic StdioClientTransport(ServerParameters params, McpJsonMapper jsonMapper)
params - The parameters for configuring the server processjsonMapper - The JsonMapper to use for JSON serialization/deserializationpublic reactor.core.publisher.Mono<java.lang.Void> connect(java.util.function.Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
connect 在接口中 McpClientTransporthandler - a transformer for incoming messagesMono that terminates upon successful client setup. It can mean
establishing a connection (which can be later disposed) but it doesn't have to,
depending on the transport type. The successful termination of the returned
Mono simply means the client can now be used. An error can be retried
according to the application requirements.java.lang.RuntimeException - if the process fails to start or if the process streams
are nullprotected java.lang.ProcessBuilder getProcessBuilder()
public void setStdErrorHandler(java.util.function.Consumer<java.lang.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()
java.lang.RuntimeException - if the process is interrupted while waitingpublic reactor.core.publisher.Mono<java.lang.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 在接口中 McpTransportmessage - the McpSchema.JSONRPCMessage to be sent to the serverMono that completes when the message has been sentprotected void handleOutbound(java.util.function.Function<reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>,reactor.core.publisher.Flux<McpSchema.JSONRPCMessage>> outboundConsumer)
public reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
closeGracefully 在接口中 McpTransportpublic reactor.core.publisher.Sinks.Many<java.lang.String> getErrorSink()
public <T> T unmarshalFrom(java.lang.Object data,
TypeRef<T> typeRef)
McpTransportunmarshalFrom 在接口中 McpTransportT - the type of the object to unmarshaldata - the data to unmarshaltypeRef - the type reference for the object to unmarshal