Class: VectorMCP::Transport::SseSessionManager

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

Overview

Session manager for SSE transport with single shared session and client connection management. Extends BaseSessionManager with SSE-specific functionality.

The SSE transport uses a single shared session for all client connections, but manages multiple client connections separately.

Instance Attribute Summary collapse

Attributes inherited from BaseSessionManager

#logger, #session_timeout, #transport

Instance Method Summary collapse

Methods inherited from BaseSessionManager

#active_session_ids, #create_session, #find_sessions, #get_or_create_session, #get_session, #get_session_metadata, #session_count, #session_metadata_updated?, #session_terminated?, #sessions?

Constructor Details

#initialize(transport, session_timeout = 300) ⇒ SseSessionManager

Initializes a new SSE session manager.

Parameters:

  • transport (SSE)

    The parent transport instance

  • session_timeout (Integer) (defaults to: 300)

    Session timeout in seconds



19
20
21
22
23
24
25
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 19

def initialize(transport, session_timeout = 300)
  @clients = Concurrent::Hash.new
  super

  # Create the single shared session for SSE transport
  @shared_session = create_shared_session
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



13
14
15
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 13

def clients
  @clients
end

Instance Method Details

#all_clientsHash

Gets all client connections.

Returns:

  • (Hash)

    Hash of client_id => client_connection



63
64
65
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 63

def all_clients
  @clients.dup
end

#cleanup_all_sessionsvoid

This method returns an undefined value.

Cleans up all clients and the shared session.



77
78
79
80
81
82
83
84
85
86
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 77

def cleanup_all_sessions
  logger.info { "Cleaning up #{@clients.size} client connection(s)" }

  @clients.each_value do |client_conn|
    close_client_connection(client_conn)
  end
  @clients.clear

  super
end

#client_countInteger

Gets the number of connected clients.

Returns:

  • (Integer)

    Number of connected clients



70
71
72
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 70

def client_count
  @clients.size
end

#client_unregistered?(client_id) ⇒ Boolean

Unregisters a client connection from the session manager.

Parameters:

  • client_id (String)

    The client connection ID

Returns:

  • (Boolean)

    True if client was found and removed



51
52
53
54
55
56
57
58
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 51

def client_unregistered?(client_id)
  client = @clients.delete(client_id)
  return false unless client

  (@shared_session.id, clients_count: @clients.size)
  logger.debug { "Client unregistered: #{client_id}" }
  true
end

#register_client(client_id, client_connection) ⇒ void

This method returns an undefined value.

Registers a client connection with the session manager.

Parameters:

  • client_id (String)

    The client connection ID

  • client_connection (Object)

    The client connection object



41
42
43
44
45
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 41

def register_client(client_id, client_connection)
  @clients[client_id] = client_connection
  (@shared_session.id, clients_count: @clients.size)
  logger.debug { "Client registered: #{client_id}" }
end

#shared_sessionSession

Gets the shared session for SSE transport. SSE uses a single session shared across all client connections.

Returns:



31
32
33
34
# File 'lib/vector_mcp/transport/sse_session_manager.rb', line 31

def shared_session
  @shared_session.touch!
  @shared_session
end