Round 5 found `hierarchy up` + `peek` cut to 20 of 77 instantiations by the 300-line cap. Same-day base controls put read-only mode at parity with file tools (a +8 %, d −8 %) and show the base arm itself moved 22–29 % in six days. Co-Authored-By: Claude Fable 5.1 <[email protected]>
43 KiB
MCP for lucisv — the plan
Written 2026-09-23 by the lead, at 0.55.0 (ef867db), before any MCP code
exists. Companion: TODO-MCP.md holds the lanes and
checkboxes; this file holds the analysis and the design they follow. Both are
deliberately separate from TODO.md and docs/topo.md: MCP is a new block,
and the owner asked that it stay one.
MCP is the Model Context Protocol: JSON-RPC 2.0 between a host (an agent
such as Claude Code, Cursor, or VS Code's agent mode) and a server that
offers tools (callable functions with a JSON schema), resources
(readable URIs) and prompts. An agent that has lucisv as an MCP server
can ask "what are the ports of prim_fifo_sync" and get thirty lines back,
instead of reading a 2 000-line file; and can say "rename req_i across the
design" as one call, instead of forty reads and forty edits.
1. Goal
Ship lucisv-mcp: one binary, MCP over stdio, that gives coding agents
project understanding (units, interfaces, hierarchy, definitions,
references, outlines, diagnostics) and token-saving edits (verified
refactorings, formatting, lint fixes, and item-level structural replacement)
over a Verilog/SystemVerilog tree — using the six library crates directly,
sharing no code path with lucisv-server (LSP) or the lucisv CLI, and
shipped inside every platform .vsix next to the two binaries already there.
Three properties the owner asked for, and how they are met:
| ask | how |
|---|---|
| independent from LSP and the CLI | A new crate crates/lucisv_mcp with its own binary. It depends on lucisv_core, vlog_parser, vlog_semantic, vlog_refactor, vlog_formatter, vlog_linter, serde, serde_json — never on lucisv_server (which is bin-only anyway) or lsp-types. It has its own workspace loader, its own tool handlers and its own tests. A change to the LSP server cannot break it except through a library crate's public API, which is already the contract every crate lives by |
| supports interacting with them | Three seams, all one-directional and file-based: (1) the same lucisv.toml discovery, filelist and walk (lucisv_core) so MCP indexes the set the editor and CLI see; (2) edits are atomic on-disk writes (lucisv_core::atomic) that the LSP's file watcher already picks up, so the editor's index follows an agent's MCP edit without either side knowing the other; (3) the LSP's persistent index cache is read read-only as a warm-start shortcut when the extension tells both processes the same store path (§6). The VS Code extension is the fourth seam: it spawns the LSP and registers the MCP server, and is the only place that knows both |
| ships with the VS Code plugin | A third binary in every platform .vsix (extension/bin/lucisv-mcp), registered through VS Code's contributes.mcpServerDefinitionProviders + vscode.lm.registerMcpServerDefinitionProvider so VS Code's agent mode finds it with no user configuration; plus a "copy MCP config" command for hosts that do not read VS Code's registry (Claude Code, Cursor) |
2. What we have (the analysis)
Surveyed 2026-09-23. File:line references are at 0.55.0.
2.1 The engines are all library crates; the orchestration is not
Every language answer already lives in a library crate with a protocol-free
API (docs/topo.md §1.2 is the authority):
- Semantics:
vlog_semantic::analyze(&SourceFile, &str) -> Semantics(never fails),Semantics::{definition_of, references_of, document_symbols, symbols_named, …};WorkspaceIndex::build((PathBuf, &str)…)andIndexBuilder::{add_file, add_facts, finish}(order-independent); queriesunits,units_of,instantiable_units,workspace_symbols,members_of,member_in(…, Surface),instantiations_of/instantiations(),subclasses_of,references_to,find_define,files_mentioning;resolve_external(&Semantics, &WorkspaceIndex)for cross-file definition;FileFacts::{of, analyzed, encode, decode}withFACTS_FORMAT = 20; the incrementalupdate_file/absorb/remove_filewithfingerprint()as the rebuild-equality oracle. - Refactorings:
vlog_refactordoes no I/O — every entry point takes the in-scope&[(PathBuf, String)]and returnsResult<RefactorEdit, String>(edits per file + warnings + created files), whole-edit verified in memory:rename,find_references,expand_wildcard,add_port,remove_port,propagate_ports,convert_to_ansi,organize_imports,extract_module,inline_module;instantiation_plan(text, no edit);module_names,module_definition. - Formatter:
format_source/format_range+LineRanges, the safety net inside;fence::protected_regionsfor "may an automatic edit touch these bytes". - Linter:
LintContext::from_parse(...).with_semantics(...).with_oracle(...),lint_with(ctx, rules, &ExternalWaivers),select_rules,apply_fixes,rules_markdown(); theMentionOracletrait for the cross-file rules. - Core:
config::Discovery(lucisv.tomlupward search),filelist::read,walk::collect_files_with(.gitignore+--exclude- cycle-safe),
atomic::write_atomic,cache::content_hash(FNV-1a).
- cycle-safe),
What exists only inside lucisv_server (bin-only; nothing linkable):
| orchestration | where | MCP's stance |
|---|---|---|
| which files to index (filelist → roots walk → folder scope depth 2; 1 MiB cap; client excludes) | state/discover.rs:283-379 |
re-done in ~80 lines over lucisv_core with a simpler ladder (§4.2); no editor settings exist here |
| the scan loop (batches, cache read-through, merge) | state/mod.rs:825-1224, state/scan.rs |
not needed: MCP builds the index once at startup and keeps it fresh per call (§4.4) |
| per-document analysis sequence (tokenize → parse_tolerant → defines → analyze → resolve_external → LineIndex) | state/mod.rs:119 Document::new |
the same six library calls, ~30 lines |
| cross-file references with open-buffer overlay and stale-span guards | nav.rs:123-519 |
not needed: MCP has no open buffers; vlog_refactor::find_references is the whole-scope oracle the server's answer is pinned equal to |
| hover card rendering | hover.rs |
MCP renders its own compact text (§5.1) |
| design hierarchy snapshot (pure function of the index) | design_hierarchy.rs:88 |
re-done as a walk over instantiations() edges; a later lift into vlog_semantic is a §2.9-style candidate, not a plan item |
index-backed MentionOracle (IndexMentions, ~40 lines) |
lint.rs:487-530 |
copied; it is a thin adapter over public index queries |
| persistent index cache codec (header + one record per line) | index_cache.rs:40,545-559,607-640 |
a read-only reader (~60 lines) over the public FileFacts::decode; §6 |
| file watching, cancel, debounce, settings doors | watch.rs, server/ |
not applicable: stdio, synchronous, one request at a time |
The CLI has a second bin-only MentionOracle (crates/lucisv/src/lint.rs:196)
and the unified-diff printer crates/lucisv/src/diff.rs::unified — the one
piece MCP would like to share (dry-run diffs). It is a Handshake request to
lift it into lucisv_core (§7), not a silent copy.
2.2 The extension and the packaging
editors/vscode is plain CommonJS, one runtime dependency
(vscode-languageclient 9.0.1), engine ^1.82.0. The server binary is found
by extension.js:152 in this order: an explicitly set lucisv.serverPath,
then bin/lucisv-server (platform vsix) or bin/<platform>-<arch>/lucisv-server
(the all-platforms vsix; bundledBinary() at :121-138 is generic and
takes the binary name), then lucisv-server on PATH. The bundled lucisv
CLI is chmod'ed but never spawned (:145). No second process, no status bar.
tools/release.sh stages lucisv and lucisv-server into
editors/vscode/bin/ and asserts each platform vsix holds exactly those
two entries (:158-191), the all-platforms vsix every pair (:202-224);
tools/audit_artifacts.sh hard-fails on an unknown artifact name;
tools/prune_release_assets.sh requires the seven vsix by name; CI's
release.yml runs all three. Adding a third binary is therefore a
three-script change with a test-locked file list — exactly the kind of wire
shape docs/topo.md §3.4 rule 5 says to change by test.
ci.yml runs cargo fmt/clippy/test and the corpus gate; it runs no
extension JavaScript tests (*_test.js are run by hand; smoke.js runs in
the release workflow only). The MCP work adds a stdio wire test that CI
runs, and is a good moment to put node --test editors/vscode/*_test.js in
CI too (a separate line in the packaging lane).
2.3 How VS Code hosts extension-provided MCP servers
Confirmed against the VS Code extension guide (2026-09-23):
package.json:"contributes": { "mcpServerDefinitionProviders": [{ "id": "lucisv.mcp", "label": "lucisv" }] }.- Activation:
vscode.lm.registerMcpServerDefinitionProvider("lucisv.mcp", provider)where the provider hasprovideMcpServerDefinitions()returningvscode.McpServerDefinition[], optionalresolveMcpServerDefinition()(called at server start) andonDidChangeMcpServerDefinitions. new vscode.McpStdioServerDefinition(label, command, args?, env?, version?)— positional, withcwdset as a property afterwards (corrected 2026-09-23 by the M5 dev against VS Code 1.138'svscode.d.ts; the VS Code guide's object form is not what the extension host accepts).- Users see the server under MCP: List Servers and the Extensions view; trust is per server via the Accounts menu. Extension-provided servers are usable by VS Code's agent mode (Copilot).
- The API landed in VS Code 1.101 (June 2025). Our engine is
^1.82.0. Decision: keep the engine, guard the registration withtypeof vscode.lm?.registerMcpServerDefinitionProvider === "function", and bump only ifvscerefuses the contribution point on packaging (it does not validate unknown contribution points today; the lane verifies). An older VS Code simply never sees the MCP server.
2.4 What an agent pays today, and what MCP saves
Without MCP an agent working on a Verilog tree has file tools and grep. The recurring costs, each of which becomes one small tool call:
| task | today | with MCP |
|---|---|---|
| "what does module X take?" | read the whole file (a 40 000-line opentitan file is not rare) | unit_interface — ports, parameters, one instantiation template |
| "who instantiates X / what is under X?" | grep the tree, read every hit to tell instances from mentions | hierarchy — the index's instantiation edges, depth-limited |
"where is foo defined / used?" |
grep, read, disambiguate by hand across packages and hierarchical tails | definition / references — the same cross-file semantics the editor has |
"rename / add a port / expand .*" |
read N files, write N files, hope the edits agree | one verified RefactorEdit, applied atomically; a diff summary back |
| "rewrite this always block" | read the file, write the whole file back (and re-send it all as tokens) | replace_item — send only the new item's text; the tool re-parses and refuses if the file no longer parses |
| "is my edit clean?" | run a simulator, or nothing | diagnostics — parse errors + lint with the project's rules; format — the verified formatter |
The saving is not asserted with numbers here; it is measured in M6 on three canonical opentitan tasks with and without the server (§8).
3. Non-goals (stated so nobody builds them by accident)
- Not an LSP bridge. MCP never talks to
lucisv-server; it never sees unsaved editor buffers. A tool answers from disk, and says so in its description. (VS Code reloads a non-dirty editor when a file changes on disk; a dirty editor shows a conflict — the standard behaviour of any external tool, and thedry_runflag exists for agents that prefer to apply edits through their own editor.) - No HTTP/SSE transport, no OAuth. Stdio only, like the LSP. A host that needs HTTP can wrap the stdio server; none of our target hosts do.
- No shell, no arbitrary file writes. Edit tools write only files inside
the configured roots, only through
write_atomic, only text that passed a verifier. There is no "run this command" tool and there never will be. - No AI in the server. It calls no model. It is a deterministic engine behind a schema; the agent is on the other side of the pipe.
- No new grammar or semantics. Every tool is a composition of existing library calls plus rendering. A tool that needs an engine change files a Handshake (the CLAUDE.md rule) — it does not add language knowledge to the MCP crate.
4. Design
4.1 Crate and binary
crates/lucisv_mcp, binary lucisv-mcp, version.workspace = true.
crates/lucisv_mcp/src/
main.rs arguments (--root DIR…, --filelist F, --index-cache DIR,
--verbose), the stack-sized main thread, the loop
transport.rs newline-delimited JSON-RPC 2.0 over stdio: read one line,
write one line; stderr is the log
rpc.rs the JSON-RPC envelope: id, method, params, error codes;
the initialize handshake and protocol-version negotiation
tools/mod.rs the tool registry: name → (schema, annotations, handler)
tools/read.rs project_overview, list_units, unit_interface, outline,
read_item, search_symbols, defines
tools/nav.rs definition, references, hierarchy, diagnostics
tools/edit.rs format, fix_lint, rename, expand_wildcard, convert_ports,
organize_imports, add_port, remove_port, propagate_ports,
extract_module, inline_module, instantiate
tools/item.rs replace_item, insert_item, delete_item (M4)
project.rs Project: roots, config, the file set, the index, the
per-file analyses, freshness (§4.4)
render.rs the compact text renderings of every answer
apply.rs RefactorEdit → dry-run diff | atomic writes; the summary
resources.rs lucisv://… resources (M2)
Every file targets the CLAUDE.md size rule (300–600 production lines); the tool families are split so that no single module owns more than one family.
Dependencies: none new. The MCP stdio transport is newline-delimited
JSON-RPC, which serde_json (already pinned) handles; the protocol's data
model is small enough to spell out as serde structs in rpc.rs. The
official Rust SDK (rmcp) was considered and rejected for the same reason
lsp-server was chosen over tower-lsp: it brings an async runtime and a
large transitive tree to a server that is one synchronous loop. The
justification lives in the feature README's Assumptions, as CLAUDE.md
requires for any dependency decision.
Synchronous, one request at a time, like lucisv-server. A host may
pipeline requests; they are answered in order. notifications/cancelled is
accepted and ignored (a tool call is bounded by an index rebuild, seconds at
worst on opentitan). The main thread is spawned with
vlog_parser::PARSE_STACK_SIZE — the recursion-limit handshake every parsing
thread in the workspace honours.
4.2 The protocol subset
Pinned by tests in crates/lucisv_mcp/tests/wire.rs (fixtures spawn the
binary, as editors/vscode/smoke.js does for the LSP):
| method | answer |
|---|---|
initialize |
protocolVersion (the client's if we support it, else our newest), capabilities: { tools: {}, resources: {}, prompts: {} }, serverInfo { name: "lucisv-mcp", version }, instructions — a short paragraph telling the agent to prefer unit_interface/outline/read_item over reading files, and that edits are on-disk and verified |
notifications/initialized |
accepted |
ping |
{} |
tools/list |
every tool with name, description, inputSchema (JSON Schema, additionalProperties: false, required), annotations (readOnlyHint, destructiveHint, idempotentHint) — read tools are readOnlyHint: true; edit tools destructiveHint: false (verified, refusable, atomic) |
tools/call |
{ content: [{ type: "text", text }], structuredContent, isError } — text is the compact rendering, structuredContent the JSON the agent can parse; a refusal is isError: true with the engine's own sentence (never a JSON-RPC error — the spec reserves those for protocol faults) |
resources/list, resources/read, resources/templates/list |
M2: lucisv://overview, lucisv://unit/{name}, lucisv://rules (the linter's rules_markdown()), lucisv://file/{path}/outline |
prompts/list, prompts/get |
M6, optional: review-module, add-port walkthroughs — only if the M6 token census shows agents use them |
notifications/cancelled, notifications/progress |
accepted / never sent |
| unknown method | JSON-RPC -32601; unknown tool -32602; invalid params -32602 with the schema path |
The protocol revision: the dev pins the current spec revision at
implementation time (2025-06-18 is the widely deployed one as this plan is
written; a newer revision exists) and lists every revision the server
accepts in rpc.rs — negotiation is "echo the client's if listed". No
JSON-RPC batching (removed from the spec). Lines are UTF-8, no embedded
newlines, stdout is protocol-only, stderr is human-only.
4.3 The tools
Superseded by §10 (the lean catalogue, 0.58). Kept as the record of the 0.57 surface.
Inputs name things the way an agent already has them: a file path
(absolute or root-relative), a unit name, a line (1-based) and
optional column, or a symbol name with an optional unit. Outputs
always come in two forms — structuredContent (JSON) and the text
rendering — and the text is the token-conscious one: no repetition, paths
root-relative, one line per fact.
Read tools (M1 unless marked).
| tool | input | output |
|---|---|---|
project_overview |
— | roots, config file, filelist, file count, units by kind, index age, top-level modules (no parent), the 10 largest files |
list_units |
kind? (module/interface/package/class/program), glob? |
name, kind, file:line per unit |
unit_interface |
name |
parameters (name, default), ports (dir, type, range, name) in declaration order, plus an instantiation template (instantiation_plan); interfaces list modports; packages list exports |
outline |
file, depth? |
the hierarchical document symbols with line ranges (Semantics::document_symbols) |
read_item |
file, item (a name or kind:name; for unlabelled blocks always@<line>) |
the item's exact text and its line range — a slice, not the file |
search_symbols |
query, limit? |
WorkspaceIndex::workspace_symbols (fuzzy) |
defines (M2) |
file?, name? |
the `define table; one-step expansion when name is given with args |
Navigation (M2).
| tool | input | output |
|---|---|---|
definition |
file, line, col or name, unit? |
every declaration site (ambiguity is a list, never a guess); the declaration's own source line |
references |
same selector, include_declaration? |
vlog_refactor::find_references — file:line:col + the line's text, grouped by file, capped with a count |
hierarchy |
root?, direction (down/up), depth? |
instance tree: instance_name : module with parameter overrides when written, from instantiations(); up lists parents |
diagnostics |
file? (else the workspace), rules?, severity? |
parse errors, missing-closer warnings, lint findings — the same {filename, rule, severity, message, location} shape lucisv check --output-format json prints, so one JSON contract serves CI and agents |
Edit tools (M3). All take dry_run? (default false). dry_run returns
the unified diff and touches nothing. A real run writes each file with
write_atomic, then returns the summary: files changed, lines added/removed
per file, the engine's warnings, files created. A refusal returns
isError: true with the engine's sentence and no file is touched — the
RefactorEdit is all-or-nothing, and so is the write loop (every file's new
text is computed and verified before the first write; a write failure after
a successful write is reported as such — the same posture the CLI has).
| tool | wraps |
|---|---|
format |
format_source over files[], or format_range with lines — the safety net decides; --check-style dry_run diff |
fix_lint |
apply_fixes filtered through fence::protected_regions — the CLI's --fix path, safe fixes only |
rename |
vlog_refactor::rename(files, file, offset, new_name); selector as definition |
expand_wildcard, convert_ports, organize_imports, inline_module, propagate_ports, remove_port |
(files, file, offset) |
add_port |
ModuleRef::Name + the declaration text |
extract_module |
file, start_line, end_line, new_name, home (new file / same file) |
instantiate |
instantiation_plan → text only, style (named/wildcard, with/without params); never an edit |
Structural edits (M4) — the general token saver, and the one new piece of logic in the block:
| tool | contract |
|---|---|
replace_item |
file, item, text: the bytes of exactly that item (as read_item slices it) are replaced by text; nothing outside the span changes; the result is refused unless the file still parses strictly (or already did not, in which case the error count must not grow), the item at that position is one item, and — when text declares a name — the name is the one asked for (or rename: true was passed). Comments inside the old item are the agent's to keep; comments outside it are structurally untouched |
insert_item |
`file, anchor (item |
delete_item |
file, item: the item and its own leading comments (the AST's Meta::leading), nothing else; refused if a reference to a declaration it owns survives in the workspace (via references) unless force: true |
These three are the closest MCP comes to CLAUDE.md invariant 1. They ship
with attack tests in the same change (a text that opens a block it does not
close; a text that closes the enclosing module; an item name that shadows
a port; a UTF-8 boundary; a fenced region; a file with an unterminated
string), asserted refused, re-attacked by QA. format after replace_item
is the agent's choice, not implicit.
4.4 The workspace model and freshness
project.rs owns one Project:
- Roots from
--root(repeatable) or the current directory. Every path a tool takes must resolve inside a root; anything else is refused. - Config:
Discovery::for_dir(root)→exclude,filelist, format and lint settings — the same ladder the CLI and the editor use, minus editor settings (there are none here). - File set: the configured
filelistif any (the editor's rung 1), elsewalk::collect_files_withover the roots with.gitignoreandexcludehonoured and a 1 MiB per-file cap (the editor'slucisv.index.maxFileSizedefault), each file's size recorded.--filelistoverrides. - Index:
IndexBuilder::add_fileper file on the stack-sized thread,finish(); per-fileSemanticscomputed lazily and kept (ananalyzed()cache keyed by content hash). - Freshness: at the start of every
tools/call, stat every file in the set (size + mtime); a changed or missing file is re-read, re-hashed andupdate_filed /remove_filed; a walk is re-run when a file went missing, onproject_overview, or when the last walk is older than 5 s, so new files appear. The promise: a tool never answers from a file older than the disk at the moment the call arrived. Fingerprint equality with a full rebuild is asserted in tests after every update path (theupdate.rsoracle already exists).
Opentitan (~3 000 files) is the size reference: the stat sweep is
milliseconds; the initial build is whatever IndexBuilder costs today (the
LSP's scan trace numbers in docs/perf/README.md are the baseline — M6
records MCP's own).
4.5 Rendering rules (the token budget is the product)
Superseded by §10.2. Kept as the record of the 0.57 rules.
- Paths root-relative; a file named once per group, never per line.
- Line numbers 1-based, columns 1-based, in
file:line:colform. - Lists capped (
limit, default 500 since feedback-2) with… and N more— the agent can page withoffset. - A declaration is shown as its own source line, trimmed, never the surrounding block.
- No prose, no markdown headings inside a tool result; a table only where the columns are fixed (ports).
instructionsatinitializeand every tooldescriptionare written for the agent that reads them once: one sentence each on what the tool answers, when to prefer it over reading a file, and what it refuses.
5. Distribution
5.1 The vsix carries three binaries
tools/release.sh: package_vsix stages lucisv-mcp[.exe] beside the two
existing binaries and the expect_vsix_bins list grows to three entries per
platform (and per pair in the all-platforms package); audit_artifacts.sh
learns the third name; prune_release_assets.sh is unchanged (it keys on
the seven vsix names, which do not change). release.sh smoke-tests the
embedded lucisv-mcp the way it smokes lucisv-server: a Node script
(editors/vscode/mcp_smoke.js) sends initialize, tools/list and one
project_overview over stdio and checks the answers. The universal vsix
still carries no binaries and looks lucisv-mcp up on PATH.
5.2 The extension registers it
editors/vscode/mcp.js (new, ~80 lines, unit-tested like restart.js):
- resolves the binary with the same three-rung ladder as the server
(
lucisv.mcp.pathset explicitly →bundledBinary(context, "lucisv-mcp")→lucisv-mcponPATH); - if
vscode.lm.registerMcpServerDefinitionProviderexists andlucisv.mcp.enabled(defaulttrue), registers providerlucisv.mcpreturning oneMcpStdioServerDefinitionper workspace folder:new McpStdioServerDefinition("lucisv (<folder>)", command, ["--root", folder, "--index-cache", storagePath], undefined, version)withcwd = folderset afterwards, re-fired on workspace-folder changes; - contributes the command lucisv: Copy MCP server config that puts a
JSON snippet on the clipboard in the host's dialect (Claude Code
.mcp.json→mcpServers; Cursor.cursor/mcp.json; VS Code.vscode/mcp.json→servers) pointing at the resolved binary — because Claude Code and Cursor do not read VS Code's provider registry, and the vsix is where the binary is; package.json:contributes.mcpServerDefinitionProviders, the two settings, the command;activationEventsunchanged (the language activation is enough; VS Code also activates on the contribution point).
Engine stays ^1.82.0 with the runtime guard (§2.3), unless vsce objects.
5.3 Standalone
cargo build --release yields target/release/lucisv-mcp; the docs site
gets an "Agents (MCP)" guide page with the one-line claude mcp add lucisv -- lucisv-mcp --root . and the Cursor/VS Code snippets. Loose binaries stay
unattached on the release page, as today (docs/features/editor-platform-vsix).
6. Interaction with the LSP: the index cache
The LSP persists one FileFacts record per file (index-cache, header
lucisv-index-cache\t2\t20\t<version>, one hash\tfacts\tchecksum line
per record; atomically compacted, appended by single write_alls) — safe to
read concurrently, keyed by content hash, never by time. Its location is
the lucisv.index.cachePath setting, else VS Code's storagePath, else the
OS cache dir keyed by the roots.
MCP reads it read-only when --index-cache DIR names it (the extension
passes the same storagePath to both processes; a CLI user may pass the OS
path): a file whose content hash has a record skips its parse at startup.
MCP never writes that store — two writers would need the coordination
docs/features/atomic-write-coordination had to build for the CLI, and the
warm start is a shortcut, not a need. MCP keeps its own index-cache-mcp in
the same directory with the same codec (M6), so the LSP could read it in
turn if anyone ever wants that (not planned). A version or FACTS_FORMAT
mismatch ignores the store, exactly as the LSP does.
7. Handshakes filed by this plan (requests, not edits)
| # | to | request | why |
|---|---|---|---|
| MCP-1 | lucisv CLI → lucisv_core |
lift crates/lucisv/src/diff.rs::unified into lucisv_core::diff (pure move; the CLI re-exports) |
dry_run diffs; two copies of a diff printer is exactly the duplication CLAUDE.md forbids |
| MCP-2 | lucisv_server (informational) |
none required; recorded so docs/topo.md §2.8 can add editors/vscode ─▶ lucisv_mcp (spawn contract) and tools/ ─▶ lucisv_mcp (packaging) rows after M5 merges |
the topology stays the authority on collisions |
| MCP-3 | vlog_semantic (candidate, not requested) |
if M2's hierarchy and the server's design_hierarchy::snapshot drift, lift the snapshot walk into vlog_semantic::workspace::hierarchy |
one instance tree for the sidebar and the agent |
8. Acceptance (what "done" means for the block)
- Protocol: an
initializehandshake and every tool exercised bytests/wire.rsover the real binary; Claude Code, Cursor and VS Code agent mode each list the tools and completeproject_overviewon a fixture (manual, recorded indocs/manual-acceptance.md). - Parity: on opentitan (read-only),
referencesfor the five symbolsdocs/features/references-navuses,definitionfor the same, andhierarchydown fromtop_earlgrey, equal to the LSP's answers modulo rendering (the census is a test with the paths as#[ignore]inputs, like the server's perf harness). - Safety: every edit tool run twice is a no-op the second time; every
refusal leaves the tree byte-identical (
git statusempty in the test); the M4 attack suite is green and QA added to it. - Token census (M6): three canonical tasks on opentitan, each run by an
agent with file tools only and with lucisv-mcp — (a) "list every
instance of
prim_fifo_syncwith itsWidth/Depthoverrides", (b) "add aninput logic dbg_iport toaes_coreand propagate it to the top", (c) "renameentropy_src_hw_if_iinaes" — with the tokens in and out recorded indocs/mcp/census.md. This is the number the owner asked the block for; it is measured, not asserted. - Packaging: every platform vsix holds the three binaries; the
darwin-arm64 one installed, the MCP server visible in MCP: List
Servers,
project_overviewanswered inside VS Code agent mode; the universal vsix still installs on a machine with no binaries. - Gates: fmt, clippy, workspace tests green through
tools/guard.sh; no file over 600 production lines in the new crate; nounwrapin library paths; every feature README complete with QA log.
9. Order and lanes (the short version; TODO-MCP.md has the checkboxes)
M1 transport + read tools ──▶ M2 navigation + resources ──▶ M3 edit tools ──▶ M4 structural edits
└──▶ M5 packaging + extension (parallel from M1: disjoint files)
M4, M5 ──▶ M6 cache reuse, freshness polish, census, docs, release
M1 first because everything else is a tool on its transport; M5 can start
the moment M1's binary name and arguments are fixed (it packages a binary
that already answers initialize), and its files (tools/, editors/,
CI) are disjoint from the crate — the one proven-parallel pair. M2/M3/M4
are serial (same crate, same registry). M6 closes the block with a release.
Roles per CLAUDE.md: one Opus dev then one Sonnet QA per lane, in a worktree
branched from trunk; the lead reviews and merges; the block ships as a minor
release (0.56.0 if it lands before anything else does).
10. The lean catalogue (0.58 — the owner's steer of 2026-09-23)
The census (mcp_analysis.md) showed the server correct on every run and
dearer than plain file reads on every small task, for three reasons: a
5 400-token catalogue read every session, answers that carry more than the
question needs, and an agent that dry-runs and re-checks what it was told
to trust. The owner's ruling: accuracy over breadth. The server's
distinct value is the hierarchy of the project — where things are, as
file:line, with a way to peek at the code — and bulk edits that a file
write cannot do safely. So: nine tools, the whole model-visible catalogue
(name + description + inputSchema of every tool, compact JSON) under
3 500 bytes (≈ 1 000 tokens) and instructions under 400 bytes, both
pinned by test; short answers by default; no dry_run, no paging arguments;
edits are file writes the agent is told to trust.
10.1 The nine tools
Arguments carry no per-argument descriptions — the one-sentence tool
description names them. Each schema is {type, properties, required, additionalProperties: false} with type alone per property (an enum
where one applies). title and structuredContent are gone; a result is
its text. The annotations stay (readOnlyHint, destructiveHint: false)
— hosts use them, the model never sees them.
| tool | arguments | answers |
|---|---|---|
hierarchy |
root?, up? (bool), depth? (1–20, default 1), peek? (bool) |
Without root: one line N files, M modules, K top then the top modules as name file:line. With root, down: the instance tree, one line per instance, two spaces per level: instance: module file:line where file:line is the instantiation site. up: every instantiation of root, parent.instance file:line, all levels up to depth. peek: true appends each instantiation statement's source under its line (indented, as written, at most 12 lines each then …). Cap 300 instances, 100 with peek; peek lines do not count; then … and N more. Unknown root: a refusal that lists up to 10 contains-matches. |
find |
name, refs? (bool) |
Every declaration of name (whole-name, any case-exact): kind name file:line, then, with refs, per declaration its uses as file:line (one file per line, lines joined with , when several are in one file: ip/uart/rtl/uart.sv:120,133,140), then unresolved: and the textual mentions (strings, comments, macro text) the same way. No declaration: up to 20 contains-matches of declarations as a refusal (no declaration named X; similar: …). Cap 300 lines. |
outline |
file? or unit? (exactly one) |
file: its declarations as a tree with line ranges, two spaces per level: kind name start–end, parse errors first as error line: message. unit: its file:line, then parameters param name = default and ports dir type[range] name in declaration order, one per line; interfaces add modports, packages their exports. No template, no counts. Cap 300 lines. |
read |
item, file? |
The item's source, exact bytes, preceded by one line file:start–end. Selector as today's read_item (name, kind:name, name@LINE, always@LINE). Without file the item is looked up design-wide; several matches → a refusal listing them as file:line. |
check |
file? |
Parse errors, missing closers and lint findings of file or the whole design, file:line:col severity message [rule], errors first, cap 200 lines then … and N more. Clean: ok (one word). |
rename |
name, new_name, file? |
Renames the declaration name (in file when the name is declared in more than one place; ambiguity without file is a refusal that lists the declarations) and every resolved use, .name/.* shorthand included (M3.5). Answer: renamed N sites in M files and, only when any, unresolved: lines as in find. |
port |
module, add? (a port declaration), after?, remove? (a port name) |
Exactly one of add/remove. add inserts the ANSI port (after port after, else last) and connects it by name in every instantiation; remove deletes the port and its connection everywhere, refused while the module body uses it. Answer: `added |
edit_item |
file, op (replace / insert_before / insert_after / delete), item, text? |
The M4 structural edits under one name, same verifier, same rules: replace keeps kind and names; insert_* anchors on item (or end / end@UNIT); delete takes the item and its leading comments and is refused while its names are used (sites listed) or it holds a `define. No force, no rename. Answer: `replaced |
format |
files (a path or a glob), fix? (bool) |
Formats every matching file; fix applies the safe lint fixes first. Answer: formatted N files (M unchanged); a refusal per file the safety net rejects, the rest still written. |
Dropped from the catalogue (the engines stay in the CLI and the LSP):
project_overview, list_units, unit_interface, read_item,
search_symbols, defines, definition, references, diagnostics,
fix_lint, expand_wildcard, convert_ports, organize_imports,
inline_module, propagate_ports, remove_port, add_port,
extract_module, replace_item, insert_item, delete_item,
instantiate. A \defineis found byfind like any declaration (macro NAME file:line`).
10.2 Rendering rules (replacing §4.5)
- One line per fact, root-relative paths,
file:line, no headers, no blank lines, no trailing hints (check:is gone — the instructions say when to check). - Fixed caps per tool (300 / 200 lines) with one
… and N moreline; nolimit/offset. Narrowing is by a better question (root,file,depth). - Counts only where they are the answer (
hierarchywithoutroot,rename,port,format). - Refusals are one sentence,
isError: true, and when a name is unknown they list the near matches so the next call is right.
10.3 Instructions (≤ 400 bytes; the shipped text, 398 bytes)
lucisv-mcp reads the SystemVerilog on disk (save first). Use it before reading files: hierarchy for instance trees and top modules, find for a name's declarations and uses, outline for a file or unit's ports, read for one item, check after edits. Edits (rename, port, edit_item, format) are verified, all-or-nothing writes: trust them as file writes, no dry run. Paths root-relative, lines 1-based.
10.4 What stays
Transport, freshness, roots, the filelist, the cache reader, the resources
(lucisv://overview, unit/{name}, file/{path}/outline render through the
new renderers; lucisv://rules stays), the apply path (all-or-nothing,
re-read before write, atomic inside the roots), the M4 verifier and its
attack tests, the unresolved-mentions scan, the extension provider and the
packaging. mcp_smoke.js --tool-table keeps working and regenerates the
Agents guide's table.
10.5 Acceptance
tools/list: exactly the nine names above, in that order; the model-visible bytes ≤ 3 500,instructions≤ 400 — a test inwire.rscomputes both.- No
dry_run,limit,offset,in,template,overrides,forceargument anywhere. - The eval tasks a–d (
~/.cache/lucisv-eval/tasks) re-run as census round 4 on the lean binary, all four correct, and the mcp arm at or under the base arm on a and d; b and c within +10 %. - The M4 attack suite green unchanged;
checkon the fixtures identical to the olddiagnosticsline set;hierarchyon opentitan'stop_earlgreyidentical instance set to the old tool.
11. Read-only mode (0.59 — the owner's request of 2026-09-29)
One binary, two modes. lucisv-mcp --read-only offers only the five read
tools and shorter instructions; without the flag nothing changes (the nine
tools of §10). The two co-exist: a host may configure both side by side
under two names, and the extension chooses by a setting.
11.1 The server
-
Flag
--read-only(no value). Usage line:usage: lucisv-mcp [--root DIR]... [--filelist FILE] [--index-cache DIR] [--read-only] [--verbose]. -
tools/listin read-only mode: exactlyhierarchy, find, outline, read, check, in that order, the same descriptions and schemas as in full mode exceptcheck, whose words "after edits" do not apply (one description for both modes if it reads right in both; otherwise a read-only wording). Model-visible bytes (compact JSON of name + description + inputSchema) ≤ 1 800, pinned by test. -
tools/callofrename,port,edit_itemorformatin read-only mode is the unknown-tool error (-32602), messageunknown tool: rename (the server runs --read-only). The edit handlers are not reachable: the mode filters the registry, it does not flag inside each handler. -
Instructions in read-only mode, ≤ 300 bytes, pinned by test:
lucisv-mcp reads the SystemVerilog on disk (save first); it never edits. Use it before reading files: hierarchy for instance trees and top modules, find for a name's declarations and uses, outline for a file or unit's ports, read for one item, check for issues. Paths root-relative, lines 1-based.
-
The promise: in read-only mode no file inside a root is created, written, renamed or removed by a tool, whatever is called. The server's own index store under
--index-cacheis still written (it is what makes the next start warm); the extension passes VS Code's workspace storage, which is outside the folder — a user who points--index-cacheinside a root gets that directory written there. A test walks the fixture tree's sizes, mtimes and names before and after calling every tool name of the full catalogue. -
Resources, transport, freshness, annotations: unchanged.
11.2 The extension
- Setting
lucisv.mcp.mode:"full"(default) or"read-only"; any other value is treated as read-only and logged (a typo must not land on the mode that can write). In read-only mode the definition's args gain--read-onlyand its label islucisv read-only (<folder>); a change of the setting fires the provider's change event, likelucisv.mcp.enabled. - lucisv: Copy MCP server config follows the setting: in read-only
mode the snippet's args end with
--read-only, the server key islucisv-ro, and the message says which mode was copied. (Two keys, so a user can paste both.) mcp_smoke.js <binary> --read-onlysmokes that mode (five tools in order, onehierarchy, andrenameanswered with the unknown-tool error);tools/release.shruns both smokes on the host binary and on the embedded one.
11.3 Acceptance
- Full mode byte-identical on the wire to 0.58.0 (
tools/list,instructions), except the usage line. - Read-only budgets met and pinned; the no-write test green; the extension's node tests cover the setting, the label, the args and the snippet.
- Census round 5 (lead): tasks a and d on the read-only mode, against round 4's full-mode figures.