Class: ActionMCP::Client::ActiveRecordSessionStore
- Inherits:
-
Object
- Object
- ActionMCP::Client::ActiveRecordSessionStore
- Includes:
- SessionStore
- Defined in:
- lib/action_mcp/client/active_record_session_store.rb
Overview
ActiveRecord-backed session store for production
Instance Method Summary collapse
- #cleanup_expired_sessions(older_than: 24.hours.ago) ⇒ Object
- #delete_session(session_id) ⇒ Object
- #load_session(session_id) ⇒ Object
- #save_session(session_id, session_data) ⇒ Object
- #session_exists?(session_id) ⇒ Boolean
Methods included from SessionStore
Instance Method Details
#cleanup_expired_sessions(older_than: 24.hours.ago) ⇒ Object
52 53 54 |
# File 'lib/action_mcp/client/active_record_session_store.rb', line 52 def cleanup_expired_sessions(older_than: 24.hours.ago) ActionMCP::Session.where("updated_at < ?", older_than).delete_all end |
#delete_session(session_id) ⇒ Object
44 45 46 |
# File 'lib/action_mcp/client/active_record_session_store.rb', line 44 def delete_session(session_id) ActionMCP::Session.find_by(id: session_id)&.destroy end |
#load_session(session_id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_mcp/client/active_record_session_store.rb', line 9 def load_session(session_id) session = ActionMCP::Session.find_by(id: session_id) return nil unless session { id: session.id, protocol_version: session.protocol_version, client_info: session.client_info, client_capabilities: session.client_capabilities, server_info: session.server_info, server_capabilities: session.server_capabilities, created_at: session.created_at, updated_at: session.updated_at } end |
#save_session(session_id, session_data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/action_mcp/client/active_record_session_store.rb', line 25 def save_session(session_id, session_data) session = ActionMCP::Session.find_or_initialize_by(id: session_id) # Only assign attributes that exist in the database attributes = {} attributes[:protocol_version] = session_data[:protocol_version] if session_data.key?(:protocol_version) attributes[:client_info] = session_data[:client_info] if session_data.key?(:client_info) attributes[:client_capabilities] = session_data[:client_capabilities] if session_data.key?(:client_capabilities) attributes[:server_info] = session_data[:server_info] if session_data.key?(:server_info) attributes[:server_capabilities] = session_data[:server_capabilities] if session_data.key?(:server_capabilities) # Store any extra data in a jsonb column if available # For now, we'll skip last_event_id and session_data as they don't exist in the DB session.assign_attributes(attributes) session.save! session_data end |