- All Known Subinterfaces:
McpClientTransport,McpServerTransport,McpStreamableServerTransport
- All Known Implementing Classes:
HttpClientSseClientTransport,HttpClientStreamableHttpTransport,StdioClientTransport
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 TypeMethodDescriptiondefault voidclose()Closes the transport connection and releases any associated resources.reactor.core.publisher.Mono<Void>Closes the transport connection and releases any associated resources asynchronously.default Stringreactor.core.publisher.Mono<Void>sendMessage(McpSchema.JSONRPCMessage message) Sends a message to the peer asynchronously.<T> TunmarshalFrom(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
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- theMcpSchema.JSONRPCMessageto be sent to the server- Returns:
- a
reactor.core.publisher.Mono<Void>that completes when the message has been sent
-
unmarshalFrom
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 unmarshaltypeRef- the type reference for the object to unmarshal- Returns:
- the unmarshalled object
-
protocolVersion
-