Files
lucioandClaude Fable 5.1 2954ae8a84
ci / checks (push) Successful in 1m28s
ci / corpus (push) Successful in 32s
MCP feedback-3: the instantiation template and hierarchy overrides are opt-in; census round 3 and the verdict written; 0.57.0 notes drafted
Round 3 of the census (mcp_analysis.md): with feedback-1/2 the whole-design question is one call and 15 % cheaper than plain file tools (47/47 in 9 calls); the small edits stay 4–19 % dearer; the cross-file rename is complete every time; a 71-instance hierarchy question costs a third of the tool calls but the same tokens because every unit_interface answer carried a 30-line template. Verdict: helpful, not a toy — no wrong answer in 20 runs, one-call whole-design answers, completeness on cross-file edits, verified writes — with a fixed catalogue tax and verbose answers as the cost. Feedback-3 (crates/lucisv_mcp/src/tools/{interface,hierarchy}.rs): `unit_interface` renders the template only with `template: true` (−40 % bytes), `hierarchy` renders `#(…)` only with `overrides: true` (−55…66 %), `ports (N):`/`parameters (N):` headers; QA proved the opt-in output byte-identical to the previous binary over every fixture and the opentitan clone. Docs: the Agents guide's tool table regenerated from the binary and the site rebuilt; CHANGELOG 0.57.0 section and the extension notes drafted for the closing release; TODO-MCP's M6 items closed; docs/mcp/census-runs.txt holds the raw run log. Gates through tools/guard.sh: fmt, clippy, workspace 4 953 passed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-23 22:53:18 -07:00
..

mcp-read-tools

TODO-MCP.md M1 (second half) — the six read tools of lucisv-mcp: project_overview, list_units, unit_interface, outline, read_item, search_symbols. Design: docs/mcp/PLAN.md §4.3 and §4.5. The transport, handshake and Project they run on are docs/features/mcp-transport.

Goal

Let an agent learn what a Verilog/SystemVerilog tree contains, and what one unit offers, in a few hundred tokens instead of reading files: which units exist and where, a module's ports and parameters with a paste-ready instantiation, a file's outline, one item's exact text, a fuzzy symbol search. Every answer is a composition of existing library queries plus rendering; no language knowledge lives in the MCP crate.

