Interface McpTransport

All Known Subinterfaces:
McpClientTransport, McpServerTransport
All Known Implementing Classes:
HttpClientSseClientTransport, StdioClientTransport

public interface McpTransport
Defines the asynchronous transport layer for the Model Context Protocol (MCP).

The McpTransport interface provides the foundation for implementing custom transport mechanisms in the Model Context Protocol. It handles the bidirectional communication between the client and server components, supporting asynchronous message exchange using JSON-RPC format.

Implementations of this interface are responsible for:

  • Managing the lifecycle of the transport connection
  • Handling incoming messages and errors from the server
  • Sending outbound messages to the server

The transport layer is designed to be protocol-agnostic, allowing for various implementations such as WebSocket, HTTP, or custom protocols.

Author:
Christian Tzolov, Dariusz Jędrzejczyk
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Closes the transport connection and releases any associated resources.
    reactor.core.publisher.Mono<Void>
    Closes the transport connection and releases any associated resources asynchronously.
    reactor.core.publisher.Mono<Void>
    Sends a message to the peer asynchronously.
    <T> T
    unmarshalFrom(Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
    Unmarshals the given data into an object of the specified type.
  • Method Details

    • close

      default void close()
      Closes the transport connection and releases any associated resources.

      This method ensures proper cleanup of resources when the transport is no longer needed. It should handle the graceful shutdown of any active connections.

    • closeGracefully

      reactor.core.publisher.Mono<Void> closeGracefully()
      Closes the transport connection and releases any associated resources asynchronously.
      Returns:
      a reactor.core.publisher.Mono<Void> that completes when the connection has been closed.
    • sendMessage

      reactor.core.publisher.Mono<Void> sendMessage(McpSchema.JSONRPCMessage message)
      Sends a message to the peer asynchronously.

      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.

      Parameters:
      message - the McpSchema.JSONRPCMessage to be sent to the server
      Returns:
      a reactor.core.publisher.Mono<Void> that completes when the message has been sent
    • unmarshalFrom

      <T> T unmarshalFrom(Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
      Unmarshals the given data into an object of the specified type.
      Type Parameters:
      T - the type of the object to unmarshal
      Parameters:
      data - the data to unmarshal
      typeRef - the type reference for the object to unmarshal
      Returns:
      the unmarshalled object