Files
lucisv/mcp_analysis.md
T
lucioandClaude Fable 5.1 74c56318c0
ci / checks (push) Successful in 2m11s
ci / corpus (push) Successful in 45s
MCP: hierarchy caps at 300 instances (100 with peek), peek lines no longer count; census round 5 (read-only, same-day base control) written up; 0.59.0 notes dated
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]>
2026-09-29 01:38:54 -07:00

412 lines
24 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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 of `prim_fifo_sync` under `hw/ip/` with their
`Width`/`Depth` overrides, computed with `hierarchy up` and checked by
hand against the files (DV, FPV, `ip_templates` and `top_*/ip_autogen`
excluded by the task's wording);
- **b** (two-file port propagation): the diff touches exactly
`aes_cipher_core.sv` and `aes_core.sv`, adds `input logic dbg_i` after
`rst_ni` in 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.txt` are
renamed — five the engine sees, plus a macro-argument use
(`` `PRIM_FLOP_SPARSE_FSM(…, state_q, …) ``) and a macro-rooted
hierarchical path in `top_earlgrey/dv/env/chip_if.sv` — and none of the
csrng/edn `state_q` sites 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:
1. **Wrong tool for the census (a).** The agent asked `references` for the
module name — a whole-set engine call, ≈4 s per shim call — and then
read the instantiating files for the overrides. `hierarchy up` answers
the question in one call, instance names and `#(…)` overrides included;
nothing in the descriptions told the agent so.
2. **The catalogue is a fixed tax.** The shim's condensed `--list` is
11.6 kB (≈3 000 tokens; the raw `tools/list` JSON 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.
3. **Verified edits were not the bottleneck on b.** Both arms produced the
identical three-line diff; the mcp arm's extra calls were `diagnostics`
checks (useful, but they cost). `add_port` was not used: it appends a
port, and the task wanted a specific position with the file's alignment.
4. **The rename missed what no engine sees, and said nothing (c).** The
`rename` tool renamed five sites and warned about the macro argument
(the agent fixed it). It found the macro-rooted `chip_if.sv` path 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 broad `rg`
found 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.
5. **What worked:** every `dry_run`/`diagnostics` answer was trusted and
correct; the macro-argument warning was acted on; the line-length lint
finding on `chip_if.sv` was 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:
1. **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 default
`limit` of 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.
2. **Let the agent filter by path.** All three census tasks wanted "under
`ip/`, RTL only"; every mcp run spent turns dropping `dv/`, `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 `diagnostics` checks.
- **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_interface` answers 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.
## Round 4 — server at bfa8e98 (M7, the lean catalogue)
The owner's ruling after round 3: accuracy over breadth, the hierarchy as
`file:line` with a peek, a catalogue under 1 000 tokens, shorter answers,
no dry runs. The server now offers nine tools (`hierarchy, find, outline,
read, check, rename, port, edit_item, format`); the model-visible
catalogue is 3 440 bytes (was 17 909), the instructions 398 bytes, and
every answer is one line per fact with a fixed cap. The mcp-arm prompt
mirrors the server's own instructions (`prompt_mcp_r4.txt`); the base
arms are the earlier rounds' (a 91 094, b 59 922, c 87 546 / 92 625 re-run,
d 102 579).
| task | arm | model | tokens | tool calls | wall | outcome |
|---|---|---|---|---|---|---|
| a | mcp | Sonnet 5 | 89 804 | 10 | 112 s | correct, 47/47, every Width/Depth value |
| b | mcp | Sonnet 5 | 66 055 | 21 | 104 s | correct, identical 3-line diff |
| c | mcp | Sonnet 5 | 101 137 | 45 | 403 s | correct, 8/8 sites in 4 files |
| d | mcp | Sonnet 5 | 104 897 | 22 | 278 s | correct, 71/20, all counts |
| d | mcp (re-run) | Sonnet 5 | 99 525 | 24 | 302 s | correct, 71/20, all counts |
| c | mcp | Opus 5.5 | 68 948 | 10 | 214 s | correct, 8/8 sites in 4 files |
### Observations
**Five correct answers out of five, and the whole-design tasks at parity
with plain file tools.** Task a is 1 % under the base arm (89.8 k vs
91.1 k); task d averages 102.2 k over two runs against the base arm's
102.6 k. The lean catalogue removed the fixed tax that round 1 identified
(the shim's `--list` is now 2.1 kB, ≈ 550 tokens, was 11.6 kB), which is
what closed the gap on a and d; their remaining cost is the answer itself
(a 47-row table, a 71-row list plus 20 port counts), which both arms pay.
- **a** used `find … refs: true` and then `read` on the instantiations
rather than `hierarchy up` with `peek`; either path answers in one call
plus reads. Against round 3b (111 k, where the agent never discovered
the `overrides` opt-in), the flag is gone and the cost fell 19 %.
- **b** (+10 % vs base, −6 % vs round 3): `port add dbg_i` did what it
promises — connected the port in every instantiation — which the task
forbade for two of them (a pre-DV testbench and `csrng_block_encrypt`);
the agent reverted those two files and edited `aes_core.sv` by hand. A
design-wide bulk edit is the wrong tool for an edit scoped to two files,
and the agent's calls went to undoing it. The answer diff is identical
to the base arm's.
- **c** (+9 % vs the base re-run, +16 % vs the round-1 base; −8 % vs
round 3): `rename` wrote the two RTL files and listed the three
unresolved mentions (the macro argument, the macro-rooted path in
`chip_if.sv`, the string-built force path in `entropy_src_path_if.sv`);
the agent fixed all three by hand, 8/8 again. Its 45 calls include a
detour where it backgrounded the rename and waited on it; the shim's
per-call re-index (~2 s) makes a 14 s rename look slow to an agent.
- **c with Opus 5.5** (68.9 k, 10 calls): 1 % under round 3's Opus mcp arm
(69.8 k) and 13 % over its base arm (61.1 k); same three hand fixes from
the `unresolved:` list, 8/8. A stronger agent needs the server less and
still pays the same relative overhead — unchanged from round 3.
- **d** (parity): two runs 5 k apart with identical content; the answer
text dominates both arms. The template-free `outline unit:` answers are
the difference from round 3's 107 k.
**What the round says about the ruling.** Accuracy held: no wrong row, no
wrong site, no stray edit survived. Tokens: the lean catalogue costs
nothing where the old one cost 15–25 %; the small edit tasks now sit at
+9…+10 %, which is the agent's own `check` calls and hand fixes, not the
server's answers. The remaining gap is bounded by how the agent works, not
by what the server sends.
## Round 5 — server at b757e82 (M8, read-only mode)
`lucisv-mcp --read-only`: five tools (`hierarchy, find, outline, read,
check`), a 1 797-byte catalogue, 297-byte instructions, and no way to
write. Only the two read tasks apply. Each arm ran twice; **the base arm
was re-run the same day as a control**, and that control is the finding.
| task | arm | model | tokens | tool calls | wall | outcome |
|---|---|---|---|---|---|---|
| a | read-only | Sonnet 5 | 67 230 | 7 | 41 s | correct, 47/47 |
| a | read-only (re-run) | Sonnet 5 | 72 361 | 7 | 56 s | correct, 47/47 |
| a | base (same day) | Sonnet 5 | 64 817 | 3 | 40 s | correct, 47/47 |
| a | read-only, cap fixed | Sonnet 5 | 72 247 | 8 | 50 s | correct, 47/47 |
| d | read-only | Sonnet 5 | 80 487 | 10 | 121 s | correct, 71/20, all counts |
| d | read-only (re-run) | Sonnet 5 | 67 104 | 8 | 151 s | correct, 71/20, all counts |
| d | base (same day) | Sonnet 5 | 80 194 | 10 | 78 s | correct, 71/20, all counts |
### Observations
**Against the old base figures the read-only mode looks 23–28 % cheaper;
against a same-day base it is at parity** (a: mean 69.8 k vs 64.8 k, +8 %;
d: mean 73.8 k vs 80.2 k, −8 %). The base arm itself fell from 91.1 k to
64.8 k on task a and from 102.6 k to 80.2 k on task d between 2026-09-23
and 2026-09-29 with no change to the task, the clone or the prompt: the
sub-agent environment changed under the census. Two consequences. Rounds
1–4 compared each mcp arm with a base arm measured the same day or within
a day, so their deltas stand; round 5 must not be compared with them, and
no figure in this file should be read as an absolute. And every future
round needs its base arm re-run alongside.
- **a: the server's own answer was cut short.** Both read-only runs asked
`hierarchy up` with `peek` (they needed the `#(…)` values), and the
300-line cap, which counted peek lines, showed 20 of 77 instantiations
and `… and 56 more`. Both agents then scanned the RTL sources themselves
— which is what the base arm does, in 3 calls. Without `peek` the same
call lists all 77 in 77 lines. Fixed after the round: the cap counts
instances (300, or 100 with `peek`, which bounds a peeked answer near
40 kB), peek lines do not count (0.59.0). Re-measured on the fixed
binary: the one call now returns all 77 with their source (31 kB), the
agent reported the server and its own search agreed — and still ran the
search, so the cost did not move (72.2 k). A complete answer removes the
need for the fallback; it does not remove the agent's habit of checking.
- **d: the server answered.** `hierarchy` at depth 1 gave the 71 instances
in one call and `outline unit:` the port counts; 8–10 calls, the same as
the base arm's 10, with a wider spread in wall time (the shim re-indexes
on every call).
- **Catalogue.** Through the shim the read-only `--list` is 1.1 kB
(≈ 300 tokens) against 2.1 kB for the nine tools; a native host sends
1.8 kB of schemas against 3.4 kB. The saving is real and small: a few
hundred tokens per session, below the run-to-run noise of any task here.
**What the round says.** Read-only mode does what it is for: a smaller
surface that cannot write, with the same answers. It does not change the
token picture, and nothing at the catalogue level will: on these tasks
the model's own reading and answer dominate, and a current Sonnet with
plain file tools is already efficient at both.
## 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.
**After round 4 (the lean catalogue, 0.58.0).** The owner's ruling
replaced the compound-tool plan: nine tools, a 3 440-byte catalogue, one
line per fact, no dry runs. Measured on the same four tasks: still no
wrong answer (six runs, one of them Opus), the whole-design tasks at parity with file tools
(a −1 %, d −0.4 % over two runs), the small edits at +9…+10 % where they
were +15…+25 % in round 1. The server's cost is no longer in what it
sends; it is in how much the agent verifies on its own. The next lever, if
one is wanted, is the agent's habits (the instructions already say "trust
them as file writes"), not the server. For scoped edits (b) a design-wide
`port add` is the wrong tool and the agent should edit the two files; for
renames (c) the `unresolved:` list is what makes 8/8 repeatable.
**After round 5 (read-only mode, 0.59.0).** Six more runs, all correct.
With a same-day base control the read-only server is at parity with file
tools on both read tasks (+8 %, −8 %), and the control showed the base arm
itself had become 22–29 % cheaper in six days — so no round here supports
an absolute claim, only same-day comparisons. The round also found a real
defect (the `peek` cap cutting `hierarchy up` to a quarter of its answer),
fixed in 0.59.0. The honest summary of five rounds: the server is correct
and safe, it matches file tools on cost, and it does not beat them on
these tasks with these models.
**Superseded by the ruling above — kept for the record.** (feedback-3 and
after, as planned before round 4): 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.