public class StdioClientTransport extends java.lang.Object implements McpClientTransport
构造器和说明 |
---|
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.
|
限定符和类型 | 方法和说明 |
---|---|
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,
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, wait
close
public 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<java.lang.Void> connect(java.util.function.Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>,reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler)
connect
在接口中 McpClientTransport
connect
在接口中 McpTransport
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)
McpTransport
This 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
在接口中 McpTransport
message
- 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
在接口中 McpTransport
public reactor.core.publisher.Sinks.Many<java.lang.String> getErrorSink()
public <T> T unmarshalFrom(java.lang.Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
McpTransport
unmarshalFrom
在接口中 McpTransport
T
- the type of the object to unmarshaldata
- the data to unmarshaltypeRef
- the type reference for the object to unmarshal