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.
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 client asks for one file, symbol or impact report instead of receiving all of them.
- The index is live by default: changed files are overlaid in memory, new files are indexed, and a repository with no snapshot is scanned without writing one.
- Responses are bounded: a read is capped at 64 KiB, a resource at 512 KiB, a tool result at 64 KiB, and a text search at 4 MiB.
- Every structured response carries a trust envelope naming the source, freshness, coverage, redaction count and any reason the answer is partial.
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 server reads only the directories it was started with. The
roottool argument selects one of them; a path outside them is refused. There is no CLI--rootflag. - Sensitive paths are never readable through snapshot_read, even when they exist on disk.
- A snapshot generated with --include-sensitive-files is refused by the MCP transport and by serve.
- HTTP binds loopback by default, requires a bearer token for /api and generates one on first run. A non-loopback bind without a token is refused.
- Remote ingestion is HTTPS-only, refuses private addresses and does not follow redirects.
- Secrets are redacted in emitted parts and checked again by the audit.
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
- The client must speak MCP. A chat that only accepts attachments cannot use the server.
- Heuristic languages. TypeScript and JavaScript get the deepest symbol support; the other language profiles classify and index but do not promise compiler-grade references.
- No write tools beyond generate. The server cannot edit, refactor or run tests; it is a read-and-generate surface.
- Not a code graph. It follows imports and declaration spans, not a semantic graph of every relationship. The impact report says where it is conservative.
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.
Related
- MCP tools reference — every schema and example call
- MCP protocol details — transports, sessions, headers and limits
- LLM codebase context — the broader guide
- All documentation