Package io.modelcontextprotocol.spec
Interface McpClientTransport
- All Superinterfaces:
McpTransport
- All Known Implementing Classes:
HttpClientSseClientTransport,HttpClientStreamableHttpTransport,StdioClientTransport
Interface for the client side of the
McpTransport. It allows setting handlers
for messages that are incoming from the MCP server and hooking in to exceptions raised
on the transport layer.- Author:
- Christian Tzolov, Dariusz Jędrzejczyk
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>, reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler) Used to register the incoming messages' handler and potentially (eagerly) connect to the server.default voidsetExceptionHandler(Consumer<Throwable> handler) Sets the exception handler for exceptions raised on the transport layer.Methods inherited from interface io.modelcontextprotocol.spec.McpTransport
close, closeGracefully, protocolVersions, sendMessage, unmarshalFrom
-
Method Details
-
connect
reactor.core.publisher.Mono<Void> connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>, reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler) Used to register the incoming messages' handler and potentially (eagerly) connect to the server.- Parameters:
handler- a transformer for incoming messages- Returns:
- a
Monothat 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 returnedMonosimply means the client can now be used. An error can be retried according to the application requirements.
-
setExceptionHandler
Sets the exception handler for exceptions raised on the transport layer.- Parameters:
handler- Allows reacting to transport level exceptions by the higher layers
-