Class: Sxn::MCP::Tools::Sessions::ListSessions

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/sxn/mcp/tools/sessions.rb

Overview

List all sessions with optional filtering

Class Method Summary collapse

Class Method Details

.call(server_context:, status: nil, limit: 100) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sxn/mcp/tools/sessions.rb', line 29

def call(server_context:, status: nil, limit: 100)
  BaseTool.ensure_initialized!(server_context)

  BaseTool::ErrorMapping.wrap do
    session_manager = server_context[:session_manager]
    sessions = session_manager.list_sessions(status: status, limit: limit)

    if sessions.empty?
      BaseTool.text_response("No sessions found.")
    else
      summary = "Found #{sessions.length} session(s):"
      formatted = sessions.map do |s|
        "- #{s[:name]} (#{s[:status]}) - #{s[:worktrees].keys.length} worktrees"
      end.join("\n")

      BaseTool.text_response("#{summary}\n#{formatted}")
    end
  end
end