Skip to main content
Glama
dambinhtu-nhuy

claude-code-session-mcp

claude-code-session-mcp

An MCP server that lets Claude answer questions about your own Claude Code history, from the transcripts already sitting on your disk.

Three tools, all read-only. Ask "which projects did I work on last week", "what was the long session on Tuesday", "how much of this month was reading versus editing", and the model reaches for them on its own.

Claude Code calling tool_usage on this server and summarising the result

Nothing in that screenshot is staged. The question is one line of English, the model picked tool_usage on its own and filled in project, since and until from the wording, the JSON is exactly what the server returned, and the table is the model's own summary of it. Two more runs, with the tool calls copied out of the transcripts Claude Code wrote for them, are in assets/real-run.md.

It counts, it does not read back

Claude Code transcripts contain everything you ever typed into it. A server that hands those back to a model is a liability, so this one is built the other way round: it reads the message text in order to count things, and returns only the counts. Prompts, replies and tool arguments never leave the process.

That is a claim worth testing rather than trusting. The fixtures carry a canary string in a prompt, in an assistant reply, and inside a tool argument, and two tests fail if it ever appears in an output: one on the reading layer, one on the far side of the protocol, checking the bytes that actually crossed the wire.

Related MCP server: cc-session-search

The three tools

Tool

Answers

Arguments

list_sessions

What happened, and when

project, since, until, limit

session_stats

Everything about one session

session_id

tool_usage

Which tools, how often

project, since, until

Every session carries its project, time span, turn and prompt counts, subagent turns, per-model token usage split into input, output, cache read and cache write, a tally of tool calls by name, and a count of damaged lines.

Install

git clone https://github.com/dambinhtu-nhuy/claude-code-session-mcp
cd claude-code-session-mcp
npm install
npm test

Claude Code

claude mcp add session-history -- node /absolute/path/to/server.mjs

Or drop this in .mcp.json at the root of a project:

{
  "mcpServers": {
    "session-history": {
      "command": "node",
      "args": ["/absolute/path/to/server.mjs"]
    }
  }
}

mcp-config.json in the repo root is that same block with a relative path, for passing to claude --mcp-config while standing in this directory, which is how the runs in assets/real-run.md were driven. Relative paths only resolve from the repo root, so use the absolute form above for a real install.

Claude Desktop

Same block, in claude_desktop_config.json:

  • macOS ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows %APPDATA%\Claude\claude_desktop_config.json

Restart the app afterwards. Claude Desktop only reads the config at startup.

Trying it without exposing anything

Point the server at the fixtures instead of your real history:

CLAUDE_PROJECTS_DIR=./sample/projects node server.mjs

CLAUDE_PROJECTS_DIR overrides the default of ~/.claude/projects. The test suite uses it so no test ever touches a real session.

How it works

sessions.mjs  reads the .jsonl transcripts, returns counts     no MCP, no model
server.mjs    declares three tools, speaks stdio               no logic

The split is the point. All the counting lives in plain functions that take a string and return an object, which is why it can be tested against fixtures without a client, a network, or a model in the loop.

Two things are worth knowing if you are reading the code:

Cache tokens are reported two different ways depending on the client version, either a flat cache_creation_input_tokens or a breakdown by TTL under cache_creation. Reading only one of them silently undercounts.

A truncated last line is normal, because a live session is being appended to while you read it. Damaged lines are counted and reported rather than thrown, so one bad byte never hides a whole session, and the count tells you when a number is standing on incomplete data.

Tested

26 tests, 26 pass

test/sessions.test.mjs   19  the reading layer, against fixtures
test/protocol.test.mjs    7  a real MCP client, over stdio, spawning server.mjs

The protocol tests are the ones that matter for "does this work". They start server.mjs as a child process, speak MCP to it, list the tools, call all three, send a deliberately malformed argument, and confirm the server rejects it by schema and is still answering afterwards.

Measured against a real transcript directory: 326 sessions, 27,392 assistant turns, 0 damaged lines, read in 1.9 seconds.

Limits worth stating

  • Read-only by design. There is no tool here that writes, moves or deletes anything.

  • Session content is not exposed and will not be added. If you want a model to read your old conversations back, this is the wrong tool.

  • Project names come from Claude Code, which derives them from the working directory with separators replaced by dashes, so c:\dev\myapp becomes c--dev-myapp. There is no lookup back to the original path.

  • Sessions are grouped by their start day. One that runs past midnight counts on the day it began.

License

MIT.

Available Tools

3 tools
list_sessionsList Claude Code sessionsA
Read-only

List past Claude Code sessions, newest first, with the project, time span, number of turns and prompts, per-model token usage and a tally of which tools were called. Use it to answer questions like which projects were worked on last week or which session was the long one. Returns counts only, never the text of any message.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum sessions to return, newest first.
sinceNoEarliest day to include, YYYY-MM-DD, inclusive.
untilNoLatest day to include, YYYY-MM-DD, inclusive.
projectNoOnly this project. Claude Code names it after the working directory with separators replaced by dashes, for example c--dev-myapp.

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true, and the description adds a key behavioral constraint: returns only counts, never message content. This goes beyond the annotation by clarifying the data privacy boundary, which is valuable for an agent deciding whether to use this tool.

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?

Two sentences, front-loaded with the action and result contents, followed by usage examples and a boundary statement. Every sentence earns its place with no redundancy or fluff.

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

Completeness4/5

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

