Class HttpClientStreamableHttpTransport
- All Implemented Interfaces:
McpClientTransport,McpTransport
2025-03-26 version of the MCP specification.
The transport is capable of resumability and reconnects. It reacts to transport-level
session invalidation and will propagate appropriate exceptions to the higher level abstraction layer when needed in order to
allow proper state management. The implementation handles servers that are stateful and
provide session meta information, but can also communicate with stateless servers that
do not provide a session identifier and do not support SSE streams.
This implementation does not handle backwards compatibility with the "HTTP
with SSE" transport. In order to communicate over the phased-out
2024-11-05 protocol, use HttpClientSseClientTransport or
WebFluxSseClientTransport.
- Author:
- Christian Tzolov
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intstatic intstatic int -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>Closes the transport connection and releases any associated resources asynchronously.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.reactor.core.publisher.Mono<Void>sendMessage(McpSchema.JSONRPCMessage sentMessage) Sends a message to the peer asynchronously.voidsetExceptionHandler(Consumer<Throwable> handler) Sets the exception handler for exceptions raised on the transport layer.toString(McpSchema.JSONRPCMessage message) <T> TunmarshalFrom(Object data, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Unmarshals the given data into an object of the specified type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.modelcontextprotocol.spec.McpTransport
close
-
Field Details
-
NOT_FOUND
public static int NOT_FOUND -
METHOD_NOT_ALLOWED
public static int METHOD_NOT_ALLOWED -
BAD_REQUEST
public static int BAD_REQUEST
-
-
Method Details
-
protocolVersions
- Specified by:
protocolVersionsin interfaceMcpTransport
-
builder
-
connect
public reactor.core.publisher.Mono<Void> connect(Function<reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>, reactor.core.publisher.Mono<McpSchema.JSONRPCMessage>> handler) Description copied from interface:McpClientTransportUsed to register the incoming messages' handler and potentially (eagerly) connect to the server.- Specified by:
connectin interfaceMcpClientTransport- 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
Description copied from interface:McpClientTransportSets the exception handler for exceptions raised on the transport layer.- Specified by:
setExceptionHandlerin interfaceMcpClientTransport- Parameters:
handler- Allows reacting to transport level exceptions by the higher layers
-
closeGracefully
Description copied from interface:McpTransportCloses the transport connection and releases any associated resources asynchronously.- Specified by:
closeGracefullyin interfaceMcpTransport- Returns:
- a
reactor.core.publisher.Mono<Void>that completes when the connection has been closed.
-
toString
-
sendMessage
Description copied from interface:McpTransportSends 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.
- Specified by:
sendMessagein interfaceMcpTransport- Parameters:
sentMessage- theMcpSchema.JSONRPCMessageto be sent to the server- Returns:
- a
reactor.core.publisher.Mono<Void>that completes when the message has been sent
-
unmarshalFrom
Description copied from interface:McpTransportUnmarshals the given data into an object of the specified type.- Specified by:
unmarshalFromin interfaceMcpTransport- 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
-