codebase-snapshot 0.20.13 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -6
- package/README.md +46 -19
- package/SECURITY.md +2 -2
- package/dist/bin.js +14535 -12036
- package/dist/{chunk-GNVRD7XS.js → chunk-NPCDJBE4.js} +6097 -4425
- package/dist/cli.cjs +11184 -8708
- package/dist/cli.d.cts +94 -2
- package/dist/cli.d.ts +94 -2
- package/dist/cli.js +944 -95
- package/dist/{generate-worker-DMzNbsAW.d.cts → generate-worker-BUNhTXkj.d.cts} +2 -2
- package/dist/{generate-worker-CRMESc0b.d.ts → generate-worker-TUMvHlgz.d.ts} +2 -2
- package/dist/index.cjs +6073 -4423
- package/dist/index.d.cts +281 -63
- package/dist/index.d.ts +281 -63
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +10240 -4315
- package/dist/mcp.d.cts +13 -7
- package/dist/mcp.d.ts +13 -7
- package/dist/mcp.js +1 -1
- package/dist/{types-C5ytHMYz.d.ts → types-DQXKiaXk.d.cts} +50 -2
- package/dist/{types-C5ytHMYz.d.cts → types-DQXKiaXk.d.ts} +50 -2
- package/docs/about.md +86 -0
- package/docs/agent.md +28 -6
- package/docs/answer.md +99 -48
- package/docs/benchmarks.md +34 -34
- package/docs/brief.md +80 -81
- package/docs/cli.md +126 -25
- package/docs/codebase-token-budget.md +14 -13
- package/docs/contents.md +68 -0
- package/docs/deploy.md +2 -2
- package/docs/faq.md +112 -0
- package/docs/glossary.md +152 -0
- package/docs/guard.md +154 -0
- package/docs/health.md +1 -1
- package/docs/how-to-feed-a-repo-to-claude.md +6 -0
- package/docs/impact.md +102 -0
- package/docs/install.md +4 -3
- package/docs/llm-codebase-context.md +166 -0
- package/docs/mcp-server-for-codebase.md +163 -0
- package/docs/mcp.md +48 -67
- package/docs/migration.md +83 -90
- package/docs/output.md +1 -3
- package/docs/security-review.md +8 -8
- package/docs/slice.md +1 -1
- package/docs/tools.md +159 -185
- package/docs/troubleshooting.md +11 -11
- package/docs/vs-code2prompt.md +7 -0
- package/docs/vs-gitingest.md +7 -0
- package/docs/vs-repomix.md +10 -1
- package/docs/workspace.md +1 -1
- package/package.json +8 -2
package/docs/install.md
CHANGED
|
@@ -115,9 +115,10 @@ it exists — run:
|
|
|
115
115
|
npx codebase-snapshot skill --install
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
That writes `.
|
|
119
|
-
`.cursor/rules/codebase-snapshot.mdc`, and adds
|
|
120
|
-
|
|
118
|
+
That writes `.agents/skills/codebase-snapshot/SKILL.md`,
|
|
119
|
+
`.claude/skills/codebase-snapshot/SKILL.md` and `.cursor/rules/codebase-snapshot.mdc`, and adds
|
|
120
|
+
all three to `.gitignore` so the install leaves nothing untracked. Add `--with-mcp` to merge a
|
|
121
|
+
server entry into `.mcp.json`. It does not touch `AGENTS.md`: that file is your project's own agent
|
|
121
122
|
contract. To put the skill there, print it and paste it —
|
|
122
123
|
`npx codebase-snapshot skill >> AGENTS.md`. See
|
|
123
124
|
[Using this with an AI agent](agent.md).
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# LLM codebase context, explained
|
|
2
|
+
|
|
3
|
+
**LLM codebase context is the part of a repository a model is allowed to see when it answers a
|
|
4
|
+
question about that repository.** It has to be selected, bounded, readable and current. Copying
|
|
5
|
+
every file into a prompt is the simplest version, and usually the worst one: it spends the context
|
|
6
|
+
window on files the question never needed and gives the model no way to tell whether the copy is
|
|
7
|
+
stale.
|
|
8
|
+
|
|
9
|
+
This guide covers what "codebase context" means, why raw dumps fail, the four practical approaches,
|
|
10
|
+
and a repeatable way to build context with codebase-snapshot.
|
|
11
|
+
|
|
12
|
+
## What is LLM codebase context?
|
|
13
|
+
|
|
14
|
+
A model has no ambient access to your repository. Everything it knows about the code arrives in the
|
|
15
|
+
request: the system prompt, the conversation, and whatever files or retrieval results the client
|
|
16
|
+
attaches. That attached material is the codebase context.
|
|
17
|
+
|
|
18
|
+
Good codebase context has four properties:
|
|
19
|
+
|
|
20
|
+
- **Relevant.** It contains the files and symbols that can answer the question.
|
|
21
|
+
- **Bounded.** It fits the window with room for instructions and a reply.
|
|
22
|
+
- **Attributable.** The model can name the file and line a claim came from.
|
|
23
|
+
- **Current.** It is possible to tell whether the context still matches the working tree.
|
|
24
|
+
|
|
25
|
+
A codebase snapshot is one way to produce all four at once. It is not the only way, and it is not
|
|
26
|
+
always the right way. A small bug in one file is better handled by opening the file than by packing
|
|
27
|
+
the repository.
|
|
28
|
+
|
|
29
|
+
## Why a raw codebase dump fails
|
|
30
|
+
|
|
31
|
+
The arithmetic is unforgiving. A token is roughly 3.5 bytes of source code, so a 1 MB repository is
|
|
32
|
+
about 285,000 tokens before any instructions. A 128k window cannot hold it; a 200k window can hold
|
|
33
|
+
the code but not much of a conversation. Real applications are five to twenty times larger than a
|
|
34
|
+
small library.
|
|
35
|
+
|
|
36
|
+
The failure is not only size. A dump is usually:
|
|
37
|
+
|
|
38
|
+
1. **Unfiltered.** Vendored dependencies, generated files, lockfiles and test fixtures ride along
|
|
39
|
+
because the packer copies what it finds.
|
|
40
|
+
2. **Undifferentiated.** The model sees every file with the same weight. The one module the
|
|
41
|
+
question depends on is buried among hundreds that are irrelevant.
|
|
42
|
+
3. **Unaccounted.** A packer that silently skips or truncates a file leaves the model unaware that
|
|
43
|
+
its picture has a hole. The answer sounds complete and is not.
|
|
44
|
+
4. **Undated.** The model cannot know whether the snapshot was generated five minutes or five
|
|
45
|
+
months ago. A stale snapshot is worse than no snapshot because it reads as current.
|
|
46
|
+
|
|
47
|
+
The tooling answer is not "write a better prompt". It is to produce a smaller, indexed artefact and
|
|
48
|
+
to make freshness checkable.
|
|
49
|
+
|
|
50
|
+
## Four ways to give a model codebase context
|
|
51
|
+
|
|
52
|
+
| Approach | What it is good at | Where it breaks |
|
|
53
|
+
| :-- | :-- | :-- |
|
|
54
|
+
| Paste files by hand | One file or one symbol; complete control | Does not scale past a handful of files; easy to miss a caller |
|
|
55
|
+
| Pack the repository | A stable artefact attached to one conversation; offline and inspectable | Size; stale copies; no principled choice of what matters |
|
|
56
|
+
| Bounded retrieval over a local index (MCP) | A question answered from the few files that matter; live edits | Needs a client that speaks MCP; the index has to be built |
|
|
57
|
+
| Code graph or embedding index | Cross-repo and semantic questions at scale | Infrastructure, embeddings and a server; overkill for one repository |
|
|
58
|
+
|
|
59
|
+
Most teams end up combining the second and third: a packed snapshot for a first, broad review, and
|
|
60
|
+
a live MCP server for follow-up questions. The rest of this page shows the packed route, because it
|
|
61
|
+
is the one that works in a fresh clone and in any chat client that accepts attachments.
|
|
62
|
+
|
|
63
|
+
## Build codebase context with codebase-snapshot
|
|
64
|
+
|
|
65
|
+
### 1. Generate the snapshot
|
|
66
|
+
|
|
67
|
+
npx codebase-snapshot generate
|
|
68
|
+
|
|
69
|
+
The default writes ./snapshot with Markdown parts, a manifest, a prompt and reports. The run is
|
|
70
|
+
deterministic: unchanged input produces byte-identical parts and the same fingerprint. The parts
|
|
71
|
+
never exceed the configured byte budget.
|
|
72
|
+
|
|
73
|
+
### 2. Read the prompt before the parts
|
|
74
|
+
|
|
75
|
+
PROMPT.md states the fingerprint, the commit, the parts, what was left out and how to attach the
|
|
76
|
+
files. Paste it as the first message. It is the instruction sheet that turns a pile of Markdown into
|
|
77
|
+
context the model can use.
|
|
78
|
+
|
|
79
|
+
### 3. Attach only what fits
|
|
80
|
+
|
|
81
|
+
A hosted chat often accepts ten files. A 12-part snapshot cannot be delivered whole. Either raise
|
|
82
|
+
--max-part-bytes so the same content becomes fewer parts, or scope the run with include/exclude
|
|
83
|
+
patterns to the directories the question is about. The prompt's delivery section does the
|
|
84
|
+
arithmetic for the current run.
|
|
85
|
+
|
|
86
|
+
### 4. Ask a bounded question
|
|
87
|
+
|
|
88
|
+
"Using the attached snapshot, trace how authentication reaches the database. Cite the file and line
|
|
89
|
+
for each hop; if the answer is not in the attached files, say what is missing." The second clause is
|
|
90
|
+
what stops a model from filling a gap with a plausible invention.
|
|
91
|
+
|
|
92
|
+
### 5. Validate before reusing the context
|
|
93
|
+
|
|
94
|
+
npx codebase-snapshot validate
|
|
95
|
+
|
|
96
|
+
validate re-hashes the tree and exits non-zero on drift. Put it in CI or a pre-commit hook. When it
|
|
97
|
+
fails, regenerate; do not keep asking questions against a snapshot that no longer describes the
|
|
98
|
+
code.
|
|
99
|
+
|
|
100
|
+
For a live alternative, run the MCP server and let the client call the tools:
|
|
101
|
+
|
|
102
|
+
npx codebase-snapshot mcp
|
|
103
|
+
|
|
104
|
+
The read tools use the working tree by default, so an uncommitted edit is visible without a
|
|
105
|
+
regeneration. See [MCP server for a codebase](mcp-server-for-codebase.md).
|
|
106
|
+
|
|
107
|
+
## How much codebase context fits?
|
|
108
|
+
|
|
109
|
+
Use the destination, not the tool's default. The snapshot budget should leave room for the system
|
|
110
|
+
prompt, the question and the reply.
|
|
111
|
+
|
|
112
|
+
| Window | Practical context ceiling | What that means |
|
|
113
|
+
| :-- | --: | :-- |
|
|
114
|
+
| 32k | ~20k tokens | One small module or a slice, not a repository |
|
|
115
|
+
| 128k | ~80k tokens | One 300 KB part, or a scoped folder |
|
|
116
|
+
| 200k | ~130k tokens | Two or three parts, or a larger slice |
|
|
117
|
+
| 1M | ~700k tokens | A medium repository whole, with room for analysis |
|
|
118
|
+
|
|
119
|
+
The estimates are conservative on purpose. A 128k window filled to 120k leaves no space for a
|
|
120
|
+
useful answer, and models often perform worse when the relevant material is diluted.
|
|
121
|
+
|
|
122
|
+
## Keep context current
|
|
123
|
+
|
|
124
|
+
A snapshot is a moment, not a subscription. The repository moves; the file on disk does not. The
|
|
125
|
+
controls that make freshness visible are:
|
|
126
|
+
|
|
127
|
+
- **Fingerprint.** The manifest records a content fingerprint; two runs over the same input agree.
|
|
128
|
+
- **Validate.** The command compares the snapshot with the tree and exits non-zero on drift.
|
|
129
|
+
- **Git state.** The manifest records the branch, commit and dirty state at generation time.
|
|
130
|
+
- **Live index.** The MCP read tools overlay uncommitted edits and new files, and say so in a trust
|
|
131
|
+
envelope.
|
|
132
|
+
|
|
133
|
+
Read [Stale context is your bug](stale-context-is-your-bug.md) for the CI pattern.
|
|
134
|
+
|
|
135
|
+
## What leaves the repository?
|
|
136
|
+
|
|
137
|
+
The CLI and the MCP server run locally. There is no account, upload or telemetry. Generated
|
|
138
|
+
artifacts contain redacted source, not your credentials: sensitive paths are excluded by default,
|
|
139
|
+
and secret-shaped values in ordinary files are replaced with a marker. The audit report names the
|
|
140
|
+
file and line but not the value.
|
|
141
|
+
|
|
142
|
+
Redaction is not a guarantee. If you need a formal data-handling statement, read the
|
|
143
|
+
[security review](security-review.md), which lists the residual risks instead of hiding them.
|
|
144
|
+
|
|
145
|
+
## How to choose a codebase context tool
|
|
146
|
+
|
|
147
|
+
Ask five questions:
|
|
148
|
+
|
|
149
|
+
1. **Does it fit the destination?** A tool that produces one 40 MB file has not solved the
|
|
150
|
+
attachment problem.
|
|
151
|
+
2. **Does it account for omissions?** Every skipped or shortened file should have a reason.
|
|
152
|
+
3. **Can it prove freshness?** A hash or a validate command, not a promise.
|
|
153
|
+
4. **Does it handle secrets?** Default exclusions, span redaction and an audit.
|
|
154
|
+
5. **Can an agent use it without a human?** A machine-readable contract and bounded tools, or at
|
|
155
|
+
least static pages it can fetch.
|
|
156
|
+
|
|
157
|
+
Those five questions are also the design brief for codebase-snapshot. The comparisons with
|
|
158
|
+
[repomix](vs-repomix.md), [gitingest](vs-gitingest.md) and [code2prompt](vs-code2prompt.md) apply the
|
|
159
|
+
same questions honestly.
|
|
160
|
+
|
|
161
|
+
## Related
|
|
162
|
+
|
|
163
|
+
- [How to feed a repository to Claude or ChatGPT](how-to-feed-a-repo-to-claude.md)
|
|
164
|
+
- [How many tokens is a codebase?](codebase-token-budget.md)
|
|
165
|
+
- [Budgeting LLM context](how-to-context-budget.md)
|
|
166
|
+
- [All documentation](contents.md)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# MCP server for a codebase
|
|
2
|
+
|
|
3
|
+
**An MCP server for a codebase lets an AI client ask a local process for the few files, symbols or
|
|
4
|
+
impact facts a question needs, instead of attaching the whole repository.** codebase-snapshot ships
|
|
5
|
+
one: seven tools (six read-only) over stdio or Streamable HTTP, a live index that sees uncommitted
|
|
6
|
+
edits, and a persistent snapshot when you need a shared artefact.
|
|
7
|
+
|
|
8
|
+
The server is listed in the official MCP Registry as
|
|
9
|
+
[`io.github.ankurhalder/codebase-snapshot`](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.ankurhalder%2Fcodebase-snapshot).
|
|
10
|
+
This guide covers what it exposes, how to wire it into Claude, Cursor, Claude Code or any generic
|
|
11
|
+
MCP client, what it can read, and where its limits are.
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://mcprush.com/to/codebase-snapshot-mcp?ref=badge">
|
|
15
|
+
<img width="380" height="200" src="https://mcprush.com/badge/codebase-snapshot-mcp/card.svg" alt="Codebase Snapshot MCP server on mcprush">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
## Why a local MCP server instead of a packed file
|
|
20
|
+
|
|
21
|
+
A packed file is a good first move: it is inspectable, portable and works in a chat that only
|
|
22
|
+
accepts attachments. It has two costs. Every follow-up question either re-attaches the same file or
|
|
23
|
+
starts a new conversation, and the copy is frozen at the moment it was written.
|
|
24
|
+
|
|
25
|
+
A local MCP server changes the interaction:
|
|
26
|
+
|
|
27
|
+
- The client asks for **one** file, symbol or impact report instead of receiving all of them.
|
|
28
|
+
- The index is **live by default**: changed files are overlaid in memory, new files are indexed, and
|
|
29
|
+
a repository with no snapshot is scanned without writing one.
|
|
30
|
+
- Responses are **bounded**: a read is capped at 64 KiB, a resource at 512 KiB, a tool result at 64
|
|
31
|
+
KiB, and a text search at 4 MiB.
|
|
32
|
+
- Every structured response carries a **trust envelope** naming the source, freshness, coverage,
|
|
33
|
+
redaction count and any reason the answer is partial.
|
|
34
|
+
|
|
35
|
+
The trade-off is that the client must speak MCP. If it cannot, generate a snapshot and attach it.
|
|
36
|
+
|
|
37
|
+
## Start the server
|
|
38
|
+
|
|
39
|
+
npx codebase-snapshot mcp
|
|
40
|
+
|
|
41
|
+
The server serves the directory it was started in. --cwd points it elsewhere; that directory is the
|
|
42
|
+
only one it reads. Add --http to listen on loopback instead of stdio.
|
|
43
|
+
|
|
44
|
+
A generic client needs a command and arguments. The surrounding shape belongs to the client; this
|
|
45
|
+
is the mcpServers form used by Claude Desktop and Cursor:
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
"mcpServers": {
|
|
49
|
+
"codebase-snapshot": {
|
|
50
|
+
"command": "npx",
|
|
51
|
+
"args": ["-y", "codebase-snapshot", "mcp", "--cwd", "/absolute/path/to/repo"]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Claude Code registers the same server from a shell:
|
|
57
|
+
|
|
58
|
+
claude mcp add codebase-snapshot -- npx -y codebase-snapshot mcp --cwd /absolute/path/to/repo
|
|
59
|
+
|
|
60
|
+
On Windows, wrap the command as cmd /c npx with the same arguments. npx is a .cmd shim there, and a
|
|
61
|
+
client that spawns without a shell cannot execute it directly.
|
|
62
|
+
|
|
63
|
+
## The seven tools
|
|
64
|
+
|
|
65
|
+
| Tool | Cost | Answers |
|
|
66
|
+
| :-- | :-- | :-- |
|
|
67
|
+
| snapshot_impact | medium | What a change reaches: changed files, symbol-pruned importers, routes, candidate tests, cycles |
|
|
68
|
+
| snapshot_context | medium | The minimum redacted, line-numbered context for a question or file list inside a token budget |
|
|
69
|
+
| snapshot_locate | cheap | Paths, symbols, routes, entrypoints or bounded redacted text in one call |
|
|
70
|
+
| snapshot_read | medium | A line window of one redacted file, never a sensitive path |
|
|
71
|
+
| snapshot_validate | cheap | Status, drift, or an integrity and secret audit of the persisted snapshot |
|
|
72
|
+
| snapshot_explain | expensive | Why a path is included, excluded, sensitive, ignored, binary or truncated |
|
|
73
|
+
| snapshot_generate | expensive | Write a snapshot, or preview one with dryRun: true. The only writable tool |
|
|
74
|
+
|
|
75
|
+
Six tools are declared readOnlyHint, which most clients use to run them without asking. The full
|
|
76
|
+
schemas, cost classes and example calls are in the [MCP tool reference](tools.md).
|
|
77
|
+
|
|
78
|
+
## What a call looks like
|
|
79
|
+
|
|
80
|
+
A question about a change, with candidate tests:
|
|
81
|
+
|
|
82
|
+
{
|
|
83
|
+
"name": "snapshot_impact",
|
|
84
|
+
"arguments": {
|
|
85
|
+
"paths": ["src/impact.ts"],
|
|
86
|
+
"includeCycles": true,
|
|
87
|
+
"includeSnippets": true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
A bounded reading list before a task:
|
|
92
|
+
|
|
93
|
+
{
|
|
94
|
+
"name": "snapshot_context",
|
|
95
|
+
"arguments": {
|
|
96
|
+
"question": "how does impact pruning work",
|
|
97
|
+
"maxTokens": 12000,
|
|
98
|
+
"linesPerFile": 100
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
A read of one file:
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
"name": "snapshot_read",
|
|
106
|
+
"arguments": { "path": "src/impact.ts", "fromLine": 1, "lines": 120 }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
## Live index versus persisted snapshot
|
|
110
|
+
|
|
111
|
+
Read-only tools are live by default. They reuse a current manifest.json, overlay changed and new
|
|
112
|
+
files in memory when the tree has moved, or scan the confined working tree when no snapshot exists.
|
|
113
|
+
They never write into the repository. Pass "live": false to require the persisted snapshot; the
|
|
114
|
+
trust envelope then says freshness is unknown rather than claiming the file is current.
|
|
115
|
+
|
|
116
|
+
This distinction matters for agents. A stale persisted snapshot is still useful if the client knows
|
|
117
|
+
it is stale; it is dangerous if the envelope says current. The server only claims current when it
|
|
118
|
+
has compared the tree, which is what snapshot_validate drift mode is for.
|
|
119
|
+
|
|
120
|
+
## Large repositories and monorepos
|
|
121
|
+
|
|
122
|
+
The server bounds its own work. A text search stops at 4 MiB; a TypeScript compiler pass stops at
|
|
123
|
+
2,500 files and four seconds; a resource above 512 KiB is refused rather than truncated. When a cap
|
|
124
|
+
is hit, the response says so in trust.reasons or in the precise coverage field.
|
|
125
|
+
|
|
126
|
+
For a monorepo, point --cwd at the member that contains the code you are asking about, or generate a
|
|
127
|
+
workspace snapshot and pass its outDir. A workspace run writes one snapshot per member plus a
|
|
128
|
+
WORKSPACE.json index. The MCP server does not silently merge members: a tool call names the
|
|
129
|
+
repository it serves.
|
|
130
|
+
|
|
131
|
+
## Security boundary
|
|
132
|
+
|
|
133
|
+
- The server reads only the served root. --root can add directories explicitly; a path outside them
|
|
134
|
+
is refused.
|
|
135
|
+
- Sensitive paths are never readable through snapshot_read, even when they exist on disk.
|
|
136
|
+
- A snapshot generated with --include-sensitive-files is refused by the MCP transport and by serve.
|
|
137
|
+
- HTTP binds loopback by default, requires a bearer token for /api and generates one on first run.
|
|
138
|
+
A non-loopback bind without a token is refused.
|
|
139
|
+
- Remote ingestion is HTTPS-only, refuses private addresses and does not follow redirects.
|
|
140
|
+
- Secrets are redacted in emitted parts and checked again by the audit.
|
|
141
|
+
|
|
142
|
+
The full threat model, including the residual risks (executable configs, DNS rebinding, prompt
|
|
143
|
+
injection inside repository content), is in the [security review](security-review.md).
|
|
144
|
+
|
|
145
|
+
## Limits and when not to use it
|
|
146
|
+
|
|
147
|
+
- **The client must speak MCP.** A chat that only accepts attachments cannot use the server.
|
|
148
|
+
- **Heuristic languages.** TypeScript and JavaScript get the deepest symbol support; the other
|
|
149
|
+
language profiles classify and index but do not promise compiler-grade references.
|
|
150
|
+
- **No write tools beyond generate.** The server cannot edit, refactor or run tests; it is a
|
|
151
|
+
read-and-generate surface.
|
|
152
|
+
- **Not a code graph.** It follows imports and declaration spans, not a semantic graph of every
|
|
153
|
+
relationship. The impact report says where it is conservative.
|
|
154
|
+
|
|
155
|
+
If you need a single portable artefact, use generate. If you need a live question-answer loop and
|
|
156
|
+
your client supports MCP, use the server. Most teams use both.
|
|
157
|
+
|
|
158
|
+
## Related
|
|
159
|
+
|
|
160
|
+
- [MCP tools reference](tools.md) — every schema and example call
|
|
161
|
+
- [MCP protocol details](mcp.md) — transports, sessions, headers and limits
|
|
162
|
+
- [LLM codebase context](llm-codebase-context.md) — the broader guide
|
|
163
|
+
- [All documentation](contents.md)
|
package/docs/mcp.md
CHANGED
|
@@ -10,7 +10,7 @@ walk — that the client sees.
|
|
|
10
10
|
## Start it
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npx -y codebase-snapshot@0.
|
|
13
|
+
npx -y codebase-snapshot@0.22.0 mcp
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
The server serves the directory it was started in. `--cwd <path>` points it elsewhere, and that
|
|
@@ -25,7 +25,7 @@ Claude Desktop and Cursor:
|
|
|
25
25
|
"mcpServers": {
|
|
26
26
|
"codebase-snapshot": {
|
|
27
27
|
"command": "npx",
|
|
28
|
-
"args": ["-y", "codebase-snapshot@0.
|
|
28
|
+
"args": ["-y", "codebase-snapshot@0.22.0", "mcp", "--cwd", "/absolute/path/to/repo"]
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -34,7 +34,7 @@ Claude Desktop and Cursor:
|
|
|
34
34
|
Claude Code registers the same thing from a shell:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.
|
|
37
|
+
claude mcp add codebase-snapshot -- npx -y codebase-snapshot@0.22.0 mcp --cwd /absolute/path/to/repo
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
On Windows, wrap the command as `cmd /c npx` with the same arguments — `npx` is a `.cmd` shim
|
|
@@ -43,7 +43,7 @@ there, and clients that spawn without a shell cannot execute it directly.
|
|
|
43
43
|
## Over HTTP, for clients that cannot spawn a process
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
|
-
npx -y codebase-snapshot@0.
|
|
46
|
+
npx -y codebase-snapshot@0.22.0 mcp --http --port 4789
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
This is the Streamable HTTP shape: POST one JSON-RPC message to `/mcp` and read the JSON-RPC
|
|
@@ -51,7 +51,11 @@ answer from the response body. Modern (`2026-07-28`) requests must also carry
|
|
|
51
51
|
`MCP-Protocol-Version`, `Mcp-Method` and — for `tools/call`, `resources/read` and
|
|
52
52
|
`prompts/get` — `Mcp-Name`. A missing header, or one that disagrees with the body, is refused
|
|
53
53
|
with HTTP `400` and JSON-RPC `-32020` before dispatch; the CORS preflight allows all three
|
|
54
|
-
names.
|
|
54
|
+
names. Modern cacheable results (`server/discover`, `tools/list`, `prompts/list`,
|
|
55
|
+
`resources/list`, `resources/read`, `resources/templates/list`) also carry `ttlMs` and
|
|
56
|
+
`cacheScope`; this server sets `ttlMs` to `0` and `cacheScope` to `private`, so a regenerated
|
|
57
|
+
snapshot is never served from a stale shared cache. Legacy requests keep the session behaviour
|
|
58
|
+
below. `GET /healthz` answers
|
|
55
59
|
`{ ok, name, version, tools, uptimeSeconds }` without a token, and `GET /metrics` answers Prometheus
|
|
56
60
|
text: `snapshot_requests_total`, `snapshot_requests_by_method_total{method="…"}` (fixed labels,
|
|
57
61
|
never a path or a credential), `snapshot_requests_refused_total` (every 4xx except 429: an
|
|
@@ -110,57 +114,34 @@ into logs and is documented as such. A heartbeat every 15 s keeps the connection
|
|
|
110
114
|
shutdown ends the streams rather than waiting on them. Request bodies are capped at 2 MB, the rate is
|
|
111
115
|
capped at 60 requests per 10 seconds per address, and every response is one bounded JSON document.
|
|
112
116
|
|
|
113
|
-
## The
|
|
117
|
+
## The 7 tools
|
|
114
118
|
|
|
115
119
|
Each tool has an entry with a ready-to-send call in the [tool reference](tools.md).
|
|
116
120
|
|
|
117
|
-
|
|
118
121
|
Every tool states its cost class in `tools/list` as `_meta["codebase-snapshot/cost"]`: `cheap`
|
|
119
|
-
reads the
|
|
120
|
-
Two tools that answer the same question can differ by an order of magnitude, and a client choosing
|
|
121
|
-
between them should not have to guess.
|
|
122
|
-
|
|
123
|
-
Modern cacheable results — `server/discover`, `tools/list`, `prompts/list`, `resources/list`,
|
|
124
|
-
`resources/read` and `resources/templates/list` — carry `ttlMs: 0` and
|
|
125
|
-
`cacheScope: "private"`. The snapshot is private to the caller and a regeneration can replace any
|
|
126
|
-
part of it between two reads, so a positive TTL would invite a client to serve stale bytes.
|
|
122
|
+
reads the index, `medium` reads a few bounded bodies, `expensive` runs a compiler or writes.
|
|
127
123
|
|
|
128
124
|
| Tool | Answers | Writes |
|
|
129
125
|
| :-- | :-- | :-- |
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
132
|
-
| `
|
|
133
|
-
| `
|
|
134
|
-
| `
|
|
135
|
-
| `
|
|
136
|
-
| `
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
| `snapshot_neighbors` | Both import directions for one path | no |
|
|
140
|
-
| `snapshot_routes` | Route handlers recorded by the summaries, with their files | no |
|
|
141
|
-
| `snapshot_cycles` | Strongly connected components in the import graph | no |
|
|
142
|
-
| `snapshot_stats` | Files by layer and kind, part sizes, token estimate, heaviest files | no |
|
|
143
|
-
| `snapshot_search` | Case-insensitive text search across the emitted parts, bounded and redaction-safe | no |
|
|
144
|
-
| `snapshot_review` | Currency, health and bounded bodies in one call, so a review can start | no |
|
|
145
|
-
| `snapshot_symbol` | Where a function, class or constant is defined, with a window and a line number | no |
|
|
146
|
-
| `snapshot_diff_context` | Bodies of the changed files plus the files that import them | no |
|
|
147
|
-
| `snapshot_context` | One bounded context block from named files or symbols, read from the snapshot | no |
|
|
148
|
-
| `snapshot_plan_for` | Given a question and a token budget, the smallest set of files that answer it, in reading order | no |
|
|
149
|
-
| `snapshot_plan` | What would a generate at this budget include, and what would it leave out? | no |
|
|
150
|
-
| `snapshot_generate` | Build it. Accepts `includeDiffs`, `includeLogs`, `tokenTree` and `stripComments`, so a client can ask for the opt-in reports the CLI has. | yes |
|
|
151
|
-
| `snapshot_validate` | Is the context the agent was given still current? | no |
|
|
152
|
-
| `snapshot_locate` | Which part holds this symbol, route or file? | no |
|
|
153
|
-
| `snapshot_dependents` | What does this file import, and what imports it? | no |
|
|
154
|
-
| `snapshot_read` | A window of one file, as the snapshot contains it. | no |
|
|
155
|
-
| `snapshot_explain` | Why is this path not in the snapshot? | no |
|
|
156
|
-
|
|
157
|
-
Twenty-five are declared `readOnlyHint`, which most clients use to run them without asking. Only
|
|
126
|
+
| `snapshot_impact` | What does this change reach? Symbol-pruned callers, routes, import cycles, candidate tests and optional snippets. Omitting `paths` and `base` compares the working tree with `HEAD`. | no |
|
|
127
|
+
| `snapshot_context` | The minimum redacted, line-numbered context for a question, files or symbols inside a hard token budget. `planOnly` returns the reading plan. | no |
|
|
128
|
+
| `snapshot_locate` | Paths, symbols, routes, entrypoints or bounded redacted text. Symbol mode can add compiler-resolved references. | no |
|
|
129
|
+
| `snapshot_read` | A bounded, redacted line window of one file. Sensitive paths are never readable. | no |
|
|
130
|
+
| `snapshot_validate` | `status` (presence, counts, fingerprint), `drift` (freshness), or `audit` (secret and integrity checks). Only drift claims `current`. | no |
|
|
131
|
+
| `snapshot_explain` | Why is this path included, excluded, sensitive, ignored, binary or truncated? | no |
|
|
132
|
+
| `snapshot_generate` | Write the snapshot, or preview it with `dryRun: true`. | yes |
|
|
133
|
+
|
|
134
|
+
Six tools are declared `readOnlyHint`, which most clients use to run them without asking. Only
|
|
158
135
|
`snapshot_generate` writes.
|
|
159
136
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
**Live by default.** Read-only tools reuse a current `manifest.json`, overlay changed and new files
|
|
138
|
+
in memory when the tree has moved, or scan the confined working tree when no snapshot exists. They
|
|
139
|
+
never write into the repository. Pass `"live": false` to require the persisted snapshot. Every
|
|
140
|
+
structured response carries a `trust` envelope naming the index source, freshness, coverage,
|
|
141
|
+
redaction count and any reason coverage is partial.
|
|
142
|
+
|
|
143
|
+
All 7 take `outDir`, so a snapshot generated into a directory other than the configured one is
|
|
144
|
+
still reachable: pass the same value to the read side that you passed to `snapshot_generate`.
|
|
164
145
|
|
|
165
146
|
An `outDir` **tool argument** must resolve inside the repository the server serves: a prompt cannot
|
|
166
147
|
drop a snapshot tree anywhere the process is able to write. The project's *configured* `outDir`
|
|
@@ -168,32 +149,25 @@ and `tmpDir` are confined the same way. If either escapes, the tool refuses and
|
|
|
168
149
|
to move the directory inside the served root, or start the server with `--cwd` at the parent
|
|
169
150
|
repository.
|
|
170
151
|
|
|
171
|
-
`
|
|
172
|
-
|
|
173
|
-
`
|
|
174
|
-
|
|
175
|
-
reported as configuration drift on every `snapshot_validate`. Pass the same switches you generated
|
|
176
|
-
with, exactly as you would on the command line. The other tools do not take them, because
|
|
177
|
-
none of them re-derives the configuration and a flag that changes nothing is the command-line form
|
|
178
|
-
of a silent fallback.
|
|
152
|
+
`snapshot_generate`, `snapshot_validate` and `snapshot_explain` also take the **scope and
|
|
153
|
+
compression** switches `generate` accepts: `maxPartTokens`, `skeleton`, `sarif`, `changedSince`,
|
|
154
|
+
`staged` and `withDependents`. `manifest.config.digest` covers those settings, so a snapshot
|
|
155
|
+
generated with `--skeleton` must be validated with the same switch rather than reported as drift.
|
|
179
156
|
|
|
180
157
|
`includeSensitiveFiles` is deliberately absent from every one of them. A prompt can ask for
|
|
181
158
|
anything, and a tool that emits `.env` on request is a secret-exfiltration primitive with a
|
|
182
159
|
friendly name.
|
|
183
160
|
|
|
184
161
|
`snapshot_locate` is the one that makes the others usable: a twelve-part snapshot is hundreds of
|
|
185
|
-
kilobytes, and asking "
|
|
186
|
-
|
|
187
|
-
kinds — and returns the part each match lives in.
|
|
162
|
+
kilobytes, and asking "where is authentication?" is cheaper than reading all twelve. It searches
|
|
163
|
+
the manifest's index and, for text mode, a bounded redacted body scan.
|
|
188
164
|
|
|
189
|
-
`snapshot_read` is windowed on purpose. It defaults to 200 lines and reports
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
page ends mid-line, `pageable` is `false` and `reason` says so, because advancing `fromLine` would
|
|
193
|
-
silently skip the rest of that line.
|
|
165
|
+
`snapshot_read` is windowed on purpose. It defaults to 200 lines and reports where more remains,
|
|
166
|
+
so an agent continues deliberately instead of pulling a whole part into a context window it has
|
|
167
|
+
not budgeted. A response never exceeds 64 KiB.
|
|
194
168
|
|
|
195
169
|
At most four requests run at once. A fifth gets a JSON-RPC `overloaded` error (`-32001`) naming
|
|
196
|
-
the limit instead of being queued silently or dropped, so a client can retry and `
|
|
170
|
+
the limit instead of being queued silently or dropped, so a client can retry and `snapshot_validate`
|
|
197
171
|
stays responsive.
|
|
198
172
|
|
|
199
173
|
## Resources
|
|
@@ -221,7 +195,7 @@ publishes them separately as `reportResources`.
|
|
|
221
195
|
A resource read is **all-or-nothing**. Above the 512 kB single-read limit the read fails with
|
|
222
196
|
JSON-RPC error `-32000` (the implementation-defined server-error range) and
|
|
223
197
|
`data: { uri, bytes, limit }`; the message says what to use instead — `snapshot_locate`,
|
|
224
|
-
`snapshot_read` or `
|
|
198
|
+
`snapshot_read` or `snapshot_validate` for a manifest or part, the file on disk for a report, and
|
|
225
199
|
the CLI for the contract or the skill. It never returns a truncated document: half a JSON manifest
|
|
226
200
|
does not parse, and half a part is a fragment that looks complete. The rule applies to every
|
|
227
201
|
resource — `snapshot://manifest`, each `snapshot://parts/{index}`, the report resources,
|
|
@@ -331,7 +305,7 @@ the same repository. The numbers below are measured, not estimated:
|
|
|
331
305
|
| A synthetic tree | 3,000 | 7.5 s |
|
|
332
306
|
|
|
333
307
|
They describe how long the *write* takes, not how long the server is deaf — which is the
|
|
334
|
-
distinction a client's request timeout actually cares about. `
|
|
308
|
+
distinction a client's request timeout actually cares about. `snapshot_generate` with `dryRun` produces the same
|
|
335
309
|
numbers without writing anything.
|
|
336
310
|
|
|
337
311
|
The worker re-reads the configuration and applies the same options this thread used, because a
|
|
@@ -349,7 +323,7 @@ to stderr. Check the client's server log — the first line says which directory
|
|
|
349
323
|
version in the client arguments.
|
|
350
324
|
|
|
351
325
|
**`Unknown resource` for a part.** Resources are computed from the manifest, so nothing but the
|
|
352
|
-
static set exists before the first generate. Call `
|
|
326
|
+
static set exists before the first generate. Call `snapshot_validate` with `mode: "status"`, then `snapshot_generate`.
|
|
353
327
|
|
|
354
328
|
**A resource read fails with `-32000`.** The resource is larger than the 512 kB single-read limit;
|
|
355
329
|
it was refused rather than truncated. `data.uri`, `data.bytes` and `data.limit` say which resource
|
|
@@ -358,3 +332,10 @@ from the snapshot directory for the manifest or a report.
|
|
|
358
332
|
|
|
359
333
|
**A file is missing from `snapshot_locate`.** It is excluded, and `snapshot_explain` will name the
|
|
360
334
|
reason — an ignore rule, the preset, a sensitive-file pattern, or your own config.
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
## See also
|
|
338
|
+
|
|
339
|
+
- [MCP server for a codebase](mcp-server-for-codebase.md) — setup for Claude, Cursor and generic clients, the seven tools, security and limits.
|
|
340
|
+
- [MCP tools](tools.md) — every schema and an example call.
|
|
341
|
+
- [LLM codebase context](llm-codebase-context.md) — why a local server beats attaching a file for follow-up questions.
|