List Sessions
listSessionsList active Claude CLI sessions tracked by the server, returning session metadata including IDs, models, timing, turn counts, and cumulative cost. Use to check available sessions before resuming with a sessionId. No cost, local lookup only.
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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:296-311 (handler)Handler function for the listSessions tool. Calls sessionStore.list() and returns the JSON-formatted list of active sessions with metadata.
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 }), }; }, - src/index.ts:296-312 (registration)Registration of the listSessions tool on the MCP server with title, description, 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 }), }; }, ); - src/index.ts:301-302 (schema)Input schema is empty (no input parameters needed) for listSessions.
inputSchema: {}, annotations: listSessionsAnnotations, - src/utils/session.ts:79-84 (helper)SessionStore.list() method that returns all active sessions sorted by lastUsedAt descending (most recent first), after evicting expired entries.
list(): SessionEntry[] { this.evictExpired(); return Array.from(this.store.values()) .map((e) => ({ ...e })) .sort((a, b) => b.lastUsedAt - a.lastUsedAt); } - src/annotations.ts:37-42 (helper)Annotations for listSessions: read-only, non-destructive, idempotent, closed-world (purely local, no side effects).
export const listSessionsAnnotations: ToolAnnotations = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, };