Files
lucisv/docs/features/mcp-packaging/README.md
T
lucioandClaude Fable 5.1 d4ec571958 MCP M5: lucisv-mcp ships in every platform vsix; the extension registers it with VS Code's agent mode; Agents guide
tools/release.sh builds -p lucisv_mcp for the host and every cross triple, stages lucisv-mcp[.exe] beside the two binaries (three per platform package, fifteen in the all-platforms one; the universal package still carries none), smoke-tests it (editors/vscode/mcp_smoke.js: initialize, tools/list ≥ 26, project_overview) loose and unzipped from the host and all-platforms packages; tools/audit_artifacts.sh audits the third name and rejects any other; prune_release_assets.sh unchanged (seven vsix names). editors/vscode/mcp.js: the three-rung binary ladder (lucisv.mcp.path → bundled → PATH), one McpStdioServerDefinition per workspace folder — the constructor is POSITIONAL (label, command, args, env, version) with cwd set afterwards; the plan's object form was wrong and is corrected — with `--root <folder> --index-cache <storage>`, refreshed on folder and setting changes, guarded so VS Code < 1.101 registers nothing but the command; a missing binary refused at resolve time with one output-channel line; the `lucisv.mcp.copyConfig` command puts the Claude Code / Cursor / VS Code snippet on the clipboard. package.json: contributes.mcpServerDefinitionProviders, lucisv.mcp.enabled/path, the command; engine stays ^1.82.0 (vsce 4 accepts). ci.yml runs node --test over the extension's unit tests. Docs: docs/site guides/agents.md with the tool table generated from the binary (site rebuilt), README paragraph, RELEASING.md, extension README/CHANGELOG (Unreleased), manual-acceptance rows 18–25 for the live-VS Code checks.

QA (Opus): API signature confirmed against VS Code 1.138's vscode.d.ts; 8 mutation checks caught by mcp_test.js; release.sh run end to end, vsix contents listed (three binaries, mcp.js, no test files), SHA256SUMS verified, the embedded binary smoke-tested, the vsix installed into an isolated profile. Gates: node --test 6/6, fmt clean.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-23 15:59:07 -07:00

