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

    Constructors
    Constructor
    Description
    DefaultMcpTransportSession(Function<String,org.reactivestreams.Publisher<Void>> onClose)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addConnection(reactor.core.Disposable connection)
    Adds a resource that this transport session can monitor and dismiss when needed.
    void
    Close and clear the monitored resources.
    reactor.core.publisher.Mono<Void>
    Close and clear the monitored resources in a graceful manner.
    boolean
    Stateful operation that flips the un-initialized state to initialized if this is the first call.
    void
    removeConnection(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultMcpTransportSession

      public DefaultMcpTransportSession(Function<String,org.reactivestreams.Publisher<Void>> onClose)
  • Method Details

    • sessionId

      public Optional<String> sessionId()
      Description copied from interface: McpTransportSession
      In case of stateful MCP servers, the value is present and contains the String identifier for the transport-level session.
      Specified by:
      sessionId in interface McpTransportSession<reactor.core.Disposable>
      Returns:
      optional session id
    • markInitialized

      public boolean markInitialized(String sessionId)
      Description copied from interface: McpTransportSession
      Stateful 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:
      markInitialized in interface McpTransportSession<reactor.core.Disposable>
      Parameters:
      sessionId - session identifier as provided by the server
      Returns:
      if successful, this method returns true and means that a post-initialization step can be performed
    • addConnection

      public void addConnection(reactor.core.Disposable connection)
      Description copied from interface: McpTransportSession
      Adds a resource that this transport session can monitor and dismiss when needed.
      Specified by:
      addConnection in interface McpTransportSession<reactor.core.Disposable>
      Parameters:
      connection - the managed resource
    • removeConnection

      public void removeConnection(reactor.core.Disposable connection)
      Description copied from interface: McpTransportSession
      Called when the resource is terminating by itself and the transport session does not need to track it anymore.
      Specified by:
      removeConnection in interface McpTransportSession<reactor.core.Disposable>
      Parameters:
      connection - the resource to remove from the monitored collection
    • close

      public void close()
      Description copied from interface: McpTransportSession
      Close and clear the monitored resources. Potentially asynchronous.
      Specified by:
      close in interface McpTransportSession<reactor.core.Disposable>
    • closeGracefully

      public reactor.core.publisher.Mono<Void> closeGracefully()
      Description copied from interface: McpTransportSession
      Close and clear the monitored resources in a graceful manner.
      Specified by:
      closeGracefully in interface McpTransportSession<reactor.core.Disposable>
      Returns:
      completes once all resources have been dismissed