Assumptions

  • Every tool is read-only: annotations {readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false}, and every inputSchema is closed (additionalProperties: false) with its required list. The schema and the argument validation come from one table (tools::Param), so they cannot disagree.
  • program is told apart by its keyword. vlog_semantic models a program as a Module (docs/features/interface-semantics). The tools read the keyword off the text between the declaration's start and its name — only for files whose text spells endprogram, recorded when the file is read, so a design without programs pays nothing.
  • Classes inside packages are units too, listed as pkg::cls (list_units, unit_interface accept that spelling). File-scope classes are listed by their own name.
  • search_symbols is WorkspaceIndex::workspace_symbols: units and the connection-surface members (ports, parameters, package and class members), case-insensitive substring. A module's internal nets are not in it by the index's own design; the description says so and points at outline. A hit carries its file and line and no column (rework, finding 4): the index records a column only for units and only in UTF-16 units, and the server prints one column unit everywhere (below). A miss walks the roots once before it is answered (finding 3).
  • read_item's slice is the parser's Item node that declares the name (attributes included, leading comments not); for a declaration a larger construct merely contains — an ANSI port in a module header, a header parameter, a function argument — the declaration's own span; for a non-ANSI port, its body declaration. A multi-name declaration (logic q, r;) is one item for either name. name@LINE picks among same-named declarations; always@LINE (also initial, final, assign) picks the unlabelled item whose lines cover LINE, any always_* flavour included. @LINE is the last @ followed only by digits, and kind: is a prefix only when it is one of the kind words render::kind produces; otherwise @ and : belong to the name, so the escaped identifiers \a@b and \k:l are selectable as written, and \a@b@1 is \a@b on line 1 (rework, finding 5). M4's replace_item is specified to replace exactly this slice, so the slicer (tools/read_item.rs::select) is public to the crate.
  • unit_interface ports come from vlog_refactor::instantiation_plan (the same plan the editor's instantiate completion uses), with the packed range split off the type in structuredContent (type, range) and the unpacked dimensions an ANSI port writes after its name read off the declaration (unpacked). A non-ANSI port's unpacked dimensions are not reported (its name sits in the header, its dimensions in the body, and pairing them is the plan's job — see Handshakes). Parameters are the plan's: overridable ones only, defaults as written; a header localparam is not offered. A unit declared in several files is refused with every site listed until file picks one — never a guess. A class's extends is read off its own declaration in the file's tree, and a member counts only when it is declared inside the found declaration's span — two classes of one name in two packages never answer for each other (rework, finding 1). A name that finds nothing walks the roots once and is looked up again before the refusal (finding 3).
  • Columns are 1-based byte columns (LineIndex::line_col), the unit parse diagnostics and the CLI already print — the one unit the whole server prints or accepts (docs/features/mcp-transport, Assumptions).

The rendering contract (PLAN §4.5, render.rs)

rule how
paths root-relative Project::relative: relative to the first root holding the file, /-separated; absolute only for a file outside every root (a filelist entry)
a file named once per group render::grouped — the file on its own line, its entries indented two spaces under it (list_units, search_symbols); single-file answers name the file once at the top (outline, read_item, unit_interface's head line)
1-based positions lines always; line:col (byte column) where a column is given — today only outline's parse errors; ranges first-last, a one-line range one number
capped lists limit (default 500) and offset on every list tool; the answer opens with its total — N units, or N units (showing a–b) when cut — and a cut list also ends … and N more; structuredContent carries total and shown so the agent can page
no prose, no headings labels are a bare word and a colon (parameters:, ports:, modports:, template:, members:); none/no units match for empty answers
tables only for fixed columns render::table — ports (direction, type-with-range, name), parameters (name, default), members, largest files; a column empty in every row takes no space
a declaration as its own line modports are shown as their declaration collapsed to one line; parameter defaults likewise

Amended 2026-09-23 (lane feedback-2, docs/features/mcp-feedback-2): the count line first, the default page 500, shown in the JSON; list_units and search_symbols take the in path glob.

Handshakes

Consumed: see docs/features/mcp-transport/README.md (one table for the crate). No library crate was modified.

Requests (informational, none blocking):

  • To vlog_refactor (candidate): PlanPort carries the packed type but not the unpacked dimensions after the name; unit_interface reads them back off an ANSI declaration itself (tools/interface.rs::unpacked). A PlanPort::unpacked field would let a non-ANSI port report them too and retire that code.
  • To vlog_semantic (candidate): a program is indistinguishable from a module in SymbolKind; the tools re-read the keyword from the text. A SymbolKind::Program (or a flag on Def) would retire that, at the cost of a FACTS_FORMAT bump — not worth one on its own.

Status / TODO

  • project_overview (roots, config, filelist, file count and skips, units by kind, index build time and age, top-level modules, ten largest files, warnings)
  • list_units (kind, glob, limit, offset)
  • unit_interface (name, file): parameters, ports, template, modports, package/class members, extends
  • outline (file, depth, limit, offset) with parse errors
  • read_item (file, item) with name, kind:name, name@LINE, always@LINE
  • search_symbols (query, limit, offset)
  • wire tests for every tool over the fixture tree (crates/lucisv_mcp/tests/fixtures/design, 7 files)

Work log

2026-09-23 (dev, M1).

Six tools in crates/lucisv_mcp/src/tools/ — read.rs (overview, list_units, outline, search_symbols), interface.rs (unit_interface), read_item.rs (read_item and the slicer) — over the rendering helpers in src/render.rs. Fixture tree tests/fixtures/design: a package with a class, leaf (parameters, an unpacked port, an unlabelled always_ff), top instantiating leaf with .* and bus_if, bus_if with two modports, a file-scope class, a program, and a file with a parse error.

Deviations from the plan's tool table, each small and additive:

  1. limit/offset on list_units, outline and search_symbols — PLAN §4.5 says every list is capped and pageable; the §4.3 table named only search_symbols's limit.
  2. unit_interface takes an optional file: opentitan declares many modules twice (prim_generic_* vs technology variants); refusing without a way to choose would make the tool useless there.
  3. read_item accepts name@LINE, initial@LINE, final@LINE and assign@LINE besides the planned always@LINE — one grammar (head@LINE) rather than a special case.
  4. Classes and the program kind in list_units as above; tool titles (a 2025-06-18 field) on every tool.

Smoke on opentitan (read-only): unit_interface prim_fifo_sync over the whole checkout answers 6 parameters, 12 ports and the template in ~1.9 KB of text, 7 ms after the index exists; project_overview lists 1 278 modules, 236 interfaces, 402 packages, 2 023 classes, 3 programs.

2026-09-23 (dev, M1 rework after QA). The lead's rulings on the QA findings, as applied to the read tools (the transport half is in docs/features/mcp-transport's work log of the same date):

  • 1 (blocking) — fixed. tools/interface.rs::members keeps a member only when its name_span lies inside found.def.decl_span (same file as before), and extends comes from the new class_base, which finds the ClassDecl whose name_span is found.def.name_span in the file's own tree (walking with read_item::child_items, now pub(super)). WorkspaceIndex::base_of is no longer called. qa_a_class_reports_its_own_base_not_a_same_named_class_s and qa_two_same_named_classes_in_one_file_do_not_share_members un-ignored.
  • 3 — fixed. Project::ensure_walked_for_miss (walks once unless this call already walked, reports whether it did); called by unit_interface when no declaration matches (candidates then pick, split from the old find_unit), by list_units when a glob matches nothing, and by search_symbols when the query has no hit. read_item/outline need no hook: Project::resolve and Project::analysis read the disk, not the index, so a new file already resolves and reads. Wire test search_symbols_finds_units_and_members_by_substring gained a brand-new file found by name; qa_a_unit_written_just_now_is_found_by_name_without_a_walk_first un-ignored.
  • 4 — fixed by removal. search_symbols prints and returns no column (tools/read.rs::search_symbols; the col key is gone from structuredContent). qa_columns_are_counted_in_one_unit_across_tools un-ignored, and its last assertion edited to the ruling: it asserted col == 17 (bytes), which removal cannot satisfy; it now asserts line == 1 and no col key. Its first assertion (the parse error at byte column 28) is unchanged. wire.rs's two search assertions dropped col likewise.
  • 5 — fixed. read_item::split_line (the last @ counts only when digits alone follow it; digits that overflow a u32 say "out of range") and render::is_kind_word (a KIND_WORDS table, pinned against every SymbolKind by a unit test). The description names the \a@b@1 spelling. qa_an_escaped_name_holding_at_or_colon_is_selectable_by_itself un-ignored. Note: the QA test selects \a@b with no line, which the plain "last @" rule would still have refused; the digits-only reading is what makes both it and the lead's \a@b@1 work.
  • 6 — no action (a library limit; QA's note stands).

2026-09-23 (dev, feedback-3). unit_interface's instantiation template is opt-in (template: true); without it the text ends after ports/modports/warnings and the JSON has no template key; the headers read parameters (N): / ports (N): (handshake change: answer shape and a new argument) — docs/features/mcp-feedback-3.

QA log

2026-09-23 (QA, M1 — the six read tools). Verdict: rework needed — finding 1 is a wrong answer. Everything else below is non-blocking. Method and the protocol/freshness/roots half: docs/features/mcp-transport QA log of the same date; attacks pinned in crates/lucisv_mcp/tests/qa_m1.rs.

Verified correct (pinned by passing qa_* tests):

  • An escaped-identifier unit (\my-mod ): listed, unit_interface by its spelled name, a legal template (\my-mod \u_my-mod (), read_item of the module. A port with packed and unpacked ranges (input logic [7:0] a [0:3], output logic [3:0][1:0] b [2][0:1]): range and unpacked both right, and the text row reads as declared. A header parameter type T = logic [3:0] and parameter int unsigned N = 4 report their defaults; a header localparam is not offered.
  • CRLF: outline line ranges, list_units lines and read_item's range are right, and read_item's structuredContent.text is the exact bytes (\r\n kept, the module slice byte-equal to the file's). UTF-8 comments (été, 日本) before items and on the item's own line: lines and slices right.
  • A module declared in two files: refused naming both file:line sites; file picks one; the top-module list names it once. A name declared twice in one file: read_item refuses with var:w@1, var:w@3, and w@3 answers. list_units glob d?p matches dup, d_p, not dp/duup. outline depth: 0 → isError naming depth; limit: i64::MAX and offset: i64::MAX are fine. search_symbols with "" matches all 5 symbols and pages with … and 3 more.
  • By hand on opentitan hw/ip/aes: unit_interface aes_core — all 18 ports, in order, with direction and type (logic [EntropyWidth-1:0], keymgr_pkg::hw_key_req_t, aes_reg2hw_t, …) match rtl/aes_core.sv:30-57 line by line; 13 parameters with defaults, the header localparam NumShares rightly absent. outline rtl/aes_core.sv (module aes_core 9-1145, 284 entries, paged); read_item always@346 returns exactly lines 346-358 (key_init_reg); list_units kind=module lists the 60-odd modules grouped by file. On hw/: unit_interface prim_flop refuses with its three technology variants.

Findings (this half; numbering shared with the transport log):

  • 1 — BLOCKING (wrong answer): a class's extends and members come from the short name, so same-named classes answer for each other. tools/interface.rs:306 asks index.base_of(name) with the class's bare name; the index keys bases by bare name, so with p1::c extends base1 and p2::c extends base2 (different files) unit_interface p2::c says extends base1, and a file-scope class c; with no base says extends base1 too. tools/interface.rs:298-301 takes index.members_of(name) filtered by file only, so package p1; class c; int a; … and package p2; class c; int b; … in one file both list a and b. opentitan census (--root hw): 2 023 classes, 298 bare names shared by more than one class (pwrmgr_env ×4, clkmgr_base_test ×4 …); of the 728 such classes whose header fits one line, none answered a wrong base — the copies are per-top clones with the same base — so the bug is latent there, but any design reusing a class name with a different base (or none) gets a confident wrong extends. Repro: qa_a_class_reports_its_own_base_not_a_same_named_class_s, qa_two_same_named_classes_in_one_file_do_not_share_members. Suggested fix: read extends from the found file's own AST (the ClassDecl whose name_span is found.def.name_span), and keep a member only when its name_span lies inside found.def.decl_span. Small, MCP-side; a library-side key by qualified name would be a Handshake, not needed.
  • 4 — non-blocking (low): two column units in one server. tools/read.rs:421 reports search_symbols columns in UTF-16 units (the index's LSP positions) while outline's parse errors use byte columns: in /* é */ module pe; assign = ; endmodule the parse error is 1:28 (bytes) and pe is 1:16 (UTF-16; 1:17 in bytes). The README states both, but an agent cannot tell which a number is. Repro: qa_columns_are_counted_in_one_unit_across_tools (asserts bytes; the dev may pick characters instead and update both sites and the test).
  • 5 — non-blocking (low): an escaped name holding @ or : cannot be named alone. tools/read_item.rs:67 splits on the last @ and :79 on the first :, so read_item \a@b is "@ must be followed by a line number" and \k:l is "no declaration matches l of kind \k". \a@b@1 and module:\k:l work, but the description does not say so. Repro: qa_an_escaped_name_holding_at_or_colon_is_selectable_by_itself. Fix: when the head starts with \, split only after the escaped name's end (first whitespace, or the whole string).
  • 6 — informational (library, no MCP test): a module declared twice in one file is answered from the first silently. module x (input a); endmodule module x (input b); endmodule in one file: the semantic layer keeps only the first (outline shows port b orphaned at depth 1), so list_units has one x, unit_interface x answers input a, and read_item x slices the first. Same root: an `ifdef/ `else pair of alternative declarations shows only the first branch. Not the MCP's to fix; recorded because PLAN's "ambiguity is a list, never a guess" does not hold here.

Notes (no action asked): parameters report name and default as PLAN §4.3 says, not the type, so a parameter type T reads like a value parameter; a type column (from vlog_refactor's plan) would cost little. list_units/outline with an offset past the end answer an empty text (not no units match); structuredContent.total still tells the truth. x@99999999999 says "must be followed by a line number" (u32 overflow).

Size and style (production lines = non-blank, non-comment, before #[cfg(test)], measured by QA): main.rs 67, transport.rs 38, rpc.rs 222, render.rs 97, project/mod.rs 212, project/files.rs 130, project/analysis.rs 52, tools/mod.rs 129, tools/read.rs 397, tools/interface.rs 285, tools/read_item.rs 199 — the dev's numbers, exactly. No function over 50 lines anywhere in the crate (largest: a 41-line wire test). unwrap/expect: only in #[cfg(test)] blocks, project/tests.rs and the tests (main.rs:115 is inside mod tests). No panic!, unreachable!, todo!, #[allow] or unsafe.

Gates (verbatim, all through tools/guard.sh):

  • cargo fmt -p lucisv_mcp -- --check: clean (exit 0) — after rustfmt on qa_m1.rs itself; the dev's files were already clean.
  • cargo clippy -p lucisv_mcp --all-targets: Finished, no warnings.
  • cargo test -p lucisv_mcp: unit 27 passed; 0 failed; 0 ignored; tests/qa_m1.rs 30 passed; 0 failed; 10 ignored; tests/wire.rs 11 passed; 0 failed; 0 ignored. With -- --ignored on qa_m1: 0 passed; 10 failed — each for its finding's reason.
  • cargo test --workspace (default guard, 8 GB / 1 800 s): exit 0 in 3 min 53 s, summed over every binary 4 527 passed, 0 failed, 56 ignored (the dev's 4 497 / 46 plus this file's 30 / 10). No guard kill; the dev's one 30-minute kill did not reproduce (no concurrent cargo invocation was running).

2026-09-23 (QA, M1 re-check after the rework). Verdict: pass, with one new non-blocking finding (11). Transport-side re-derivations (2, 3, 10) and the check of the dev's edit to qa_columns_…: the transport QA log of the same date.

Re-derived by hand:

  • 1 — p1::c extends bp::base #(8) with the base package in another file answers extends bp::base (the scope kept, the overrides dropped); p2::c with no base answers none, although its nested class inner extends p1::c has one — class_base matches the exact name_span; p2::c's members are b and inner, not inner's z; two cs in two packages of one file no longer share members.
  • Same-named class twice in one package (class d extends lbase then class d extends other): the semantic layer keeps only the first (outline shows the second's y orphaned) — finding 6's library limit, unchanged — and the answer is internally consistent: line 2, extends lbase, member x.
  • 5 — \a@b, \k:l, module:\k:l, \port:q (an escaped name whose text starts with a kind word) and \a@12@2 all select; w@3 and always@4\t select (the handler trims); module:w is refused "no declaration matches w of kind module"; w@99999999999 says "line … is out of range"; struct:w (not a kind word) is read as a name and refused naming it.
  • 4 — search_symbols hits carry line and no col in both the JSON and the text, for a unit after a multibyte comment and for members.

New finding:

  • 11 — non-blocking (low): an escaped name that ends in @ and digits cannot be named alone. tools/read_item.rs::split_line takes \a@12 as \a on line 12, and select never tries the whole selector as a name, so read_item \a@12 (a legal identifier \a@12 ) is refused "no declaration matches \a on line 12" — true, but no hint. \a@12@2 works, and the description documents the \a@b@1 spelling, so the agent has a way out if it reads that far. Repro: qa_rework_an_escaped_name_ending_in_at_digits_is_selectable_by_itself (#[ignore = "QA finding 11"], confirmed failing on the bare spelling). Suggested fix: when the @LINE reading matches nothing and the head starts with \, retry with the whole selector as the name. Related, cosmetic: whitespace around @ (w @7, always@ 8) is not accepted.

New tests this round (qa_rework_*): a package-scoped base in another file plus a nested class; a class declared twice in one package; a symlinked directory leaving the root, a loop and an alias (dropped, warned, terminates); a real kind word of the wrong kind and an escaped name starting with a kind word; @ selectors with trailing spaces, overflow and an empty line number; the escaped @digits name (ignored, finding 11); every by-name tool finding a file written just now; a legitimate miss not making later hits walk; search hits with a line and no column; a file that stops being UTF-8; a rename-over and a cp -p restore with an old mtime and the same size.

Gates (verbatim, all through tools/guard.sh, one cargo invocation at a time): cargo fmt -p lucisv_mcp -- --check exit 0; cargo clippy -p lucisv_mcp --all-targets Finished, no warnings; cargo test -p lucisv_mcp unit 28 passed; 0 failed, qa_m1 50 passed; 0 failed; 1 ignored, wire 11 passed; 0 failed; cargo test --workspace (default guard) exit 0 in 242 s, 4 548 passed, 0 failed, 47 ignored (the dev's 4 538 / 46 plus this round's 10 / 1). No guard kill.

Review

Lead, 2026-09-23. The six tools read as the plan's table and the rendering follows §4.5 (paths once per group, … and N more, no prose). unit_interface refusing a name declared in several files with every site listed is the right posture for opentitan's per-top duplicates; the file argument is the escape hatch. The M1 QA round's class-base cross-contamination was the one wrong answer and is fixed at the declaration, where it belongs. Committed as M1; the token census (M6) will say whether the renderings are compact enough.