# mcp-read-only Lane **M8** of the MCP block (`TODO-MCP.md`, `docs/mcp/PLAN.md` §11). ## Goal One binary, two modes. `lucisv-mcp --read-only` offers only the five read tools (`hierarchy`, `find`, `outline`, `read`, `check`) and shorter instructions, so an agent that only needs to *understand* a design reads a catalogue half the size and talks to a server that cannot change it: no file inside a root is created, written, renamed or removed, whatever is called. Without the flag nothing changes — full mode is byte-identical to 0.58.0 on the wire. The VS Code extension chooses the mode by a setting (`lucisv.mcp.mode`), and its copy-config command keys a read-only server `lucisv-ro` so a host can carry both side by side. ## Assumptions Where §11 is silent, the simplest thing, recorded: - **The mode is a registry filter.** `tools::Mode { Full, ReadOnly }` lives in `tools/mod.rs`; `Mode::offers(Effect)` admits `Read` tools in read-only mode and every tool in full mode. `tools::list(mode)` and `tools::find(name, mode)` both go through the one filter, so the listed set and the callable set cannot disagree. No handler checks the mode. - **`Options.mode`** carries the mode (default `Full`); `--read-only` sets it. The flag takes no value and may be repeated harmlessly. - **Resources** run their read tools through `tools::find(name, Mode::ReadOnly)` — the strictest registry that has them — so a resource can never reach an edit tool in either mode and answers the same in both. - **The unknown-tool message** carries the ` (the server runs --read-only)` suffix for *any* unknown name in read-only mode, not only the four edit names: the sentence is true either way and the rule is one line. Full mode keeps `unknown tool: NAME` exactly. - **`check`'s description is shared.** The shipped description ("Parse errors and lint findings of `file` or the whole design, …") never said "after edits" — only the full-mode *instructions* do — so it reads right in both modes and there is one description (§11.1 allows this). The read tools' descriptions, schemas and annotations are identical in both modes (pinned by test). - **The instructions text deviates from §11.1 by one phrase.** The quoted text is 302 bytes, over its own 300-byte budget; "check for diagnostics" became "check for issues" (297 bytes). Nothing else changed. - **The promise covers the roots.** The index store under `--index-cache` is still written on exit. The extension passes VS Code's workspace storage, which is outside the folder. A user who points `--index-cache` at a directory *inside* a root gets that directory written (the store, its `.gitignore`); that is the user's own choice of store location, not a tool call, and is not guarded against. - **Extension:** only an unset `lucisv.mcp.mode` or exactly `"full"` is full mode; exactly `"read-only"` is read-only, and any other value fails safe to read-only with one line in the lucisv output channel (lead ruling on QA finding 2; was: anything but `"read-only"` is full). The change event already fires for every `lucisv.mcp.*` change (`affectsConfiguration('lucisv.mcp')`), so the mode needed no new listener — only a test. `--read-only` is appended *last* in the definition's args (after `--index-cache`) and in the snippet's args. The copy-config message names the mode in both modes (`(full mode)` / `(read-only mode)`), a wording change for full mode too. - **`mcp_smoke.js --read-only`** additionally checks the tiny project's two files are byte-identical after the session; with `--tool-table` it prints whatever the mode lists (the full-mode table is unchanged, compared byte for byte against the 0.58.0 script). ## Handshakes - **Consumes** from the tool registry (M7): the `Effect` per tool in `TOOLS`. A new tool must be given the right `Effect` — an `Edit` tool marked `Read` would be offered in read-only mode. The five-name tests in `tools/mod.rs` and `tests/read_only.rs` pin the current set. - **Promises** to hosts: `--read-only` → exactly `hierarchy, find, outline, read, check` in that order, catalogue ≤ 1 800 model-visible bytes (1 797 shipped), instructions ≤ 300 (297 shipped); `tools/call` of an edit name → JSON-RPC `-32602` `unknown tool: NAME (the server runs --read-only)`; no write inside a root. Full mode: `initialize` and `tools/list` byte-identical to 0.58.0 (checked against the 0.58.0 release binary; the full catalogue stays 3 440 bytes, instructions 398). - **Promises** to the extension's users and to `release.sh`: setting `lucisv.mcp.mode` (`"full"` / `"read-only"`), label `lucisv read-only ()`, args `[…, "--read-only"]`, copy-config key `lucisv-ro`; `mcp_smoke.js --read-only` as the second MCP gate at both `release.sh` sites. Recorded in `docs/topo.md` §2.8. - **Requests:** none. Every file touched is on the lane's list. ## Status / TODO - [x] server: `--read-only` parsed and in the usage line; `Mode` filters the registry (`tools/list`, `tools/call`); read-only instructions; the unknown-tool message - [x] tests: `tests/read_only.rs` (names and order, both budgets, the five identical to full mode's, the four edit names unknown, full mode's nine names and 0.58.0 instructions, the no-write snapshot with every tool name and every resource, the full-mode control that the edit arguments do write); unit tests in `tools/mod.rs`, `rpc.rs`, `main.rs` - [x] extension: `lucisv.mcp.mode` in `package.json`; `mcp.js` args, label, copy-config key/args/message; `mcp_test.js` - [x] `mcp_smoke.js --read-only`; `tools/release.sh` runs both smokes at both sites; `tools/RELEASING.md` - [x] docs: Agents guide "Read-only mode" section, settings table and arguments line; extension README and CHANGELOG; `CHANGELOG.md` 0.59.0 (unreleased); `docs/topo.md` §2.8; manual-acceptance rows 26–27 ## Work log ### 2026-09-29 — dev (Opus) - Captured the 0.58.0 wire (`initialize` + `tools/list` over `tests/fixtures/design`) from a release build of HEAD before any change; after the change the full-mode output is `cmp`-identical to it. - `tools/mod.rs`: `Mode`, `Mode::offers`, `offered(mode)`; `list` and `find` take the mode. `rpc.rs`: `INSTRUCTIONS_READ_ONLY`, `instructions(mode)`, `unknown_tool(name, mode)`. `main.rs`: `Options.mode`, `--read-only`, the usage line. `resources.rs`: reads through `Mode::ReadOnly`. - Deviation: §11.1's instructions text measured 302 bytes against its own ≤ 300 budget; "check for diagnostics" → "check for issues" (297). - Figures (release build): read-only catalogue 1 797 bytes, instructions 297; full catalogue 3 440, instructions 398 (unchanged). The read-only catalogue is 3 bytes under its ceiling: any growth of the five read tools' descriptions or schemas now needs a trim elsewhere. - `tests/read_only.rs` copies the small `Tree`/`Session` helpers from `wire.rs` rather than sharing them (brief). The no-write test snapshots path → (size, mtime) for files and mtime for directories (so a temp file created and removed is caught), runs with `--index-cache` outside the tree, closes stdin and waits for exit before the second snapshot, and asserts the cache directory did get the store. - Extension: setting, provider args/label, copy-config snippet key and message; `mcp_smoke.js --read-only` (five tools, `hierarchy`, `rename` → the exact `-32602` error, files untouched). Against the 0.58.0 binary `--read-only` fails as it should (`unknown option`). - Gates: `cargo fmt --all`; `cargo clippy --all-targets -- -D warnings` clean (guard exit 0); `cargo test -p lucisv_mcp` 14 suites, 373 passed, 0 failed, 4 ignored (guard exit 0); `node --test editors/vscode/*_test.js` 6/6; `mcp_smoke.js target/release/lucisv-mcp` OK in both modes. ### 2026-09-29 — dev (Opus), QA rework - QA finding 2 (lead ruling 1): `mcp.js` `readOnlyMode(log)` — unset or exactly `"full"` → full; exactly `"read-only"` → read-only; anything else (`"Read-Only"`, `"readonly"`, `"Full"`, `null`, `true`, a number) → read-only plus one line, `lucisv: lucisv.mcp.mode is "", not "full" or "read-only"; using read-only.`, through `activate`'s `log` (now passed to `serverDefinitions` and `copyConfig`, which share the rule). `mcp_test.js` `anUnknownModeFailsSafeToReadOnly` covers the three cases and the line; `theReadOnlySnippets` covers copy-config with `"readonly"`. One clause ("any other value is treated as read-only") in the `package.json` description, the extension README settings table and the Agents guide settings table. - QA finding 4 (lead ruling 2): `mcp_smoke.js --read-only` now checks the tool list (count and names) before the `rename` refusal; against a wrapper that drops `--read-only` it fails with `tools/list is 9 tools […], expected 5 […]`. - No Rust changed. `node --test editors/vscode/*_test.js` 6/6; both smokes OK against `target/release/lucisv-mcp`. ### 2026-09-29 — dev (Opus), rework 2 - The `hierarchy` cap now counts instances, not peek lines (census round 5 finding on `prim_fifo_sync` up + peek). The change and its tests are logged in `docs/features/mcp-lean-catalogue/README.md` (work log, 2026-09-29); tool descriptions and both modes' byte figures unchanged. ### 2026-09-29 — dev (Opus), rework 3 - QA finding 6: the `hierarchy` cap is 300 instances without `peek`, 100 with it (lead ruling). Logged in the M7 README (work log, rework 3). QA's boundary test in `qa_m8.rs` is renamed `qa_the_node_cap_is_exact_at_300_and_301_plain_and_100_and_101_with_peek` (the QA log below still names it by its old name). Descriptions and both modes' byte figures unchanged. ## QA log ### 2026-09-29 — QA (Opus) **Verdict: PASS with findings** (two low, three informational; no corruption, no write, no reachable edit handler). What was verified, and how: - **No-write promise, fixture.** `tests/qa_m8.rs` `qa_read_only_never_changes_a_byte_whatever_arrives`: snapshot of every entry under a copy of `fixtures/edit` (file size + mtime + **bytes**, directory mtime so a temp file created and removed is caught), then one session with: 13 edit shapes (rename ×2, port add / add-after / remove, edit_item replace / insert_before / insert_after / delete, format with and without `fix`, `**/*.sv`, `rtl`) sent before `initialize` (all `-32002`), after it as requests (all `-32602` with the exact message), as notifications (`tools/call` with no id) and as `notifications/`; 12 near-miss names (`Rename`, `" rename"`, `"rename "`, `rename\n`, `rename\0`, `edit-item`, `editItem`, fullwidth `rename`, `format\t`, …); `name` as number / array / object / null / bool (`-32602` "need a string `name`"); edit names with null / array / string / smuggled `mode` arguments and a `_meta`/`mode` in params; a batch array (`-32600`); a duplicate `name` key (`check` then `format`: last key wins → refused); a second `initialize` asking for `experimental.mode: full` followed by `format` (still refused); eight resource URIs (the four real ones plus `lucisv://format/…`, `lucisv://unit/..%2F..%2Fetc`); three stray notifications. Snapshot identical after exit. Control `qa_every_edit_shape_writes_in_full_mode`: each of the 13 shapes writes in full mode. Mutation `Mode::offers` → `(Mode::ReadOnly, _)`: three QA tests fail; reverted, `cmp`-identical. - **No-write promise, opentitan** (`~/.cache/lucisv-eval/ot/hw`, release binary, `--read-only`, no `--index-cache`): `format **/*.sv fix` before `initialize`, then rename `uart_rx`, port add/remove on `uart_rx`, edit_item insert/delete in `ip/uart/rtl/uart_rx.sv`, format `**/*.sv` and `ip/uart/rtl`, `Format `, a notification-form format, the five reads and three resources (3 944 files indexed). Every edit answered `-32602`; `git status --short` empty before and after, `--ignored` set unchanged, no file newer than the run outside `.git`. `/Users/…/repo/opentitan` not touched. - **Reachability.** `tools::find` is the only way from a name to a handler; callers: `rpc.rs:247` (`self.options.mode`) and `resources.rs:116` (`Mode::ReadOnly`, and only `hierarchy`/`outline` are named). No cached `Tool` reference; `apply::run` is called only from `edit.rs`, `format.rs`, `item.rs` (and `port` through them). `Options` is built only by `Options::default()` in `parse_args` (`main.rs:82`) and in `rpc.rs`'s unit tests; `Server.options` is never reassigned. - **Arguments** (`qa_argument_order_and_repetition_cannot_undo_read_only`): flag first, last, repeated, mixed with `--verbose` → five tools; `--read-only=false`, `--read-only false`, `--read-only=true`, `--readonly`, `--no-read-only` → exit 2, `unknown option`, usage line naming `[--read-only]`, no server. - **Budgets, recomputed in Python** from the wire (compact JSON of name + description + inputSchema): read-only 1 797 bytes, 5 tools, all `readOnlyHint: true`, instructions 297; full 3 440, instructions 398. Sum of name + description + schema alone: 1 576 / 3 043. Mutation: 4 bytes appended to `hierarchy`'s description → `read_only.rs` fails ("the read-only catalogue is 1801 bytes"); reverted, `cmp`-identical. - **Full-mode identity.** `initialize` + `notifications/initialized` + `tools/list` + `resources/list` + `resources/templates/list` + an unknown tool, over `fixtures/design`: current release binary vs `~/.cache/lucisv-eval/bin/lucisv-mcp-r5` — identical except `serverInfo.version` (finding 3). - **Read answers across modes** (`qa_the_read_tools_and_resources_answer_identically_in_both_modes`): 12 read calls (incl. a refusal) + 4 resource reads (incl. not-found) + the three list methods on `design` and `edit`: identical text in both modes. - **Extension.** `node --test editors/vscode/*_test.js` 6/6. The change event: `mcp.js:176-177` fires on `affectsConfiguration('lucisv.mcp')`, which VS Code answers true for `lucisv.mcp.mode` (pinned by the dev's test). Copy-config per host per mode pinned by `theThreeSnippets` / `theReadOnlySnippets`. `mcp_smoke.js` against the release binary: OK in both modes; `--read-only` against r5 (refuses the flag, exit 2) → smoke exit 1; against a wrapper that drops `--read-only` (a server listing nine tools) → smoke exit 1 (finding 4). - **Release script.** `bash -n tools/release.sh` OK; `set -eu` (line 32); both new invocations (host `$dist/lucisv-mcp-$version-$host`, embedded `$unpacked/$inner/lucisv-mcp`) are plain statements, so a failing smoke aborts the script. - **Docs.** The guide's two-key example parses as JSON and each entry has the shape copy-config emits for Claude Code / Cursor (`command`, `args`; `lucisv-ro` args end `--read-only`). Arguments line and usage line name the same five flags in the same order. - **Gates.** `cargo fmt --all` clean; `cargo clippy --all-targets -- -D warnings` clean (guard exit 0); `cargo test -p lucisv_mcp` 15 suites, 378 passed, 0 failed, 4 ignored (guard exit 0, no `guard.sh:` line). Findings, by severity: 1. **Low (docs, fixed).** The Agents guide (`docs/site/src/content/docs/guides/agents.md`, "Read-only mode", last paragraph) and `CHANGELOG.md` 0.59.0 said the index store "is outside the roots" — true only as the extension passes it. Repro: `lucisv-mcp --root R --index-cache R/.cache --read-only`, call `check`, close stdin → `R/.cache/.gitignore` and `R/.cache/index-cache-mcp` appear (the dev's recorded deviation). Reworded both to say the store is written where `--index-cache` points. PLAN §11.1 carries the same sentence; left for the lead. 2. **Low (design, recorded).** `editors/vscode/mcp.js:57`: any `lucisv.mcp.mode` other than exactly `"read-only"` — `"Read-Only"`, `"readonly"`, `null`, `true` — is full mode, silently. That is the brief's rule and nothing dangerous is said, but a typo lands on the *permissive* mode; VS Code's only hint is the enum warning in `settings.json`. No change made. 3. **Info.** `~/.cache/lucisv-eval/bin/lucisv-mcp-r5` reports `serverInfo.version` `0.57.0` (built before the 0.58.0 bump); the wire is otherwise byte-identical to the current full mode. 4. **Info.** `mcp_smoke.js --read-only` against a server that ignores the flag fails on the `rename` check (`rename in read-only mode answered undefined`) before the tool-list check — it fails, but the message does not say "nine tools". Against r5 it fails the same way (the server exited 2 with its usage line on stderr). 5. **Info.** `tools/release.sh` `smoke_embedded_mcp`: a failing smoke aborts before `rm -rf "$unpacked"`, leaving `target/vsix-check` (pre-existing pattern; the next run removes it first). Tests added: `crates/lucisv_mcp/tests/qa_m8.rs` (5 tests, all green). ### 2026-09-29 — QA (Opus), re-check: `hierarchy` cap counts nodes Rework under test: `tools/hierarchy.rs` `render_nodes` caps at 300 nodes (the down root line included), peek lines never count. **Verdict: PASS with one finding.** - **No-peek identity with b757e82** (`lucisv-mcp-r6` vs a fresh release build): 43 calls on `fixtures/design` and 85 on `fixtures/edit` (every unit down / down depth 20 / up / up depth 20, with and without peek) — 0 differ. Eval clone, 9 calls — `top_earlgrey` depth 2 (50 lines) and depth 3 (`… and 165 more`), `prim_fifo_sync` up (77) and up depth 3 (`… and 1421 more`), `top_darjeeling` depth 3 (`… and 174 more`), `prim_flop` up (`… and 176 more`) and up depth 4 (`… and 45166 more`), `uart` depth 20, the overview (`… and 69 more`) — byte-identical, and identical again under `--read-only`. - **`prim_fifo_sync` up + peek** (eval clone): 1 078 lines, no cut. Its lines that are neither statement lines (4-space indent) nor blank are exactly the 77 lines of the no-peek answer, in order; every node is followed by at least one statement line; no block exceeds 12 lines + `…` (69 blocks end in `…`). r6 gave 21 of them then `… and 56 more`. - **`qa_m7.rs` diff vs HEAD:** one expected tuple `(299, 251)` → `(599, 101)` (root + 299 two-line blocks, 401 − 300 = 101 — what the rule requires) and the peek assertion now pins *two* lines (`peek[597]` the 299th instance's node line, `peek[598]` its statement) where it pinned one; no other assertion touched. - **Boundaries** (`qa_m8.rs` `qa_the_node_cap_is_exact_at_300_and_301_down_and_up_with_and_without_peek`, 14-line statements so every block is cut to 12 + `…`): down 299 instances (300 nodes) → 300 lines, no cut; down 300 → root + 299 and `… and 1 more`; up 300 → 300, no cut; up 301 → 300 and `… and 1 more`. With peek: the same node lines and cut line in the same order, exactly 14 lines per instance node, the line before the cut is the last block's `…` (never split). The down count counts the root as a node consistently: 401 nodes → `… and 101 more` = the 101 instances not shown. - **Modes:** every text above is identical in full and `--read-only` mode (asserted in the test, and on the eval clone with and without peek). - **Gates:** `cargo test -p lucisv_mcp` 16 suites, 381 passed, 0 failed, 4 ignored (guard exit 0, no `guard.sh:` line); clippy `-p lucisv_mcp --all-targets -D warnings` clean. Eval clone `git status` empty. Finding: 6. **Medium (answer size, design consequence).** A peeked answer is no longer bounded by ~300 lines but by 300 × 14 lines. Repro on the eval clone: `hierarchy {"root":"top_earlgrey","depth":3,"peek":true}` → 3 759 lines, 151 224 bytes (r6: 295 lines, 10 152 bytes); `{"root":"prim_fifo_sync","up":true,"depth":3,"peek":true}` → 4 154 lines, 152 356 bytes (r6: 10 457); `prim_flop` up peek → 2 984 lines, 89 972 bytes. That is roughly 40 k tokens in one answer, against the lean catalogue's short-answer goal (PLAN §10). The fix the brief asked for (77 of 77) needs only ~31 KB; whether a byte ceiling on peek belongs beside the node cap is the lead's call. Not changed. Tests added: `qa_m8.rs` `qa_the_node_cap_is_exact_at_300_and_301_down_and_up_with_and_without_peek`. ## Review 2026-09-29 (lead). Examined the diff, the registry filter, the QA log and the live wire in both modes. Accepted. `--read-only` lists five tools in 1 797 model-visible bytes with 297-byte instructions; full mode is byte-identical to 0.58.0. QA could not make the read-only server write inside a root or reach an edit handler. Rulings: the dev's deviations 1–5 stand (instructions say "check for issues"; any unknown tool name carries the read-only suffix); an unknown `lucisv.mcp.mode` value selects read-only and is logged (QA finding 2); the smoke checks the tool list first (finding 4); PLAN §11 now says the index store is written wherever `--index-cache` points. Gates at commit: lucisv_mcp 378 passed / 4 ignored (15 suites), node tests 6/6, both smokes OK. Census round 5 follows on this binary.