Skip to main content
Glama
es6kr

claude-session-manager

by es6kr

list_sessions

Retrieve all sessions within a specified project to manage and organize Claude Code Session Manager workflows.

Instructions

List all sessions in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_nameYesProject folder name (e.g., '-Users-young-works-myproject')

Implementation Reference

  • Registration of the list_sessions tool with MCP Server, defining its name, description, and input schema requiring project_name.
    Tool(
        name="list_sessions",
        description="List all sessions in a project",
        inputSchema={
            "type": "object",
            "properties": {
                "project_name": {
                    "type": "string",
                    "description": "Project folder name (e.g., '-Users-young-works-myproject')"
                }
            },
            "required": ["project_name"]
        }
    ),
    Tool(
  • Handler dispatch in the main call_tool function that handles the list_sessions tool call by extracting the project_name parameter and invoking the get_sessions function.
    elif name == "list_sessions":
        project_name = arguments.get("project_name", "")
        result = get_sessions(project_name)
  • Primary handler function that lists sessions for the specified project by scanning .jsonl files (excluding agent-), parsing summaries, and sorting by updated_at.
    def get_sessions(project_name: str) -> list[dict]:
        """Get all sessions for a project."""
        base_path = get_base_path()
        project_path = base_path / project_name
        sessions = []
    
        if not project_path.exists():
            return sessions
    
        for jsonl_file in project_path.glob("*.jsonl"):
            if jsonl_file.name.startswith("agent-"):
                continue
    
            session_info = parse_session_summary(jsonl_file)
            if session_info:
                sessions.append(session_info)
    
        return sorted(sessions, key=lambda s: s.get("updated_at", ""), reverse=True)
  • Supporting helper that parses a session's .jsonl file to extract metadata: session_id, title (derived from first user message), message_count, created_at, updated_at timestamps.
    def parse_session_summary(file_path: Path) -> dict | None:
        """Parse session file for summary info."""
        session_id = file_path.stem
        info = {
            "session_id": session_id,
            "title": f"Session {session_id[:8]}",
            "message_count": 0,
            "created_at": None,
            "updated_at": None,
        }
    
        try:
            with open(file_path, 'r', encoding='utf-8') as f:
                first_user_content = None
                for line in f:
                    line = line.strip()
                    if not line:
                        continue
                    try:
                        entry = json.loads(line)
                        entry_type = entry.get('type')
    
                        if entry_type in ('user', 'assistant'):
                            info["message_count"] += 1
                            timestamp = entry.get('timestamp', '')
                            if timestamp:
                                if not info["created_at"] or timestamp < info["created_at"]:
                                    info["created_at"] = timestamp
                                if not info["updated_at"] or timestamp > info["updated_at"]:
                                    info["updated_at"] = timestamp
    
                            if entry_type == 'user' and first_user_content is None:
                                message = entry.get('message', {})
                                content_list = message.get('content', [])
                                for item in content_list:
                                    if isinstance(item, dict) and item.get('type') == 'text':
                                        text = item.get('text', '').strip()
                                        text = re.sub(r'<ide_[^>]*>.*?</ide_[^>]*>', '', text, flags=re.DOTALL).strip()
                                        if text:
                                            first_user_content = text
                                            break
                    except json.JSONDecodeError:
                        continue
    
                if first_user_content:
                    if '\n\n' in first_user_content:
                        info["title"] = first_user_content.split('\n\n')[0][:100]
                    elif '\n' in first_user_content:
                        info["title"] = first_user_content.split('\n')[0][:100]
                    else:
                        info["title"] = first_user_content[:100]
    
        except Exception:
            return None
    
        return info if info["message_count"] > 0 else None
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states it's a list operation, implying read-only behavior, but doesn't specify whether it returns all sessions at once, supports pagination, or has any rate limits or authentication requirements. This leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without any unnecessary words. It's appropriately sized and front-loaded, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that presumably returns session data. It doesn't explain what a 'session' entails, what fields are returned, or the format of the response, leaving the agent without necessary context for proper usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the single parameter 'project_name' with its description. The tool description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high coverage but not adding extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List') and target resource ('all sessions in a project'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'list_projects' or 'preview_cleanup', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'list_projects' for listing projects instead of sessions, or 'clear_sessions'/'delete_session' for related operations, leaving the agent without contextual usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/es6kr/claude-session-manager'

If you have feedback or need assistance with the MCP directory API, please join our Discord server