The description is complete for a read-only list tool, covering the return shape and privacy boundary. It lacks an explicit note on defaults (e.g., limit behavior) but given the schema documents all parameters and no output schema exists, the description provides sufficient context for an agent to use the tool effectively.

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 all parameters (limit, since, until, project) are already documented. The description adds no additional parameter-level meaning beyond what the schema provides, so a baseline score of 3 is appropriate.

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?

The description clearly states the tool lists past Claude Code sessions with specific attributes (newest first, project, time span, turns, prompts, token usage, tool tally). This distinguishes it from siblings like session_stats and tool_usage by focusing on session listing rather than aggregate stats or tool usage alone.

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 concrete use cases ('which projects were worked on last week or which session was the long one') and clarifies what the tool does not return ('never the text of any message'). While it doesn't explicitly mention when to use sibling tools instead, the guidance is sufficient for typical use.

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

session_statsRead one session in detailA
Read-only

Full counts for a single session id: duration in seconds, turns, prompts, subagent turns, damaged lines, per-model token usage and the combined totals. Take the id from list_sessions. Returns counts only, never the text of any message.

ParametersJSON Schema
NameRequiredDescriptionDefault
session_idYesThe session id, which is the transcript filename without the .jsonl suffix.

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true, so the read-only nature is covered. The description adds valuable context that it returns counts only and never message text, clarifying privacy and data handling beyond the annotations. No contradiction with 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?

Two concise sentences pack all essential information: content of the return value, source for the parameter, and an explicit exclusion. There is no wasteful or repetitive text.

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?

For a simple one-parameter tool with no output schema, the description fully enumerates the return fields (duration, turns, prompts, token usage, etc.) and behavior. It is complete given the tool's complexity.

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

Parameters4/5

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

Schema coverage is 100% and the schema already explains session_id as a transcript filename without .jsonl. The description adds 'Take the id from list_sessions', which is extra guidance on how to obtain the correct value, raising it above the baseline of 3.

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?

The description uses a specific verb ('Read') and identifies a unique resource ('one session') with a detailed list of what counts are included. It clearly distinguishes itself from list_sessions (which lists sessions) and tool_usage (broader usage stats).

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?

It instructs the agent to take the id from list_sessions, giving a direct prerequisite workflow. It also sets an explicit boundary by stating 'never the text of any message', helping the agent decide when not to use it. It doesn't explicitly name alternative tools for when not to use, but the guidance is clear.

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

tool_usageTally tool calls across sessionsA
Read-only

Count how often each Claude Code tool (Read, Edit, Bash, Grep and the rest) was called across the sessions matching the filters, most used first. Use it to answer questions about working habits, such as how much of a week was reading versus editing. Returns tool names and counts, never tool arguments.

ParametersJSON Schema
NameRequiredDescriptionDefault
sinceNoEarliest day to include, YYYY-MM-DD, inclusive.
untilNoLatest day to include, YYYY-MM-DD, inclusive.
projectNoOnly this project. Claude Code names it after the working directory with separators replaced by dashes, for example c--dev-myapp.

TDQS

A4.3/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true, and the description goes further by specifying return details: tool names and counts, ordering, and the guarantee that tool arguments are never included. It does not contradict annotations and adds privacy-relevant behavioral context beyond the structured fields.

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, all substantive: first sentence states the aggregation and ordering, second gives the usage scenario, third explains the output and a privacy boundary. No filler or repetition.

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?

With no output schema, the description appropriately discloses the return shape (tool names and counts, no arguments), ordering, and the type of questions it answers. For a simple aggregation tool with well-described optional filters and read-only semantics, this is sufficient to select and invoke correctly.

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 each parameter (since, until, project) clearly documented in the schema. The description only refers generically to 'filters' and adds no new parameter-level information, so it meets the baseline of 3 without surpassing it.

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?

The description clearly identifies the action (count), the resource (Claude Code tool calls across sessions), the output ordering (most used first), and the specific filtering context. The examples of tools and the intent (working habits) distinguish it from sibling tools that list sessions or provide session-level stats.

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?

The description explicitly states the intended use case: answering questions about working habits, with a concrete example (reading versus editing). It does not, however, mention when not to use it or point to list_sessions/session_stats as alternatives, so it stops short of explicit exclusion guidance.

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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv1.0.0
    • First observedlist_sessions
    • First observedsession_stats
    • First observedtool_usage

TDQS

A4.4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a distinctly separate purpose: list_sessions provides an overview for browsing, session_stats drills into a single session's aggregate counts, and tool_usage analyzes tool call frequencies across sessions. There is no overlap or ambiguity in what each tool returns.

Naming Consistency4/5

list_sessions follows a verb-noun pattern, while session_stats and tool_usage are noun-noun, but all use consistent snake_case and are immediately readable. The slight variation is predictable and does not cause confusion.

Tool Count5/5

With only three tools, the server is tightly scoped to session statistics and aggregation. This count is well within the ideal 3-15 range, and each tool serves a necessary, non-redundant function for the stated purpose.

Completeness5/5

The tool set fully covers the intended workflow: listing sessions, viewing detailed stats for a specific session, and aggregating tool usage across sessions. The deliberate omission of message content is consistent with the server's focus on counts, leaving no obvious gaps.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that enables users to retrieve, filter, and search through Claude Code conversation history stored in local projects. It provides tools for listing projects and sessions, paginating through message history, and searching across conversations with keyword filtering.
    4
    13
    11
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    Exposes analytics from Claude Code transcripts as MCP tools, enabling cost, audit, safety, and efficiency queries through natural language.
    4
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Enables search, analytics, and visualization of Claude Code sessions with MCP tools for session management, recovery, and insights.
    10
    1
    MIT