Package io.modelcontextprotocol.spec
Class DefaultMcpTransportStream<CONNECTION>
java.lang.Object
io.modelcontextprotocol.spec.DefaultMcpTransportStream<CONNECTION>
- Type Parameters:
CONNECTION- the resource serving the stream
- All Implemented Interfaces:
McpTransportStream<CONNECTION>
public class DefaultMcpTransportStream<CONNECTION>
extends Object
implements McpTransportStream<CONNECTION>
An implementation of
McpTransportStream using Project Reactor types.- Author:
- Dariusz Jędrzejczyk
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMcpTransportStream(boolean resumable, Function<McpTransportStream<CONNECTION>, org.reactivestreams.Publisher<CONNECTION>> reconnect) Constructs a new instance representing a particular stream that can resume using the provided reconnect mechanism. -
Method Summary
Modifier and TypeMethodDescriptionorg.reactivestreams.Publisher<McpSchema.JSONRPCMessage>consumeSseStream(org.reactivestreams.Publisher<reactor.util.function.Tuple2<Optional<String>, Iterable<McpSchema.JSONRPCMessage>>> eventStream) Allows keeping track of the transport stream of events (currently an SSE stream from Streamable HTTP specification) and enable resumability and reconnects in case of stream errors.lastId()The last observed event identifier.longstreamId()An internal stream identifier used to distinguish streams while debugging.
-
Constructor Details
-
DefaultMcpTransportStream
public DefaultMcpTransportStream(boolean resumable, Function<McpTransportStream<CONNECTION>, org.reactivestreams.Publisher<CONNECTION>> reconnect) Constructs a new instance representing a particular stream that can resume using the provided reconnect mechanism.- Parameters:
resumable- whether the stream is resumable and should try to reconnectreconnect- the mechanism to use in case an error is observed on the current event stream to asynchronously kick off a resumed stream consumption, potentially using the storedlastId().
-
-
Method Details
-
lastId
Description copied from interface:McpTransportStreamThe last observed event identifier.- Specified by:
lastIdin interfaceMcpTransportStream<CONNECTION>- Returns:
- if not empty, contains the most recent event that was consumed
-
streamId
public long streamId()Description copied from interface:McpTransportStreamAn internal stream identifier used to distinguish streams while debugging.- Specified by:
streamIdin interfaceMcpTransportStream<CONNECTION>- Returns:
- a
longstream identifier value
-
consumeSseStream
public org.reactivestreams.Publisher<McpSchema.JSONRPCMessage> consumeSseStream(org.reactivestreams.Publisher<reactor.util.function.Tuple2<Optional<String>, Iterable<McpSchema.JSONRPCMessage>>> eventStream) Description copied from interface:McpTransportStreamAllows keeping track of the transport stream of events (currently an SSE stream from Streamable HTTP specification) and enable resumability and reconnects in case of stream errors.- Specified by:
consumeSseStreamin interfaceMcpTransportStream<CONNECTION>- Parameters:
eventStream- aPublisherof tuples (pairs) of an optional identifier associated with a collection of messages- Returns:
- a flattened
PublisherofJSON-RPC messageswith the identifier stripped away
-