codebase-snapshot

· 5 min read · by

MCP server for a codebase

An MCP server for a codebase lets an AI client ask a local process for the few files, symbols or impact facts a question needs, instead of attaching the whole repository. codebase-snapshot ships one: seven tools (six read-only) over stdio or Streamable HTTP, a live index that sees uncommitted edits, and a persistent snapshot when you need a shared artefact.

The server is listed in the official MCP Registry as io.github.ankurhalder/codebase-snapshot. This guide covers what it exposes, how to wire it into Claude, Cursor, Claude Code or any generic MCP client, what it can read, and where its limits are.

Codebase Snapshot MCP server on mcprush

Why a local MCP server instead of a packed file

A packed file is a good first move: it is inspectable, portable and works in a chat that only accepts attachments. It has two costs. Every follow-up question either re-attaches the same file or starts a new conversation, and the copy is frozen at the moment it was written.

A local MCP server changes the interaction:

The trade-off is that the client must speak MCP. If it cannot, generate a snapshot and attach it.

Start the server

npx codebase-snapshot mcp

The server serves the directory it was started in. --cwd points it elsewhere; that directory is the only one it reads. Add --http to listen on loopback instead of stdio.

A generic client needs a command and arguments. The surrounding shape belongs to the client; this is the mcpServers form used by Claude Desktop and Cursor:

{
  "mcpServers": {
    "codebase-snapshot": {
      "command": "npx",
      "args": ["-y", "codebase-snapshot", "mcp", "--cwd", "/absolute/path/to/repo"]
    }
  }
}

Claude Code registers the same server from a shell:

claude mcp add codebase-snapshot -- npx -y codebase-snapshot mcp --cwd /absolute/path/to/repo

On Windows, wrap the command as cmd /c npx with the same arguments. npx is a .cmd shim there, and a client that spawns without a shell cannot execute it directly.

The seven tools

Tool Cost Answers
snapshot_impact medium What a change reaches: changed files, symbol-pruned importers, routes, candidate tests, cycles
snapshot_context medium The minimum redacted, line-numbered context for a question or file list inside a token budget
snapshot_locate cheap Paths, symbols, routes, entrypoints or bounded redacted text in one call
snapshot_read medium A line window of one redacted file, never a sensitive path
snapshot_validate cheap Status, drift, or an integrity and secret audit of the persisted snapshot
snapshot_explain expensive Why a path is included, excluded, sensitive, ignored, binary or truncated
snapshot_generate expensive Write a snapshot, or preview one with dryRun: true. The only writable tool

Six tools are declared readOnlyHint, which most clients use to run them without asking. The full schemas, cost classes and example calls are in the MCP tool reference.

What a call looks like

A question about a change, with candidate tests:

{
  "name": "snapshot_impact",
  "arguments": {
    "paths": ["src/impact.ts"],
    "includeCycles": true,
    "includeSnippets": true
  }
}

A bounded reading list before a task:

{
  "name": "snapshot_context",
  "arguments": {
    "question": "how does impact pruning work",
    "maxTokens": 12000,
    "linesPerFile": 100
  }
}

A read of one file:

{
  "name": "snapshot_read",
  "arguments": { "path": "src/impact.ts", "fromLine": 1, "lines": 120 }
}

Live index versus persisted snapshot

Read-only tools are live by default. They reuse a current manifest.json, overlay changed and new files in memory when the tree has moved, or scan the confined working tree when no snapshot exists. They never write into the repository. Pass "live": false to require the persisted snapshot; the trust envelope then says freshness is unknown rather than claiming the file is current.

This distinction matters for agents. A stale persisted snapshot is still useful if the client knows it is stale; it is dangerous if the envelope says current. The server only claims current when it has compared the tree, which is what snapshot_validate drift mode is for.

Large repositories and monorepos

The server bounds its own work. A text search stops at 4 MiB; a TypeScript compiler pass stops at 2,500 files and four seconds; a resource above 512 KiB is refused rather than truncated. When a cap is hit, the response says so in trust.reasons or in the precise coverage field.

For a monorepo, point --cwd at the member that contains the code you are asking about, or generate a workspace snapshot and pass its outDir. A workspace run writes one snapshot per member plus a WORKSPACE.json index. The MCP server does not silently merge members: a tool call names the repository it serves.

Security boundary

The full threat model, including the residual risks (executable configs, DNS rebinding, prompt injection inside repository content), is in the security review.

Limits and when not to use it

If you need a single portable artefact, use generate. If you need a live question-answer loop and your client supports MCP, use the server. Most teams use both.