Skip to main content
Glama
es6kr
by es6kr

list_sessions

Retrieve all Claude Code conversation sessions within a specified project to manage and review ongoing discussions.

Instructions

List all sessions in a project

Input Schema

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

Implementation Reference

  • MCP tool handler for 'list_sessions': invokes session.listSessions(project_name) and returns the result as formatted JSON text content.
    async ({ project_name }) => {
      const result = await Effect.runPromise(session.listSessions(project_name))
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      }
    }
  • Zod input schema defining the 'project_name' parameter for the list_sessions tool.
    {
      project_name: z.string().describe("Project folder name (e.g., '-Users-young-works-myproject')"),
    },
  • src/mcp/index.ts:23-35 (registration)
    Registration of the 'list_sessions' tool on the McpServer instance.
    server.tool(
      'list_sessions',
      'List all sessions in a project',
      {
        project_name: z.string().describe("Project folder name (e.g., '-Users-young-works-myproject')"),
      },
      async ({ project_name }) => {
        const result = await Effect.runPromise(session.listSessions(project_name))
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        }
      }
    )
  • Core implementation of listSessions: reads session files in a project directory, parses messages, extracts metadata (title from first human message, counts, timestamps), returns array of SessionMeta objects.
    export const listSessions = (projectName: string) =>
      Effect.gen(function* () {
        const projectPath = path.join(getSessionsDir(), projectName)
        const files = yield* Effect.tryPromise(() => fs.readdir(projectPath))
        const sessionFiles = files.filter((f) => f.endsWith('.jsonl'))
    
        const sessions = yield* Effect.all(
          sessionFiles.map((file) =>
            Effect.gen(function* () {
              const filePath = path.join(projectPath, file)
              const content = yield* Effect.tryPromise(() => fs.readFile(filePath, 'utf-8'))
              const lines = content.trim().split('\n').filter(Boolean)
              const messages = lines.map((line) => JSON.parse(line) as Message)
    
              const sessionId = file.replace('.jsonl', '')
              const firstMessage = messages[0]
              const lastMessage = messages[messages.length - 1]
    
              // Extract title from first user message
              const title = pipe(
                messages,
                A.findFirst((m) => m.type === 'human'),
                O.map((m) => {
                  const msg = m.message as { content?: string } | undefined
                  const content = msg?.content ?? ''
                  return content.slice(0, 50) + (content.length > 50 ? '...' : '')
                }),
                O.getOrElse(() => 'Untitled')
              )
    
              return {
                id: sessionId,
                projectName,
                title,
                messageCount: messages.length,
                createdAt: firstMessage?.timestamp,
                updatedAt: lastMessage?.timestamp,
              } satisfies SessionMeta
            })
          ),
          { concurrency: 10 }
        )
    
        return sessions
      })
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'List' implies a read-only operation, the description doesn't address permissions, pagination, rate limits, or what constitutes a 'session' in this context. It lacks behavioral details needed for safe invocation.

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, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with zero wasted content.

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 with behavioral implications. It doesn't explain what a 'session' is, how results are returned, or any constraints, leaving significant gaps for the agent to navigate.

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%, with the single parameter 'project_name' fully documented in the schema. The description doesn't add any parameter semantics beyond what the schema provides, so it meets the baseline for high schema coverage without compensating 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 all sessions') and resource ('in a project'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'list_projects' or 'get_session_files' beyond the obvious scope difference.

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?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites, context for usage, or exclusions, leaving the agent to infer usage from the tool name alone.

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-sessions-mcp'

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