# TODO-MCP — the Model Context Protocol block Planned 2026-09-23 by the lead at 0.55.0. The analysis and design are in [`docs/mcp/PLAN.md`](docs/mcp/PLAN.md); read it before touching any lane. This file is the tracking sheet for the block and stays separate from `TODO.md` on purpose: the block is independent of the LSP and CLI lanes, and its lanes collide with nothing in `docs/topo.md` except where a lane below says so. Rules that apply to every lane, restated once: CLAUDE.md in full (guard every suite and sweep through `tools/guard.sh`; no `git commit`/`push`; a feature README kept current as you work; no file outside the lane's list; cross-module wants are Handshake requests, not edits); opentitan is read-only; no `sleep` over 60 s; `cargo fmt -p` per package while another lane is live. Each lane is one Opus dev then one Opus QA (owner's ruling 2026-09-23: both Opus 5.5), working directly on trunk, then the lead's self-inspection and a commit; no release until every lane is done. A QA "rework" loops inside its lane. ## Fixed names (the wire shapes every lane pins by test) | thing | name | |---|---| | crate / binary | `crates/lucisv_mcp` / `lucisv-mcp` | | arguments | `--root DIR` (repeatable; default cwd), `--filelist FILE`, `--index-cache DIR`, `--verbose`; anything else → `usage:` on stderr, exit 2 (the server's posture) | | vsix entry | `extension/bin/lucisv-mcp[.exe]` (platform), `extension/bin//lucisv-mcp[.exe]` (all) | | VS Code provider id | `lucisv.mcp`; settings `lucisv.mcp.enabled` (true), `lucisv.mcp.path` (""); command `lucisv.mcp.copyConfig` | | feature READMEs | `docs/features/mcp-transport`, `mcp-read-tools`, `mcp-navigation`, `mcp-edit-tools`, `mcp-structural-edits`, `mcp-packaging`, `mcp-cache-and-census` | ## M1. Transport and the read tools **Files:** `Cargo.toml` (workspace `members` += `crates/lucisv_mcp`), `Cargo.lock`, everything under `crates/lucisv_mcp/` (`src/main.rs`, `transport.rs`, `rpc.rs`, `project.rs`, `render.rs`, `tools/mod.rs`, `tools/read.rs`, `tests/wire.rs`, `tests/fixtures/`), the two feature READMEs. Nothing else — in particular no change to any library crate; a missing public query is a Handshake entry. - [x] crate skeleton: `main.rs` argument contract (table above), the `PARSE_STACK_SIZE` main thread, the ordered loop; `transport.rs` newline-delimited JSON-RPC over stdio (stdout protocol-only, stderr log-only; a line that is not JSON → `-32700`, never a crash) - [x] `rpc.rs`: `initialize` (version negotiation over a listed set, the pinned current revision first; `serverInfo`; `capabilities`; `instructions`), `notifications/initialized`, `ping`, `tools/list`, `tools/call` envelope (`content` text + `structuredContent`, `isError` for refusals), `notifications/cancelled` accepted, unknown method/tool/params → `-32601`/`-32602` - [x] `project.rs`: roots, `Discovery`, filelist-or-walk file set with the 1 MiB cap, `IndexBuilder` build, lazy per-file `Semantics`, the per-call stat sweep + `update_file`/`remove_file` + re-walk policy (PLAN §4.4); a path outside every root is refused by name - [x] tools `project_overview`, `list_units`, `unit_interface` (ports, parameters, template via `instantiation_plan`; modports for an interface; exports for a package), `outline`, `read_item` (incl. the `always@` spelling for unlabelled blocks), `search_symbols` — each with `inputSchema`, `annotations` (`readOnlyHint: true`), a one-sentence description written for the agent, and the compact rendering rules of PLAN §4.5 - [x] `tests/wire.rs`: spawns the built binary; the handshake; every tool over a fixture tree of ≥ 6 files (a package, two modules with a `.*` instance, an interface with a modport, a class, a file with a parse error); a freshness test (edit a fixture on disk between two calls, second answer reflects it; delete one, it disappears; fingerprint equals a rebuild after each); a malformed-line test; a `--root` outside-path refusal - [x] README `mcp-transport`: Goal, Assumptions (why no `rmcp`; the pinned protocol revisions; sync one-at-a-time), Handshakes (none consumed beyond public APIs — list them), work log; README `mcp-read-tools` likewise, with the rendering rules as its contract - [x] gates through `tools/guard.sh`; sizes reported per file - [x] QA: protocol attacks (an `id` that is a string, a null `id`, a notification with an `id`, a 10 MB line, a request before `initialize`, an unsupported `protocolVersion`), rendering attacks (a unit named with an escaped identifier, a port with a packed and unpacked range, a file with CRLF line endings — line numbers must still be right), the freshness promise under a rename-then-recreate of a file within one second; verdict in the QA logs ## M2. Navigation, diagnostics, resources **Files:** `crates/lucisv_mcp/src/tools/nav.rs`, `resources.rs`, `tools/mod.rs` (registry entries only), `rpc.rs` (the three `resources/*` methods), `tests/wire.rs` (additions), the `mcp-navigation` README. Depends on M1 merged. - [x] `definition` (selector: `file,line,col` or `name,unit?`; local via `Semantics::definition_of`, cross-file via `resolve_external`; ambiguity is a list), `references` (`vlog_refactor::find_references`, grouped by file, capped with `limit`/`offset`), `hierarchy` (down from `root` or every top-level module; `up` lists parents; parameter overrides as written; `depth`), `diagnostics` (parse errors, missing-closer warnings via the tolerant tree, lint through `select_rules` + the project's `[lint]` config + external waivers + an index-backed `MentionOracle`; the CLI's JSON field names), `defines` (table; one-step expansion when called with `name` + `args`) - [x] resources `lucisv://overview`, `lucisv://unit/{name}`, `lucisv://rules` (`rules_markdown()`), `lucisv://file/{path}/outline`; `resources/templates/list` for the two parameterised ones - [x] the opentitan parity census as an `#[ignore]` test taking the checkout path from an env var: `references`/`definition` on the `references-nav` symbols and `hierarchy` down from `top_earlgrey` compared with the LSP's answers recorded in that README (read-only; `git status` of the checkout identical before and after) - [x] README `mcp-navigation`; work log; gates; sizes - [x] QA: a `bind` connection's bare name, a `u_x.sig` tail, a name that is both a port and an internal net (must list both, not pick), a class member, a macro-only name (`files_naming_in_macros`), a `hierarchy` over a recursive/generate-instantiated module (must terminate with the depth cap), lint options from `lucisv.toml` honoured; verdict ## M3. Edit tools (wrapping the verified engines) **Files:** `crates/lucisv_mcp/src/tools/edit.rs`, `apply.rs`, `tools/mod.rs` (entries), `tests/wire.rs` (additions), `tests/fixtures/` (additions), the `mcp-edit-tools` README. Depends on M2 merged and on the ruling for Handshake MCP-1 (the diff lift) — until MCP-1 lands, `apply.rs` carries a private copy of `unified` marked `// TODO(MCP-1)` and the README says so. - [x] `apply.rs`: `RefactorEdit` → (`dry_run`) unified diff per file | the all-computed-then-written loop over `write_atomic`, refusing before the first write on any verifier failure; the summary (files, +/- lines, warnings, created); the "written N of M then failed" report - [x] `format` (`files[]` or `file` + `lines`, `dry_run`), `fix_lint` (`apply_fixes` through `fence::protected_regions`, safe fixes only), `rename`, `expand_wildcard`, `convert_ports`, `organize_imports`, `inline_module`, `propagate_ports`, `remove_port`, `add_port`, `extract_module` (`home`: new file / same file; the created file is written too), `instantiate` (text only; `style`) — every one with `destructiveHint: false`, `idempotentHint` where true - [x] the source-set rule: each refactor gets the whole in-scope file set (PLAN §2.1 — the server narrows; MCP does not, so it can never be narrower than the engine needs); the README states the cost on opentitan and M6 measures it - [x] tests: every tool `dry_run` then real on the fixtures; run twice → second run is a no-op with an empty diff; a refusal leaves the fixture tree byte-identical (hash the tree before/after); an `extract_module` into a new file; a rename that touches three files; a `fix_lint` whose finding sits in a format fence (must not touch it) - [x] README `mcp-edit-tools`; Handshake MCP-1 filed there with the exact move; work log; gates; sizes - [x] QA: an edit whose target file changed on disk between the stat sweep and the write (the freshness promise vs the write — the write must be refused, not applied over the newer bytes; the dev states the mechanism); a read-only file; a path through a symlink leaving the root; concurrent `lucisv --check` on the same tree; a CRLF file through `format`; verdict — done 2026-09-23 (Opus, two rounds + lead fixes): pass for the lane; the write path held under a 50 ms writer race, chmod 444, symlinked escapes and a concurrent CLI; `format`/`fix_lint` byte-identical to the CLI. Findings ruled: skipped files refuse a whole-word match; whole-set tools re-walk first. **Open, out of lane:** the engine's rename breaks `.*`/`.name` shorthand connections → M3.5 below. ## M3.5. Rename vs implicit connections (inserted 2026-09-23 after M3 QA) **Files:** `crates/vlog_refactor/src/rename/**`, `crates/vlog_refactor/src/check/**` only if the verifier must learn the shape, `crates/vlog_refactor/tests/` (or the crate's test modules), `docs/features/refactor-rename/README.md` (a dated section), `crates/lucisv_mcp/src/tools/edit.rs` (drop the known-limit sentence) + `tests/qa_m3.rs` (un-ignore finding 1), `TODO.md` (one line under the §8 rope-port refactorings noting the fix). An engine lane: the LSP's rename inherits the fix. - [x] `vlog_refactor::rename` rewrites implicit connections: renaming a port `p` → `q` turns `.p` into `.q(p)` and adds `.q(p)` beside a `.*` that bound it (explicit connections beside `.*` are legal); renaming a net `n` → `m` in a module whose instantiations bind it through `.n` or `.*` turns `.n` into `.n(m)` and adds `.n(m)` beside the `.*`; comments and layout of the connection list preserved (append after the last connection, before the closing paren, on its own line when the list is one-per-line); every such rewrite listed in `warnings` so the user sees it; refuse (never guess) when the instantiation's port list cannot be read (`ifdef`-split, error element) - [x] the verifier sees the new edits as intended (no false "moved" refusal); attack tests: `.*` + explicit of the same port; nested instances; a `.name` whose net and port differ; a bind instance - [x] QA: attack the rewrite on opentitan copies (`prim_fifo_sync` ports under `.*` users); LSP parity via `vlog_refactor::rename` directly ## M4. Structural edits (the one new verifier in the block) **Files:** `crates/lucisv_mcp/src/tools/item.rs`, `tools/mod.rs` (entries), `tests/wire.rs` and `tests/attacks.rs` (new), fixtures, the `mcp-structural-edits` README. Depends on M3 merged. - [ ] `replace_item`, `insert_item`, `delete_item` with the PLAN §4.3 contracts: bytes outside the span untouched (asserted by the test, not trusted), strict re-parse of the whole file (or no growth in tolerant error count when it did not parse before), one item at the position, the declared name matches unless `rename: true`, `delete_item` refuses over surviving references unless `force` - [ ] `tests/attacks.rs`, written by the dev, every case asserted **refused with the tree byte-identical**: a `text` opening a block it does not close; one that closes the enclosing module; one that re-declares a port; a UTF-8 boundary inside the span; an item inside a format fence; a file with an unterminated string; an `insert_item` after `end` — the CLAUDE.md invariant-4 discipline applied to the block's own verifier - [ ] README `mcp-structural-edits`: the contract as a table, the attack list, what the tool deliberately does not check (semantic sense of the new text) - [ ] gates; sizes (`item.rs` is expected to be the largest file in the crate; if it passes 600 lines the verifier moves to `item/verify.rs`) - [ ] QA: re-attack with at least eight new cases (a `text` that is two items; an empty `text`; a `text` equal to the old bytes — must be a no-op, not a refusal; a macro-bracketed item; a `generate` block target; an item whose leading comment is shared with the previous item's trailing one; a 40 000-line file for timing; `delete_item` on the last item of a module); verdict ## M5. Packaging and the extension (parallel with M2–M4) **Files:** `tools/release.sh`, `tools/audit_artifacts.sh`, `tools/RELEASING.md`, `.gitea/workflows/ci.yml` (two lines: the MCP wire test is already in `cargo test`; add `node --test editors/vscode/*_test.js`), `editors/vscode/{package.json,package-lock.json,extension.js,mcp.js, mcp_test.js,mcp_smoke.js,.vscodeignore,README.md,CHANGELOG.md}`, `docs/site/src/content/docs/guides/agents.md` (new) and the guides index, `README.md` (an "Agents (MCP)" paragraph under Editor setup), the `mcp-packaging` README. May start once M1's binary answers `initialize` on trunk; touches no Rust. `extension.js` changes are limited to requiring `mcp.js` and calling its `activate(context)`. - [ ] `release.sh`: stage `lucisv-mcp[.exe]` into `bin/` (platform) and `bin//` (all); `expect_vsix_bins` lists grow to three; `mcp_smoke.js` run against the host binary and against the one unzipped from the host vsix and the all-platforms vsix (mirror `smoke_embedded_server`); `audit_artifacts.sh` accepts the third name; the universal vsix still asserts no `extension/bin/*` - [ ] `mcp.js`: the three-rung binary ladder reusing `bundledBinary`; the guarded `registerMcpServerDefinitionProvider("lucisv.mcp", …)` with one `McpStdioServerDefinition` per workspace folder (`--root`, `--index-cache `, `cwd`, `version` from `package.json`), re-fired on folder changes; `lucisv.mcp.enabled` / `lucisv.mcp.path` read like `serverPath` (`inspect()`, blank = unset); the `lucisv.mcp.copyConfig` command with the three dialects (Claude Code `.mcp.json`, Cursor, VS Code `.vscode/mcp.json`) naming the resolved binary; `mcp_test.js` with a stubbed `vscode` (the `hierarchyView_test` pattern) covering the ladder, the guard on an old VS Code (no `lm`), and the three snippets - [ ] `package.json`: `contributes.mcpServerDefinitionProviders`, the two settings, the command + palette entry; engine stays `^1.82.0` unless `vsce package` refuses — then bump to `^1.101.0` and record why in the README and CHANGELOG - [ ] docs: the site guide page (install via vsix → nothing to do; Claude Code / Cursor snippets; the standalone `cargo build` line; the tool list generated from `tools/list` output, checked in); `README.md` paragraph; `tools/RELEASING.md` (three binaries; the smoke); the extension README and CHANGELOG - [ ] CI: `node --test editors/vscode/*_test.js` in `ci.yml` - [ ] README `mcp-packaging`; work log; `node --test` green; a local `tools/release.sh` (host only) producing a darwin-arm64 vsix with the three binaries, unzipped and checked - [ ] QA: install the vsix into a clean VS Code profile: the server listed under **MCP: List Servers**, trusted, `project_overview` answered in agent mode; `lucisv.mcp.enabled: false` removes it; a multi-root workspace registers one server per folder; the universal vsix on a machine without `lucisv-mcp` on PATH degrades to a clear output-channel line, not an error dialog; the Claude Code snippet pasted into a `.mcp.json` works from a terminal; rows in `docs/manual-acceptance.md`; verdict ## M6. Cache reuse, census, closing release **Files:** `crates/lucisv_mcp/src/{project.rs,cache.rs}` (new `cache.rs`), `tests/` additions, `docs/mcp/census.md` (new), `docs/perf/README.md` (an MCP section), `docs/topo.md` (§1.1 node + §2.8 rows for `lucisv_mcp`, an §1.4 touch-set row), `docs/manual-acceptance.md`, `CHANGELOG.md`, `docs/repository-analysis.md` (the crate count and map row), the `mcp-cache-and-census` README, `TODO-MCP.md` (this file's closing entries). Depends on M4 and M5 merged. - [ ] `cache.rs`: the read-only reader of the LSP's `index-cache` (header check on `CACHE_FORMAT`/`FACTS_FORMAT`/version, per-line checksum, `FileFacts::decode`, `record_path`); on `--index-cache DIR` a file whose `content_hash` has a record is `add_facts`'d instead of parsed; MCP's own `index-cache-mcp` written with the same codec on exit and read on start; never a write to the LSP's file (a test opens the store read-only and asserts its bytes after a full MCP session) - [ ] startup timing on opentitan cold / warm-from-LSP-store / warm-from-own-store, and the per-call stat sweep, recorded in `docs/perf/README.md` next to the LSP's scan trace numbers; the whole-set refactor cost from M3 measured on `rename` in `aes` - [ ] the token census (PLAN §8): the three tasks, each run twice (file tools only / with lucisv-mcp) by the same agent model, tokens in and out from the transcripts, written up in `docs/mcp/census.md` with the transcripts' task ids; if a task saved nothing, say so — the number is the deliverable, not its sign - [ ] `instructions` and tool descriptions revised from what the census transcripts show the agent misunderstood; `prompts/*` added only if the census shows a repeated multi-tool sequence worth one prompt - [ ] `docs/topo.md`: the `lucisv_mcp` node (`──▶` the six libraries; `-.spawn contract.->` from `editors/vscode`; `-.builds/packages.->` from `tools/`), the §2.8 rows, the Handshake MCP-1 status (delivered or still open), and MCP-3 filed in §2.9 if M2's hierarchy walk and the server's snapshot drifted - [ ] `CHANGELOG.md` section, `README.md` architecture table row (nine crates), `docs/repository-analysis.md` map row, CLAUDE.md measurement line refreshed with the new crate's sizes - [ ] release **0.56.0** (or the next minor free at the time): tag, CI green, 8 assets, the darwin-arm64 vsix unzipped and checked for three binaries, the MCP smoke in the release log; the install line and the `claude mcp add` line given to the owner - [ ] QA: the read-only promise on the LSP store attacked (a store with a torn last line; one from a different version; one whose record hash matches but whose facts checksum does not — each must be skipped, not trusted, and the file left byte-identical); a cold start with no store directory permission (must still answer, warn on stderr); the census transcripts spot-checked for a tool answer the agent had to correct by reading the file anyway (each is a finding against a tool's rendering); verdict ## Open questions for the owner (answer before the lane that needs it) 1. **Engine bump** (M5): if `vsce` accepts the contribution point on `^1.82.0`, keep it; if not, bump to `^1.101.0` and drop VS Code < 1.101 users. The lane records which happened; no ruling needed unless the bump is unwelcome. 2. **Whole-set refactors** (M3): MCP hands every refactor the full in-scope set. On opentitan that is a parse of ~3 000 files per `rename` unless `KnownFacts` from the cache is threaded through (M6 can). Acceptable for the first release, or should M3 already narrow with `files_mentioning` the way the server does? 3. **Structural edits and the formatter** (M4): after `replace_item`, the agent's text is left as written. The alternative — format the replaced item's lines through `format_range` automatically — costs a refusal path when the safety net objects. Default in this plan: not automatic; the agent calls `format` with `lines`.