Package com.tnsai.mcp.client
Interface McpTransport
- All Known Implementing Classes:
BaseTransport,HttpTransport,McpInspectorClient,McpTracingInterceptor,MockMcpTransport,OAuthMcpTransport,SSETransport,StdioTransport,StreamableHttpTransport
public interface McpTransport
Interface for MCP transport mechanisms.
Defines how McpClient communicates with an MCP server.
-
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Connects to the MCP server.voidDisconnects from the MCP server.booleanChecks if the transport is currently connected.voidSends a message to the MCP server.voidsetOnError(Consumer<Throwable> errorConsumer) Sets a consumer for transport errors.voidsetOnMessage(Consumer<String> messageConsumer) Sets a consumer for incoming messages from the MCP server.
-
Method Details
-
connect
Connects to the MCP server.- Throws:
IOException- if connection fails
-
send
Sends a message to the MCP server.- Parameters:
message- the message to send (JSON-RPC request)- Throws:
IOException- if sending fails
-
setOnMessage
Sets a consumer for incoming messages from the MCP server.- Parameters:
messageConsumer- the consumer for incoming messages (JSON-RPC response/notification)
-
setOnError
Sets a consumer for transport errors.- Parameters:
errorConsumer- the consumer for transport errors
-
disconnect
Disconnects from the MCP server.- Throws:
IOException- if disconnection fails
-
isConnected
boolean isConnected()Checks if the transport is currently connected.- Returns:
- true if connected, false otherwise
-