Class: VectorMCP::Transport::HttpStream::SessionManager Private

Inherits:
BaseSessionManager show all
Defined in:
lib/vector_mcp/transport/http_stream/session_manager.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Manages HTTP stream sessions with automatic cleanup and thread safety. Extends BaseSessionManager with HTTP streaming-specific functionality.

Handles:

  • Session creation and lifecycle management

  • Thread-safe session storage using concurrent-ruby

  • Automatic session cleanup based on timeout

  • Session context integration with VectorMCP::Session

  • HTTP streaming connection management

Defined Under Namespace

Classes: Session

Instance Attribute Summary

Attributes inherited from BaseSessionManager

#logger, #session_timeout, #transport

Instance Method Summary collapse

Methods inherited from BaseSessionManager

#active_session_ids, #cleanup_all_sessions, #find_sessions, #get_session, #get_session_metadata, #initialize, #session_count, #session_metadata_updated?, #session_terminated?, #sessions?

Constructor Details

This class inherits a constructor from VectorMCP::Transport::BaseSessionManager

Instance Method Details

#create_session(session_id = nil, rack_env = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new session. RequestContext.from_rack_env handles nil rack_env by falling back to a minimal context, so we don’t need to branch here.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 76

def create_session(session_id = nil, rack_env = nil)
  session_id ||= generate_session_id
  now = Time.now

  request_context = VectorMCP::RequestContext.from_rack_env(rack_env, "http_stream")
  session_context = VectorMCP::Session.new(
    @transport.server, @transport, id: session_id, request_context: request_context
  )

  session = Session.new(session_id, session_context, now, now, )
  @sessions[session_id] = session

  logger.info { "Session created: #{session_id}" }
  session
end

#get_or_create_session(session_id = nil, rack_env = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override to add rack_env support. Returns nil when a session_id is provided but not found (expired or unknown). Callers are responsible for returning 404 in that case.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 95

def get_or_create_session(session_id = nil, rack_env = nil)
  if session_id
    session = get_session(session_id)
    if session
      # Update existing session context if rack_env is provided
      if rack_env
        request_context = VectorMCP::RequestContext.from_rack_env(rack_env, "http_stream")
        session.context.request_context = request_context
      end
      return session
    end

    # Session ID provided but not found — signal 404 to caller
    return nil
  end

  create_session(nil, rack_env)
end

#remove_streaming_connection(session, connection = nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Removes streaming connection from a session.

Parameters:

  • session (Session)

    The session to remove streaming from

  • connection (Object, nil) (defaults to: nil)

    The specific connection to remove, or nil to clear all



145
146
147
148
149
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 145

def remove_streaming_connection(session, connection = nil)
  session.remove_streaming_connection(connection)
  session.touch!
  logger.debug { "Streaming connection removed: #{session.id}" }
end

#set_streaming_connection(session, connection) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Associates a streaming connection with a session.

Parameters:

  • session (Session)

    The session to associate with

  • connection (Object)

    The streaming connection object



134
135
136
137
138
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 134

def set_streaming_connection(session, connection)
  session.add_streaming_connection(connection)
  session.touch!
  logger.debug { "Streaming connection associated: #{session.id} (stream #{connection.stream_id})" }
end

#terminate_session(session_id) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Terminates a session by ID.

rubocop:disable Naming/PredicateMethod

Parameters:

  • session_id (String)

    The session ID to terminate

Returns:

  • (Boolean)

    True if session was found and terminated



119
120
121
122
123
124
125
126
# File 'lib/vector_mcp/transport/http_stream/session_manager.rb', line 119

def terminate_session(session_id)
  session = @sessions.delete(session_id)
  return false unless session

  on_session_terminated(session)
  logger.info { "Session terminated: #{session_id}" }
  true
end