Class ClosedMcpTransportSession<CONNECTION>

java.lang.Object
io.modelcontextprotocol.spec.ClosedMcpTransportSession<CONNECTION>
Type Parameters:
CONNECTION - the resource representing the connection that the transport manages.
All Implemented Interfaces:
McpTransportSession<CONNECTION>

public class ClosedMcpTransportSession<CONNECTION> extends Object implements McpTransportSession<CONNECTION>
Represents a closed MCP session, which may not be reused. All calls will throw a McpTransportSessionClosedException.
Author:
Daniel Garnier-Moiroux
  • Constructor Details

    • ClosedMcpTransportSession

      public ClosedMcpTransportSession(@Nullable String sessionId)
  • 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<CONNECTION>
      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<CONNECTION>
      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(CONNECTION 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<CONNECTION>
      Parameters:
      connection - the managed resource
    • removeConnection

      public void removeConnection(CONNECTION 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<CONNECTION>
      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<CONNECTION>
    • closeGracefully

      public org.reactivestreams.Publisher<Void> closeGracefully()
      Description copied from interface: McpTransportSession
      Close and clear the monitored resources in a graceful manner.
      Specified by:
      closeGracefully in interface McpTransportSession<CONNECTION>
      Returns:
      completes once all resources have been dismissed