340 lines
21 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-packaging
## Goal
Ship `lucisv-mcp` (the Model Context Protocol server of `docs/mcp/PLAN.md`)
the way `lucisv-server` ships: as a third binary in every platform `.vsix` and
in the all-platforms one, smoke-tested out of the package by
`tools/release.sh`; registered by the VS Code extension with agent mode (one
stdio server per workspace folder) on a VS Code that has the MCP API; and
reachable from hosts that do not read VS Code's registry (Claude Code, Cursor)
through a copy-config command and a docs page. TODO-MCP **M5**, PLAN §5.
## Assumptions
- **Engine stays `^1.82.0`.** `npx @vscode/vsce package` (vsce 4.0.0,
2026-09-23) packages `contributes.mcpServerDefinitionProviders` under
`^1.82.0` with no warning beyond the pre-existing "bundle your extension"
one, so no bump. The registration is guarded at runtime: `vscode.lm`,
`vscode.lm.registerMcpServerDefinitionProvider` and
`vscode.McpStdioServerDefinition` must all exist (VS Code 1.101+); on an
older VS Code nothing is registered, one line goes to the lucisv output
channel, and the rest of the extension is unaffected.
- **`McpStdioServerDefinition`'s constructor is positional**, not an object:
`(label, command, args?, env?, version?)`, with `cwd` a plain property.
Verified against the installed VS Code 1.138's `vscode.d.ts` and its
extension-host implementation (`constructor(t,e,n,o={},i,s){this.label=t;
this.command=e;this.args=n;this.env=o;this.version=i;…}`). PLAN §2.3 and the
VS Code extension guide's sample show an object argument — that would make
the object the label and leave `command` undefined. `mcp.js` uses the
positional form and assigns `cwd` afterwards.
- **Activation.** `activationEvents` is unchanged: VS Code derives
`onMcpCollection:lucisv.mcp` from the contribution point itself (seen in the
1.138 workbench: `activationEventsGenerator` yields it for every provider
id), so agent mode can activate the extension without a Verilog file open.
Activation starts the language server too — `mcp.activate` is called at the
end of `extension.js`'s `activate`, after the server start.
- **Where the binary is found** — the server's three-rung ladder: an explicit
`lucisv.mcp.path` (read with `inspect()`; blank and the manifest default
count as unset — the `userServerPath` rule), else `bin/lucisv-mcp` or
`bin/<platform>-<arch>/lucisv-mcp` in the package (`extension.js`'s own
`bundledBinary`, handed to `mcp.activate` — so there is one implementation
of the two layouts and the chmod), else `lucisv-mcp` on `PATH`.
- **What the extension passes**: `--root <folder fsPath>` and, when VS Code
gives one, `--index-cache <storageUri, else globalStorageUri, fsPath>` — the
same directory the language server receives as `storagePath`. `cwd` is the
folder's URI, `env` is `{}`, `version` is `package.json`'s. Not passed:
`lucisv.index.cachePath` (the LSP's override of that directory) and
`lucisv.filelist` (MCP reads the project's `lucisv.toml` `filelist` itself).
M6, which reads the store, may want the former.
- **What VS Code shows**: one `lucisv (<folder name>)` server per workspace
folder under **MCP: List Servers**; trust is VS Code's own per-server
prompt. A folder added/removed or any `lucisv.mcp.*` change fires
`onDidChangeMcpServerDefinitions`, so the list follows without a reload.
- **`lucisv.mcp.enabled: false` is live.** The provider stays registered and
returns no definitions while the setting is off (one output-channel line at
activation says so); turning it back on needs no reload. The brief said
"register nothing" — returning nothing has the same visible effect and
avoids the reload.
- **A missing binary is not started.** `resolveMcpServerDefinition` checks the
command exists (as given when it has a directory part, else on `PATH`);
when not, it logs one line to the lucisv output channel and returns
`undefined`, which the API defines as "do not start". This is the universal
package on a machine without `lucisv-mcp`.
- **Hosts that need the copied config**: Claude Code (`.mcp.json`,
`mcpServers`), Cursor (`.cursor/mcp.json`, `mcpServers`) — neither reads VS
Code's provider registry — and VS Code itself when configured by hand
(`.vscode/mcp.json`, `servers` with `type: "stdio"`). The snippet names the
resolved binary and one `--root` per workspace folder; when that binary is
the bundled one, the message warns that its path changes on update.
- **The loose binaries stay unpublished**, as for the other two
(`tools/prune_release_assets.sh`, unchanged: it keys on the seven `.vsix`
names).
- **CI runs the extension's JavaScript tests** with `node --test
editors/vscode/*_test.js`. The runner is this Mac in host mode, node 22
(`--test` needs ≥ 18). The tests stub `vscode` and need no `npm ci`.
## Handshakes
- **`editors/vscode ─▶ lucisv_mcp` (spawn contract).** Binary name
`lucisv-mcp` (`lucisv-mcp.exe` on Windows); arguments `--root DIR` and
optionally `--index-cache DIR`, nothing else; stdio newline-delimited
JSON-RPC; cwd the folder. Pinned by `mcp_test.js` (exact args) and
`mcp_smoke.js` (spawns the real binary with the same shape). A rename of
either flag in `crates/lucisv_mcp/src/main.rs` breaks both.
- **`tools/ ─▶ lucisv_mcp` (packaging).** `release.sh` builds `-p
lucisv_mcp` for the host and every cross triple and expects
`target/[<triple>/]release/lucisv-mcp[.exe]`; `mcp_smoke.js` expects
`serverInfo.name == "lucisv-mcp"`, ≥ 26 tools and a non-error
`project_overview` whose text names the top module. Lowering the tool count
means lowering `MIN_TOOLS` in `mcp_smoke.js`.
- **Promised to users**: the settings `lucisv.mcp.enabled` / `lucisv.mcp.path`,
the command `lucisv.mcp.copyConfig`, the provider id `lucisv.mcp`.
- **Request to the lead (outside this lane's files)**:
`.gitea/workflows/release.yml`'s header comment still says the platform
packages embed "the lucisv + lucisv-server binaries"; it wants "lucisv,
lucisv-server and lucisv-mcp". `docs/mcp/PLAN.md` §2.3/§5.2 show the object
form of the `McpStdioServerDefinition` constructor, which is wrong (see
Assumptions). `docs/topo.md` edges are M6's.
## Status / TODO
- [x] `release.sh`: `-p lucisv_mcp` in the host and cross builds; loose
`dist/lucisv-mcp-<version>-<triple>[.exe]`; staged as `bin/lucisv-mcp`
and `bin/<target>/lucisv-mcp`; `expect_vsix_bins` three per platform,
fifteen for `all`; universal still asserts no `bin/`;
`smoke_embedded_mcp` for the host platform package and (with `--cross`)
the `all` package; host `mcp_smoke.js` run; checksummed
- [x] `audit_artifacts.sh`: every binary must be one of the three names; the
same per-triple audits apply to `lucisv-mcp`
- [x] `prune_release_assets.sh`: read, unchanged
- [x] `mcp.js`, `mcp_test.js`, `mcp_smoke.js`; `extension.js` +2 lines
- [x] `package.json`: provider, two settings, command + palette; engine kept
- [x] `.vscodeignore`: `mcp_test.js`, `mcp_smoke.js` excluded
- [x] CI step `node --test editors/vscode/*_test.js`
- [x] docs: site guide `guides/agents.md` + sidebar, `README.md` paragraph,
`tools/RELEASING.md`, extension README + CHANGELOG (Unreleased)
- [x] local `tools/release.sh` (host) green; darwin-arm64 vsix unzipped
- [ ] QA (TODO-MCP M5 last box)
## Work log
### 2026-09-23 (dev)
- **VS Code API check.** Read the installed VS Code 1.138's `vscode.d.ts` and
minified extension host: the stdio definition's constructor is positional;
the plan's object form would have produced a server with an object label
and no command. The contribution point generates `onMcpCollection:<id>`
activation implicitly.
- **`mcp.js`** (≈ 180 lines with comments): ladder, provider with
`provideMcpServerDefinitions` / `resolveMcpServerDefinition` /
`onDidChangeMcpServerDefinitions`, copy-config command (registered on every
VS Code, including those without the MCP API). `bundledBinary` and the
output channel are passed in from `extension.js`, whose change is two lines
(the `require`, and the call after `restarter.start()`).
- **`mcp_test.js`**: 7 groups — the ladder (explicit / blank / bundled /
PATH), one definition per folder with exact args/cwd/version and both
storage fallbacks, change events (folders, `lucisv.mcp`, not others),
`enabled: false` (no definitions, one log line, re-enabled live), the old
VS Code guard in three forms (no `lm`, `lm` without the function, no
definition class; no throw with no channel), missing-binary refusal, and
the three snippets' exact JSON plus the dismissed pick.
- **`mcp_smoke.js`**: temp project of two files, the extension's spawn shape,
all four messages written then stdin closed; checks serverInfo, tool count,
overview text, stdout purity and exit status 0. Fails cleanly (exit 1) on
a missing binary and on the wrong binary (`lucisv-server` refuses
`--root`). `--tool-table` prints the Markdown table checked into the guide.
- **`release.sh`** host run under `tools/guard.sh -t 1800`: exit 0; both
smokes passed on the loose binaries and on the ones unzipped from
`lucisv-0.56.0-darwin-arm64.vsix`; `shasum -c` OK for all five artifacts.
`unzip -Z1 … 'extension/bin/*'` → `lucisv`, `lucisv-mcp`, `lucisv-server`;
`extension/mcp.js` present; no `mcp_test.js` / `mcp_smoke.js`. The universal
vsix has `extension/mcp.js` and no `bin/`.
- **Size**: `lucisv-0.56.0-darwin-arm64.vsix` = 6 784 784 bytes; the
`lucisv-mcp` entry is 4 532 816 bytes, 1 922 890 deflated, `mcp.js` 2 686
deflated — **+1.93 MB** per platform package (≈ +9.6 MB for `all`, by the
same ratio across five targets; not measured, needs `--cross`).
- **Cross check** (not in the brief, cheap insurance): built `-p lucisv_mcp`
for `x86_64-unknown-linux-gnu`, `x86_64-pc-windows-gnu` and
`x86_64-unknown-linux-musl` with the script's recipes; `audit_artifacts.sh`
passed all three (glibc ceiling `GLIBC_2.28`); a stray name
(`lucisv-lsp-…`) is rejected.
- **vsce**: engine `^1.82.0` accepted (see Assumptions); no bump.
- `node --test editors/vscode/*_test.js`: 6 files, all pass. The docs site
builds (`astro build` to a scratch dir) with the new page.
- No Rust touched.
## QA log
### 2026-09-23 (QA) — verdict: **pass** (headless); live-VS Code steps filed as manual-acceptance rows 18–25
Everything below ran on master 23ec444 + the lane's uncommitted tree; scratch
work under the session scratchpad, nothing committed, no Rust touched.
1. **API claim — confirmed.** VS Code **1.138.0** (`code --version`;
`/Applications/Visual Studio Code.app/Contents/Resources/app/out/vscode-dts/vscode.d.ts`):
`vscode.d.ts:20467` `constructor(label: string, command: string, args?: string[], env?: Record<string, string | number | null>, version?: string);`
and `vscode.d.ts:20434` `cwd?: Uri;` (a plain, non-readonly property;
`label` is the only readonly one). The extension host
(`out/vs/workbench/api/node/extensionHostProcess.js`) implements it as
`constructor(t,e,n,o={},i,s){this.label=t;this.command=e;this.args=n;this.env=o;this.version=i;this.metadata=s}`.
`resolveMcpServerDefinition` may return `undefined` = "do not start"
(`vscode.d.ts:20538`). Contribution point schema in
`workbench.desktop.main.js`: `extensionPoint:"mcpServerDefinitionProviders"`,
items `{id, label, when}` (`additionalProperties:false`), and
`activationEventsGenerator` yields `onMcpCollection:<id>` — the
Assumptions' implicit-activation claim holds. `package.json` uses exactly
`id`/`label`; `PROVIDER_ID` in `mcp.js` equals it.
2. **`mcp.js`** — read line by line; `node --test editors/vscode/*_test.js`:
6 files, 6 pass, 0 fail (node v22.13.1). Ladder order, blank = unset,
one definition per folder with args exactly `--root <fsPath>
--index-cache <storage>`, change events, `enabled:false`, the three
old-VS Code shapes, the snippets — all asserted. **Mutation check** (8
mutants of a scratch `mcp.js`: bundled-before-explicit, untrimmed blank,
`--index-cache` renamed, `cwd` dropped, fire on every config change,
`type:"stdio"` dropped, `enabled` ignored, `lm` guard dropped): all 8
killed by `mcp_test.js` under `node --test`. **Own scratch checks**
(`qa_mcp_test.js`, not checked in), all pass, with
`unhandledRejection`/`uncaughtException` hooks asserting nothing escaped:
zero folders (`workspaceFolders` both `undefined` and `[]`): no
definitions, no log line, each snippet `JSON.parse`s with `args: []`;
folder `/work/my proj` and bundled path `/ext dir/bin/lucisv-mcp`: label
`lucisv (my proj)`, args keep the space inside one element, `cwd.fsPath`
right, all three snippets `JSON.parse` and round-trip the path, only the
VS Code one has `"type":"stdio"`, and a real existing binary under a
directory with a space resolves; `lucisv.mcp.path` →
`/definitely/not/here/lucisv-mcp`: the setting wins over bundled, resolve
returns `undefined` without throwing, one output-channel line (and no
throw with no channel at all); no `vscode.lm`: copy-config still yields
valid VS Code JSON naming bare `lucisv-mcp`.
3. **`extension.js`**: `git diff` is exactly +2 lines (the `require` and
`mcp.activate(context, { bundledBinary, outputChannel: client.outputChannel })`
after `restarter.start()`; no early return in `activate` before it).
`restart_test.js` passes (44 checks); `tools/guard.sh -- cargo build
--release -p lucisv_server -p lucisv_mcp` then `node
editors/vscode/smoke.js target/release/lucisv-server`: OK (55 messages).
4. **Packaging**: `tools/guard.sh -t 1800 -- tools/release.sh` → exit 0
(both smokes on the loose binaries and on the ones unzipped from the
darwin-arm64 vsix; `bin/ contents ok` for both packages; vsce 4.0.0
printed only the pre-existing "bundle your extension" warning — engine
`^1.82.0` accepted). `shasum -a 256 -c SHA256SUMS`: 5 × OK.
`unzip -Z1 dist/lucisv-0.56.0-darwin-arm64.vsix | sort` minus 315
`extension/node_modules/` entries: `[Content_Types].xml`,
`extension.vsixmanifest`, `extension/LICENSE.txt`,
`extension/bin/lucisv`, `extension/bin/lucisv-mcp`,
`extension/bin/lucisv-server`, `extension/changelog.md`,
`extension/extension.js`, `extension/extract.js`,
`extension/hierarchyModel.js`, `extension/hierarchySections.js`,
`extension/hierarchyView.js`, `extension/images/{architecture.png,feature-map.png,hierarchy.svg,icon.png}`,
`extension/mcp.js`, `extension/media/{hierarchy.css,hierarchy.js}`,
`extension/package.json`, `extension/readme.md`, `extension/restart.js`,
`extension/snippets/{systemverilog,verilog}.json`,
`extension/syntaxes/systemverilog.tmLanguage.json` — no `*_test.js`, no
`smoke.js`/`mcp_smoke.js`. Universal `lucisv-0.56.0.vsix`: 0
`extension/bin/` entries, `extension/mcp.js` present. Unzipped by hand
to scratch: `mcp_smoke.js` against the embedded `lucisv-mcp` → OK
(0.56.0, 26 tools); it is byte-identical (`cmp`) to the loose binary.
Negative smokes exit 1: missing path (ENOENT), `lucisv-server` and
`lucisv` (both refuse `--root`). **Clean-profile install**: `code
--user-data-dir <scratch> --extensions-dir <scratch> --install-extension
dist/lucisv-0.56.0-darwin-arm64.vsix` → installed,
`guoliangchen.lucisv@0.56.0`, `bin/` holds the three executables (755).
`tools/prune_release_assets.sh`: not in `git diff`/`git status`; its
seven suffixes (`""`, darwin-arm64, darwin-x64, linux-x64, linux-arm64,
win32-x64, all) match `vsce_target_for` + the universal + `-all` in
`release.sh` (read, cross not run). `--cross` artifact arithmetic in
`RELEASING.md` (6 triples × 3 = eighteen loose binaries, fifteen `bin/`
entries in `all`) matches the script. `audit_artifacts.sh` on a scratch
copy of dist: clean → exit 0 (3 audited, incl. `lucisv-mcp-…`); a stray
`lucisv-foo-0.56.0-aarch64-apple-darwin` → `FAIL: … not lucisv,
lucisv-server or lucisv-mcp`, exit 1; a Mach-O renamed
`lucisv-mcp-0.56.0-x86_64-unknown-linux-musl` → `not an x86-64 ELF`,
exit 1 (the per-triple audit really applies to the third name).
5. **CI**: `yaml.safe_load` parses `ci.yml`; job `checks` steps in order
`cargo fmt`, `cargo clippy`, `cargo test`, `extension tests` (after the
cargo steps). Local node v22.13.1 (≥ 18); the runner's node version is
the dev's statement, not checked from here.
6. **Docs**: `node editors/vscode/mcp_smoke.js --tool-table
target/release/lucisv-mcp` regenerated; `diff` against the guide's table
→ identical (26 rows). Every one of the 14 write tools has `dry_run` in
its input schema (the guide's "on any edit tool" holds); `lucisv-mcp
--bogus` → usage line, exit 2; default root `.` (`canonical_roots`) — the
Standalone paragraph is accurate. Links: the guide has one, absolute; the
extension README's only non-`https://` links are in-page anchors
(`#agents-mcp`, new; `#large-workspaces`, pre-existing), which vsce
accepts (it packaged). Site: `tools/guard.sh -t 600 -- npx astro build
--outDir <scratch>` → 14 pages, `guides/agents/` built, sidebar entry on
every page, the `` `define `` row renders as text, `\a@b@1` intact. (Built
to scratch because `docs/site/dist/` is **tracked** — see lead items.)
`README.md` paragraph and `RELEASING.md` agree with `release.sh`
(three binaries, both smokes, host + `all` re-smoke, the artifact
table, "nine crates" = 9 `version.workspace` crates).
7. **PLAN §2.3/§5.2**: found already corrected in the working tree (not
this lane's edit) to the positional form with `cwd` set afterwards;
`release.yml`'s header now names `lucisv-mcp`.
Extra, headless proxies for the QA checklist's live-VS Code clauses: the
Claude Code snippet built by `configSnippet` with the *installed* extension's
`bin/lucisv-mcp` and a root containing a space, spawned exactly as
`command`/`args` from an unrelated cwd (`os.tmpdir()`): status 0,
`serverInfo.name` `lucisv-mcp`, `project_overview` non-error with the right
root. `lucisv-mcp --index-cache /nonexistent/dir/x` starts and answers
(exit 0) — VS Code creates `storageUri` lazily, so the directory the
extension passes may not exist yet.
**Findings** (none blocking; no fix made):
- F1 (docs, minor) `tools/RELEASING.md:240` — "~13 MB rather than ~3 MB (both
before `lucisv-mcp` joined them; the darwin-arm64 package measured 6.8 MB
with it, +1.9 MB)": 3 + 1.9 ≠ 6.8. The pre-MCP darwin-arm64 package was
already ≈ 4.9 MB (6 785 772 − 1 922 890 deflated), so "~3 MB" was stale
before this lane; the new parenthesis makes the inconsistency visible.
Same stale "about 13 MB against 3 MB" at `editors/vscode/README.md:55`
(pre-existing, untouched by the lane).
- F2 (docs, drift risk) `editors/vscode/README.md:196` hard-codes "its 26
tools"; `MIN_TOOLS` in `mcp_smoke.js` only guards the floor, so a 27th
tool leaves this stale silently. Suggest "its tools" or regenerate with the
guide's table.
- F3 (hardening, optional) `mcp.js:157` — `registerMcpServerDefinitionProvider`
is not wrapped: if it ever throws (e.g. a future VS Code rejecting the
provider), `activate` in `extension.js:293` throws *after* the language
server has started, and VS Code reports the whole extension's activation
as failed. A try/catch logging one line would keep the MCP part
strictly additive. Not reproducible today (the id is declared).
- F4 (for M6) the `--index-cache` directory may not exist when VS Code spawns
the server (see above); the M6 reader must treat a missing directory as
"cold start", not an error.
**Lead items (outside this lane's files):** `docs/site/dist/` is tracked
and was not rebuilt, so the committed site build lacks `guides/agents/` until
someone regenerates it; `.gitea/workflows/release.yml:6` still says "every
pair at once" one line below the corrected binary list; PLAN §5.2 now shows
`undefined` for `env` where `mcp.js` passes `{}` (equivalent — the host
defaults `env` to `{}` — noted only so the two read alike).
**Not done here (owner, live VS Code):** MCP: List Servers, trust, an agent-mode
`project_overview`, `enabled:false` live, multi-root, universal-without-PATH
degradation as VS Code shows it, the copied snippet in a real Claude Code
session — `docs/manual-acceptance.md` rows 18–25. The stubbed unit tests and
the headless proxies above cover the logic behind each; only VS Code's own UI
reaction (e.g. whether it adds a toast when `resolve` returns `undefined`) is
unverified.
## Review
**Lead, 2026-09-23 (M5).** The lane is scripts, JavaScript and docs, and it
did the one thing the plan got wrong right: VS Code's
`McpStdioServerDefinition` is a positional constructor (confirmed by the dev
and by QA against 1.138's `vscode.d.ts`), so the plan's object form is
corrected in `docs/mcp/PLAN.md` §2.3/§5.2. Rulings kept from the dev's
deviations: `lucisv.mcp.enabled: false` leaves the provider registered and
returning no servers (no reload to turn it back on); a missing binary is
refused at `resolveMcpServerDefinition` with one output-channel line, which
is what the universal package needs. Engine stays `^1.82.0` — vsce 4 accepts
the contribution point and the registration is guarded at runtime. QA's F1/F2
(stale size and tool-count prose) fixed by the lead; F3 (a try/catch around
the registration) and F4 (`--index-cache` may not exist yet — M6's reader
must tolerate it) noted for M6. The tracked docs site rebuilt so the Agents
page ships. Rows 18–25 of `docs/manual-acceptance.md` are the owner's in a
live VS Code. Committed as M5.