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 Type
    Method
    Description
    void
    Connects to the MCP server.
    void
    Disconnects from the MCP server.
    boolean
    Checks if the transport is currently connected.
    void
    send(String message)
    Sends a message to the MCP server.
    void
    setOnError(Consumer<Throwable> errorConsumer)
    Sets a consumer for transport errors.
    void
    setOnMessage(Consumer<String> messageConsumer)
    Sets a consumer for incoming messages from the MCP server.
  • Method Details

    • connect

      void connect() throws IOException
      Connects to the MCP server.
      Throws:
      IOException - if connection fails
    • send

      void send(String message) throws IOException
      Sends a message to the MCP server.
      Parameters:
      message - the message to send (JSON-RPC request)
      Throws:
      IOException - if sending fails
    • setOnMessage

      void setOnMessage(Consumer<String> messageConsumer)
      Sets a consumer for incoming messages from the MCP server.
      Parameters:
      messageConsumer - the consumer for incoming messages (JSON-RPC response/notification)
    • setOnError

      void setOnError(Consumer<Throwable> errorConsumer)
      Sets a consumer for transport errors.
      Parameters:
      errorConsumer - the consumer for transport errors
    • disconnect

      void disconnect() throws IOException
      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