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]>
23 KiB
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 everyinputSchemais closed (additionalProperties: false) with itsrequiredlist. The schema and the argument validation come from one table (tools::Param), so they cannot disagree. programis told apart by its keyword.vlog_semanticmodels aprogramas aModule(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 spellsendprogram, 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_interfaceaccept that spelling). File-scope classes are listed by their own name. search_symbolsisWorkspaceIndex::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 atoutline. 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'sItemnode 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@LINEpicks among same-named declarations;always@LINE(alsoinitial,final,assign) picks the unlabelled item whose lines cover LINE, anyalways_*flavour included.@LINEis the last@followed only by digits, andkind:is a prefix only when it is one of the kind wordsrender::kindproduces; otherwise@and:belong to the name, so the escaped identifiers\a@band\k:lare selectable as written, and\a@b@1is\a@bon line 1 (rework, finding 5). M4'sreplace_itemis specified to replace exactly this slice, so the slicer (tools/read_item.rs::select) is public to the crate.unit_interfaceports come fromvlog_refactor::instantiation_plan(the same plan the editor's instantiate completion uses), with the packed range split off the type instructuredContent(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 headerlocalparamis not offered. A unit declared in several files is refused with every site listed untilfilepicks one — never a guess. A class'sextendsis 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):PlanPortcarries the packed type but not the unpacked dimensions after the name;unit_interfacereads them back off an ANSI declaration itself (tools/interface.rs::unpacked). APlanPort::unpackedfield would let a non-ANSI port report them too and retire that code. - To
vlog_semantic(candidate): aprogramis indistinguishable from amoduleinSymbolKind; the tools re-read the keyword from the text. ASymbolKind::Program(or a flag onDef) would retire that, at the cost of aFACTS_FORMATbump — 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,extendsoutline(file,depth,limit,offset) with parse errorsread_item(file,item) withname,kind:name,name@LINE,always@LINEsearch_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:
limit/offsetonlist_units,outlineandsearch_symbols— PLAN §4.5 says every list is capped and pageable; the §4.3 table named onlysearch_symbols'slimit.unit_interfacetakes an optionalfile: opentitan declares many modules twice (prim_generic_*vs technology variants); refusing without a way to choose would make the tool useless there.read_itemacceptsname@LINE,initial@LINE,final@LINEandassign@LINEbesides the plannedalways@LINE— one grammar (head@LINE) rather than a special case.- Classes and the
programkind inlist_unitsas above; tooltitles (a2025-06-18field) 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::memberskeeps a member only when itsname_spanlies insidefound.def.decl_span(same file as before), andextendscomes from the newclass_base, which finds theClassDeclwhosename_spanisfound.def.name_spanin the file's own tree (walking withread_item::child_items, nowpub(super)).WorkspaceIndex::base_ofis no longer called.qa_a_class_reports_its_own_base_not_a_same_named_class_sandqa_two_same_named_classes_in_one_file_do_not_share_membersun-ignored. - 3 — fixed.
Project::ensure_walked_for_miss(walks once unless this call already walked, reports whether it did); called byunit_interfacewhen no declaration matches (candidatesthenpick, split from the oldfind_unit), bylist_unitswhen aglobmatches nothing, and bysearch_symbolswhen the query has no hit.read_item/outlineneed no hook:Project::resolveandProject::analysisread the disk, not the index, so a new file already resolves and reads. Wire testsearch_symbols_finds_units_and_members_by_substringgained a brand-new file found by name;qa_a_unit_written_just_now_is_found_by_name_without_a_walk_firstun-ignored. - 4 — fixed by removal.
search_symbolsprints and returns no column (tools/read.rs::search_symbols; thecolkey is gone fromstructuredContent).qa_columns_are_counted_in_one_unit_across_toolsun-ignored, and its last assertion edited to the ruling: it assertedcol == 17(bytes), which removal cannot satisfy; it now assertsline == 1and nocolkey. Its first assertion (the parse error at byte column 28) is unchanged.wire.rs's two search assertions droppedcollikewise. - 5 — fixed.
read_item::split_line(the last@counts only when digits alone follow it; digits that overflow au32say "out of range") andrender::is_kind_word(aKIND_WORDStable, pinned against everySymbolKindby a unit test). The description names the\a@b@1spelling.qa_an_escaped_name_holding_at_or_colon_is_selectable_by_itselfun-ignored. Note: the QA test selects\a@bwith 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@1work. - 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_interfaceby its spelled name, a legal template (\my-mod \u_my-mod (),read_itemof 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]):rangeandunpackedboth right, and the text row reads as declared. A headerparameter type T = logic [3:0]andparameter int unsigned N = 4report their defaults; a headerlocalparamis not offered. - CRLF:
outlineline ranges,list_unitslines andread_item's range are right, andread_item'sstructuredContent.textis the exact bytes (\r\nkept, 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:linesites;filepicks one; the top-module list names it once. A name declared twice in one file:read_itemrefuses withvar:w@1, var:w@3, andw@3answers.list_unitsglobd?pmatchesdup,d_p, notdp/duup.outlinedepth: 0→isErrornamingdepth;limit: i64::MAXandoffset: i64::MAXare fine.search_symbolswith""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, …) matchrtl/aes_core.sv:30-57line by line; 13 parameters with defaults, the headerlocalparam NumSharesrightly absent.outline rtl/aes_core.sv(module aes_core 9-1145, 284 entries, paged);read_item always@346returns exactly lines 346-358 (key_init_reg);list_units kind=modulelists the 60-odd modules grouped by file. Onhw/:unit_interface prim_floprefuses with its three technology variants.
Findings (this half; numbering shared with the transport log):
- 1 — BLOCKING (wrong answer): a class's
extendsand members come from the short name, so same-named classes answer for each other.tools/interface.rs:306asksindex.base_of(name)with the class's bare name; the index keys bases by bare name, so withp1::c extends base1andp2::c extends base2(different files)unit_interface p2::csaysextends base1, and a file-scopeclass c;with no base saysextends base1too.tools/interface.rs:298-301takesindex.members_of(name)filtered by file only, sopackage p1; class c; int a; …andpackage p2; class c; int b; …in one file both listaandb. 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 wrongextends. 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: readextendsfrom the found file's own AST (theClassDeclwhosename_spanisfound.def.name_span), and keep a member only when itsname_spanlies insidefound.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:421reportssearch_symbolscolumns in UTF-16 units (the index's LSP positions) whileoutline's parse errors use byte columns: in/* é */ module pe; assign = ; endmodulethe parse error is1:28(bytes) andpeis1:16(UTF-16;1:17in 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:67splits on the last@and:79on the first:, soread_item \a@bis "@must be followed by a line number" and\k:lis "no declaration matcheslof kind\k".\a@b@1andmodule:\k:lwork, 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); endmodulein one file: the semantic layer keeps only the first (outlineshowsport borphaned at depth 1), solist_unitshas onex,unit_interface xanswersinput a, andread_item xslices the first. Same root: an`ifdef/`elsepair 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) — afterrustfmtonqa_m1.rsitself; the dev's files were already clean.cargo clippy -p lucisv_mcp --all-targets:Finished, no warnings.cargo test -p lucisv_mcp: unit27 passed; 0 failed; 0 ignored;tests/qa_m1.rs30 passed; 0 failed; 10 ignored;tests/wire.rs11 passed; 0 failed; 0 ignored. With-- --ignoredonqa_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 answersextends bp::base(the scope kept, the overrides dropped);p2::cwith no base answers none, although its nestedclass inner extends p1::chas one —class_basematches the exactname_span;p2::c's members arebandinner, notinner'sz; twocs in two packages of one file no longer share members. - Same-named class twice in one package (
class d extends lbasethenclass d extends other): the semantic layer keeps only the first (outline shows the second'syorphaned) — finding 6's library limit, unchanged — and the answer is internally consistent: line 2,extends lbase, memberx. - 5 —
\a@b,\k:l,module:\k:l,\port:q(an escaped name whose text starts with a kind word) and\a@12@2all select;w@3andalways@4\tselect (the handler trims);module:wis refused "no declaration matcheswof kindmodule";w@99999999999says "line … is out of range";struct:w(not a kind word) is read as a name and refused naming it. - 4 —
search_symbolshits carrylineand nocolin 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_linetakes\a@12as\aon line 12, andselectnever tries the whole selector as a name, soread_item \a@12(a legal identifier\a@12) is refused "no declaration matches\aon line 12" — true, but no hint.\a@12@2works, and the description documents the\a@b@1spelling, 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@LINEreading 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.