15 KiB
mcp_analysis.md — does lucisv-mcp help an agent? (the token census)
Owner's brief (2026-09-23): after the MCP block is complete, run the server against the OpenTitan tree, have sub-agents do real edits with and without it, compare the token usage, feed what is learned back into the server, and repeat for at least three rounds. This file is the record. It is written by the lead; numbers are measured, not asserted.
Method
Harness. ~/.cache/lucisv-eval/ (durable, outside the volatile session
scratchpad): a local clone of OpenTitan (ot/, 0098135), the three task
prompts (tasks/{a,b,c}.txt), the frozen server binary per round
(bin/lucisv-mcp-r<N>), and a stdio shim (mcpc <tool> '<json>',
mcpc --list) that runs one MCP session per call. Why a shim and
sub-agents rather than a headless claude -p --mcp-config session: the
claude CLI on this machine has an expired OAuth session that only the
owner can renew, and the lead's own agent harness cannot attach a new MCP
server mid-session. The shim costs the agent the same tokens a native tool
result would (the answer text lands in its context either way); what it
loses is the persistent process (each call re-indexes, ~1–2 s) and the
tool-schema exposure a host gives natively (the agent reads --list once
instead).
Arms. For each task, one sub-agent per arm, same model, same prompt
text, same clean clone (git checkout -- . && git clean -fdq before every
run), one agent at a time:
- base — ordinary file tools and search (
rg), no lucisv binaries; - mcp — the same, plus the shim and one paragraph telling it which
tools to prefer (the server's own
instructions, paraphrased).
Model. Claude Sonnet 5 for the arms (cost); one Opus 5.5 confirmation run on the hardest task in the last round if the budget allows. The lead grades.
Metrics per run. Tokens (the harness's total for the sub-agent, input plus output across all its turns), tool calls, wall time, and the outcome graded against a lead-computed ground truth:
- a (read-only census): set equality with
results/truth_a.txt— the 47 RTL instantiations ofprim_fifo_syncunderhw/ip/with theirWidth/Depthoverrides, computed withhierarchy upand checked by hand against the files (DV, FPV,ip_templatesandtop_*/ip_autogenexcluded by the task's wording); - b (two-file port propagation): the diff touches exactly
aes_cipher_core.svandaes_core.sv, addsinput logic dbg_iafterrst_niin both, and connects.dbg_i(dbg_i)on the instance; both files parse (diagnostics); style matches the neighbours; - c (cross-file rename): the seven sites in
results/truth_c.txtare renamed — five the engine sees, plus a macro-argument use (`PRIM_FLOP_SPARSE_FSM(…, state_q, …)) and a macro-rooted hierarchical path intop_earlgrey/dv/env/chip_if.sv— and none of the csrng/ednstate_qsites move; - hygiene: any file touched outside the task is a failure.
Rounds. After each round the mcp-arm transcripts are read for tool
misuse, refusals the agent could not recover from, and answers it had to
re-derive by reading files anyway; each becomes a change to the server
(descriptions, instructions, rendering, a missing tool, a bug) through a
dev+QA lane, the binary is re-frozen, and the round repeats.
Round 1 — server at 0f4830a (M1–M6 as committed)
| task | arm | tokens | tool calls | wall | outcome |
|---|---|---|---|---|---|
| a | base | 91 094 | 10 | 114 s | correct, 47/47 |
| a | mcp | 107 605 | 14 | 335 s | correct, 47/47 |
| b | base | 59 922 | 11 | 25 s | correct, clean |
| b | mcp | 74 720 | 17 | 78 s | correct, identical diff |
| c | base | 87 546 | 34 | 172 s | correct, 8/8 sites |
| c | mcp | 104 837 | 35 | 171 s | incomplete, 7/8 sites |
Observations
The server did not pay for itself in round 1. On every task the mcp arm
used more tokens than the base arm (+18 %, +25 %, +20 %), took longer, and
on the rename it was less complete. Sonnet with plain file tools is a
strong baseline on a tree this well organised: rg finds instantiations
and hierarchical paths by text, and reading a 1 000-line file is cheap
compared with a catalogue of 26 tool schemas plus several calls that each
re-index the tree through the shim. What the transcripts show:
- Wrong tool for the census (a). The agent asked
referencesfor the module name — a whole-set engine call, ≈4 s per shim call — and then read the instantiating files for the overrides.hierarchy upanswers the question in one call, instance names and#(…)overrides included; nothing in the descriptions told the agent so. - The catalogue is a fixed tax. The shim's condensed
--listis 11.6 kB (≈3 000 tokens; the rawtools/listJSON a native host sends is 30.3 kB, ≈7 500 tokens). Read once, it costs the mcp arm those tokens before any work — on a 25-second task (b) that is most of the gap. - Verified edits were not the bottleneck on b. Both arms produced the
identical three-line diff; the mcp arm's extra calls were
diagnosticschecks (useful, but they cost).add_portwas not used: it appends a port, and the task wanted a specific position with the file's alignment. - The rename missed what no engine sees, and said nothing (c). The
renametool renamed five sites and warned about the macro argument (the agent fixed it). It found the macro-rootedchip_if.svpath by its own search. It never looked for the DV string".state_q"that builds a force path, because nothing in the answer said "the old name is still spelled in these files as text". The base arm's broadrgfound it. A rename that lists the unresolved textual mentions of the old name — strings, comments, macro text, across the whole set — would have handed the agent exactly that list. - What worked: every
dry_run/diagnosticsanswer was trusted and correct; the macro-argument warning was acted on; the line-length lint finding onchip_if.svwas fixed by the agent (the base arm left a 105-column line). Correctness of the server's answers was never the problem; discoverability and completeness of what it says were.
Changes for round 2 (dev+QA lane "feedback-1"): (i) rename and
references end with an "unresolved mentions" section — every whole-word
spelling of the name in strings, comments and macro text across the whole
set, as file:line, with the sentence that the engine did not resolve them;
(ii) hierarchy's description leads with "who instantiates X — instance
names and parameter overrides", references' description points a module
name at hierarchy up, and instructions say the same in one line;
(iii) add_port takes an optional after port name so a positioned
insertion is one verified call; (iv) descriptions trimmed by about 40 % (30 kB → ≤ 18 kB of tools/list
JSON) — the catalogue is read by every agent on every session; (v) M6 QA's orphaned
temp-file sweep. The shim's per-call re-index is a harness artefact, not a
product one; a native host keeps the process alive, so wall time is not
graded.
Round 2 — server at 4671b91 (feedback-1 applied)
Base arms are independent of the server, so rounds 2 and 3 re-run only the mcp arms; task c's base arm is re-run once for run-to-run variance.
| task | arm | tokens | tool calls | wall | outcome |
|---|---|---|---|---|---|
| a | mcp | 106 938 | 7 | 105 s | incomplete, 35/47 |
| b | mcp | 70 136 | 18 | 86 s | correct, identical diff |
| c | mcp | 98 636 | 35 | 206 s | correct, 8/8 sites |
| c | base (re-run) | 92 625 | 30 | 131 s | correct, 8/8 sites |
Observations
Completeness moved; tokens did not. The rename (c) is now complete —
the unresolved-mentions list put the DV string path in front of the agent
and it fixed it — at 99 k tokens against the base arm's 88–93 k
(run-to-run variance on the base arm is about 6 %, so c is now a wash on
tokens and a win on correctness). Task b is unchanged: an identical
three-line diff either way, the mcp arm ~15 % dearer for its diagnostics
checks. Task a regressed: the agent now reached for hierarchy up
(7 calls, half the wall time) but paged the 77-row answer with a small
limit and never read the trailing "… and 28 more" line — 35 of 47
instantiations reported as "complete and final". Two lessons:
- Put the total first. A paged answer must open with
77 instantiations (showing 1–50); a count at the bottom is invisible to an agent that stops reading when the table looks done. The defaultlimitof 200 is also too low for a "list everything" question on a 4 000-file tree once DV and FPV rows are interleaved with RTL. - Let the agent filter by path. All three census tasks wanted "under
ip/, RTL only"; every mcp run spent turns droppingdv/,fpv/,ip_templates/rows by hand. A path filter on the listing tools (in: "ip/**/rtl/*") would return exactly the rows asked for.
Changes for round 3 (lane "feedback-2"): (i) every paged answer
opens with N <things> (showing a–b) and the cap moves to 500 by default;
(ii) hierarchy, references, list_units, search_symbols and
diagnostics take an optional in path glob (*, **, ?), applied to
root-relative paths; (iii) the rename/add_port answers end with one
line naming the files to check with diagnostics (the agents ran it
anyway; saying so saves a decision). Round 3 also adds a fourth,
understanding-heavy task (d: the instance tree of entropy_src to depth 3
with each leaf module's port count) where reading files is the expensive
path, and repeats task c with Opus 5.5 on both arms once.
Round 3 — server at c2e42b8 (feedback-1 + feedback-2 applied)
Tasks a–c as before (mcp arms), the new task d on both arms, and task c once more with Opus 5.5 on both arms.
| task | arm | model | tokens | tool calls | wall | outcome |
|---|---|---|---|---|---|---|
| a | mcp | Sonnet 5 | 77 708 | 9 | 72 s | correct, 47/47 |
| b | mcp | Sonnet 5 | 70 030 | 17 | 79 s | correct, identical diff |
| c | mcp | Sonnet 5 | 109 650 | 40 | 218 s | correct, 8/8 sites |
| d | base | Sonnet 5 | 102 579 | 33 | 235 s | correct, 71/20, all counts |
| d | mcp | Sonnet 5 | 106 942 | 12 | 305 s | correct, 71/20, all counts |
| c | base | Opus 5.5 | 61 092 | 7 | 44 s | correct, 8/8 sites |
| c | mcp | Opus 5.5 | 69 849 | 8 | 62 s | correct, 8/8 sites |
Observations
The census task finally paid: −15 % tokens, −37 % wall, 47/47. With the
count line first and the in path filter, hierarchy up prim_fifo_sync
with in: "ip/**/rtl/*.sv" is one call that answers the whole question;
the agent spent its remaining turns formatting. Every other task is at or
slightly above the base arm on tokens and complete on correctness:
- b (port propagation): +17 %, identical diff both ways, three rounds
running. The task is too small for a server to help: two files, three
lines, and the agent edits them by hand either way; the mcp arm pays the
catalogue and its
diagnosticschecks. - c (cross-file rename): complete in every round since feedback-1, at +19 % (Sonnet) and +14 % (Opus) over the base arm. What the server buys here is not tokens but certainty: the base arm's completeness rests on the agent choosing a broad enough search; the mcp arm gets the engine's sites, the macro warning and the unresolved-mentions list handed to it.
- d (a 71-instance hierarchy with 20 port counts): +4 % tokens, a third
of the tool calls (12 vs 33). The answer text dominates both arms; the
server's overhead is twenty
unit_interfaceanswers each carrying a 30-line instantiation template the task never used. Making the template opt-in (feedback-3) removes roughly 15 k tokens from this run. - Opus vs Sonnet on c: Opus needed 7–8 calls and ~65 k tokens either way, Sonnet 30–40 calls and ~100 k; the server's relative overhead is the same (+14 % vs +19 %). A stronger agent does not need the server more; it needs it less, and uses it more economically when it has it.
What the shim costs. Every mcp-arm call re-indexes the tree (1–2 s) and
the catalogue is read as text (≈3 000 tokens per session). A native host
keeps the process alive and sends the 18 kB tools/list JSON as tool
schemas (≈7 000 tokens, once per session, cached by the API). The wall
times above therefore overstate the server's latency; the token figures
understate the catalogue tax a native host pays and overstate the
per-call overhead. Neither changes the ranking.
Round 3b — re-measure on the final binary (2954ae8, feedback-3 applied)
| task | arm | model | tokens | tool calls | wall | outcome |
|---|---|---|---|---|---|---|
| d | mcp | Sonnet 5 | 96 416 | 10 | 231 s | correct, 71/20, all counts |
| a | mcp | Sonnet 5 | 111 444 | 12 | 169 s | correct, 47/47 |
With the template opt-in, task d drops from 106 942 to 96 416 tokens
(−10 %), now 6 % under the base arm's 102 579 with a third of its tool
calls. Task a moves the other way: the agent never passed
overrides: true, read each instantiation's #(…) from the files instead,
and grep-verified the count — 111 k tokens against round 3's 78 k, still
under round 1's 108 k. The two runs are the same lesson from both sides:
an opt-in that the agent does not discover costs more than the bytes it
saves, and a default that carries what most questions do not need costs
every question. The right default is the one a native host's schema makes
visible — the flag is in the tool's argument list, which a native client
shows the model and the shim's --list only summarises — so this
trade-off is best re-measured once the server is driven natively.
Verdict, and what to do next
Helpful, not a toy — for the questions an engine answers better than text search, and for the guarantees. Across three rounds and 20 runs the server never gave a wrong answer; every edit it wrote parsed, and every refusal was right. Its measured value is: (1) one-call answers to whole-design questions (who instantiates X, filtered by path) at fewer tokens and a third of the wall time; (2) completeness on cross-file edits that text search gets right only when the agent chooses a broad enough search — the unresolved-mentions list turned a 7/8 into 8/8; (3) verified, all-or-nothing writes with a diff first, which the agents used and trusted. Its measured cost is a fixed catalogue tax and verbose answers, which is why small edit tasks come out 15–20 % dearer in tokens.
Improvements that fell out of the loop and landed (feedback-1/2): the
unresolved-mentions section; hierarchy/references routing and a 40 %
smaller catalogue; the count line first; default limit 500; the in path
filter; positioned add_port; post-edit check hints.
Still to do (feedback-3 and after): the instantiation template opt-in
on unit_interface; a terser hierarchy line (overrides only on request);
then re-measure d. Beyond rendering, the token win will come from letting
the agent ask compound questions — one call for "instances of X under
ip/ with each target's port count" — which is a tool that composes
hierarchy and unit_interface; the census says that is where the next
15 % is.