Skip to main content
Glama

List Sessions

listSessions
Read-onlyIdempotent

Retrieve metadata of active Claude CLI sessions, including IDs, models, timing, turn counts, and cumulative cost. Use to identify available sessions before resuming with a session ID.

Instructions

List active Claude CLI sessions tracked by this server. Returns session metadata (IDs, models, timing, turn counts, cumulative cost) for orchestration. Use to check available sessions before resuming with sessionId. No cost (local lookup only).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler (tool logic) for 'listSessions'. Registered via server.registerTool, calls sessionStore.list() to return all active sessions as JSON.
    server.registerTool(
      "listSessions",
      {
        title: "List Sessions",
        description: listSessionsDescription,
        inputSchema: {},
        annotations: listSessionsAnnotations,
      },
      async () => {
        const start = Date.now();
        const sessions = sessionStore.list();
        return {
          content: [{ type: "text" as const, text: JSON.stringify(sessions, null, 2) }],
          _meta: buildMeta({ durationMs: Date.now() - start }),
        };
      },
    );
  • Annotations/schema metadata for listSessions: readOnlyHint=true, destructiveHint=false, idempotentHint=true, openWorldHint=false.
    export const listSessionsAnnotations: ToolAnnotations = {
      readOnlyHint: true,
      destructiveHint: false,
      idempotentHint: true,
      openWorldHint: false,
    };
  • SessionStore.list() helper: returns all active sessions sorted by lastUsedAt descending. Called by the handler.
    list(): SessionEntry[] {
      this.evictExpired();
      return Array.from(this.store.values())
        .map((e) => ({ ...e }))
        .sort((a, b) => b.lastUsedAt - a.lastUsedAt);
    }
  • Global SessionStore singleton used by listSessions.
    /** Global session store singleton. */
    export const sessionStore = new SessionStore();
  • src/index.ts:296-312 (registration)
    Registration of 'listSessions' tool with name, title, description, empty inputSchema, and annotations.
    server.registerTool(
      "listSessions",
      {
        title: "List Sessions",
        description: listSessionsDescription,
        inputSchema: {},
        annotations: listSessionsAnnotations,
      },
      async () => {
        const start = Date.now();
        const sessions = sessionStore.list();
        return {
          content: [{ type: "text" as const, text: JSON.stringify(sessions, null, 2) }],
          _meta: buildMeta({ durationMs: Date.now() - start }),
        };
      },
    );
Behavior4/5

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

Annotations already signal readOnly and idempotent. Description adds 'No cost (local lookup only)', clarifying behavior beyond annotations.

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?

Three sentences, front-loaded with purpose, no redundant information. Each sentence contributes unique value.

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

Completeness5/5

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

Covers purpose, return content, usage context, and cost. No output schema, so description fully compensates. All necessary information present.

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?

No parameters exist, so schema coverage is 100%. Baseline 3 applies; description adds value by listing return fields but not required.

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

Purpose5/5

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

Description clearly states 'List active Claude CLI sessions' with specific resource and verb. It distinguishes from siblings like search and query by focusing on sessions tracked by this server, making it unique.

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

Usage Guidelines4/5

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

Provides explicit usage guidance: 'Use to check available sessions before resuming with sessionId.' Does not state when not to use, but context is clear enough.

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/hampsterx/claude-mcp-bridge'

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