Package io.modelcontextprotocol.spec
Class DefaultMcpTransportSession
java.lang.Object
io.modelcontextprotocol.spec.DefaultMcpTransportSession
- All Implemented Interfaces:
McpTransportSession<reactor.core.Disposable>
public class DefaultMcpTransportSession
extends Object
implements McpTransportSession<reactor.core.Disposable>
Default implementation of
McpTransportSession which manages the open
connections using tye Disposable type and allows to perform clean up using the
Disposable.dispose() method.- Author:
- Dariusz Jędrzejczyk
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMcpTransportSession(Function<String, org.reactivestreams.Publisher<Void>> onClose) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnection(reactor.core.Disposable connection) Adds a resource that this transport session can monitor and dismiss when needed.voidclose()Close and clear the monitored resources.reactor.core.publisher.Mono<Void>Close and clear the monitored resources in a graceful manner.booleanmarkInitialized(String sessionId) Stateful operation that flips the un-initialized state to initialized if this is the first call.voidremoveConnection(reactor.core.Disposable connection) Called when the resource is terminating by itself and the transport session does not need to track it anymore.In case of stateful MCP servers, the value is present and contains the String identifier for the transport-level session.
-
Constructor Details
-
DefaultMcpTransportSession
-
-
Method Details
-
sessionId
Description copied from interface:McpTransportSessionIn case of stateful MCP servers, the value is present and contains the String identifier for the transport-level session.- Specified by:
sessionIdin interfaceMcpTransportSession<reactor.core.Disposable>- Returns:
- optional session id
-
markInitialized
Description copied from interface:McpTransportSessionStateful operation that flips the un-initialized state to initialized if this is the first call. If the transport provides a session id for the communication, argument should not be null to record the current identifier.- Specified by:
markInitializedin interfaceMcpTransportSession<reactor.core.Disposable>- Parameters:
sessionId- session identifier as provided by the server- Returns:
- if successful, this method returns
trueand means that a post-initialization step can be performed
-
addConnection
public void addConnection(reactor.core.Disposable connection) Description copied from interface:McpTransportSessionAdds a resource that this transport session can monitor and dismiss when needed.- Specified by:
addConnectionin interfaceMcpTransportSession<reactor.core.Disposable>- Parameters:
connection- the managed resource
-
removeConnection
public void removeConnection(reactor.core.Disposable connection) Description copied from interface:McpTransportSessionCalled when the resource is terminating by itself and the transport session does not need to track it anymore.- Specified by:
removeConnectionin interfaceMcpTransportSession<reactor.core.Disposable>- Parameters:
connection- the resource to remove from the monitored collection
-
close
public void close()Description copied from interface:McpTransportSessionClose and clear the monitored resources. Potentially asynchronous.- Specified by:
closein interfaceMcpTransportSession<reactor.core.Disposable>
-
closeGracefully
Description copied from interface:McpTransportSessionClose and clear the monitored resources in a graceful manner.- Specified by:
closeGracefullyin interfaceMcpTransportSession<reactor.core.Disposable>- Returns:
- completes once all resources have been dismissed
-