Repository navigation
Description
Summary
All 13 preview_* tools on BiBCode's MCP endpoint advertise the same open schema, {"type":"object","additionalProperties":true}, plus a one-line description. Agents can't see which arguments a tool takes, so they guess, and a failed call costs a retry. The typed inputs, with field descriptions, already exist in packages/contracts/src/previewAutomation.ts. Generate compact JSON Schemas from those contracts, so tools/list tells agents the real arguments without bloating their context.
Current behavior (verified at a0ea849ef92b)
Descriptors
apps/server/src/production/connect_mcp.rs:1650-1664:TOOL_OPERATIONSlists 13 operations (status,open,navigate,resize,snapshot,click,type,press,scroll,evaluate,wait_for,recording_start,recording_stop).operation_wire_nameis at:1666-1673, andtool_descriptorsat:1675-1681.preview_tool_descriptors(:1683-1704) gives every tool the description"Control the collaborative browser preview ({operation})."andinputSchema: {"type":"object","additionalProperties":true}(:1692). Only the annotations (readOnlyHintetc.) differ per operation.tools/listreturns these at:1023-1024.
Call path
:1098-1131stripstabIdand forwards the arguments as an untypedserde_json::Valueto the preview broker. Failures map toPreviewAutomationExecutionError.- The web host casts without decoding:
apps/web/src/components/preview/PreviewAutomationHosts.tsx:114,:521,:595,:624(request.input as PreviewAutomationOpenInput, …).workspace_preview.rs:324-388decodes the other preview RPC inputs but not automation input. I didn't trace the desktop host. - The Codex developer instructions already plan for guessing:
apps/server/src/provider/codex/model.rs:6-15says "A failed BiBCode preview tool call should be inspected and retried with corrected arguments".
The typed inputs already exist (packages/contracts/src/previewAutomation.ts, with field description annotations)
PREVIEW_AUTOMATION_V1_OPERATIONS(:29),PREVIEW_AUTOMATION_OPERATIONS(:45),PreviewAutomationTabTargetInput(:65).Open(:82, with a.checkfilter:tabIdvsreuseExistingTab: false),Navigate(:143),Resize(:182),Click(:267),Type(:306),Press(:336),Scroll(:357),Evaluate(:392),WaitFor(:421).
Other MCP tools already declare real schemas
device_*:apps/server/src/production/connect_mcp/device_tools.rs:374.- Profiler MCP:
apps/server/src/diagnostics/profiler/mcp.rs:207, tested at:663.
Proposed change
-
One source of truth. Export a JSON Schema for each
preview_*input from the Effect Schemas inpreviewAutomation.ts, using effect's JSON Schema export (toJsonSchemaDocument). Commit them as a fixture, e.g.packages/contracts/fixtures/mcp-tools/preview-tools.json. Rust embeds it withinclude_str!, andvp run check:contractsfails when the fixture drifts from the contracts. -
Compact for agents, strict for decoding. Apply T3's compaction rules (below) only to the advertised schema:
- no
additionalProperties: true; - no safe-integer bounds;
- no JSON-string fallbacks;
- no
nullbranch on optional fields; - one object for a tagged union.
Keep the
descriptionannotations; drop titles and identifiers. Decoding keeps the full schema. - no
-
Better descriptions. Replace the generic description with one sentence per operation that says what it returns, e.g. what
snapshotreturns and when to usewait_for. -
Decode at the boundary. The host decodes
request.inputwith the contract schema (PreviewAutomationHosts.tsx), instead of casting, and returns a typed argument error the agent can act on. Check the desktop host too. -
Apply this to MCP server so AI agents can operate BiBCode without the UI #139. When MCP server so AI agents can operate BiBCode without the UI #139 exposes
preview_*/device_*on/mcpfor remote clients, it should use these generated schemas. Its design doc should require the compaction rules for any new tool.
T3 Code reference (their claims, not measured by us)
- pingdotgg/t3code#25423, merged 2026-10-26 22:49 ART. It states the schema rules quoted above: "no
additionalProperties: true, no safe-integer bounds, no JSON-string fallbacks, nonullbranch on optional fields, and one object for a tagged union. Decoding still uses the full schema." - They also merged related tools into action tools (e.g.
preview_act), going from 84 to 66 tools. - They report the tool list shrinking from 65,789 to 43,175 characters (−34%), plus an eval table. These are T3's numbers; we haven't measured BiBCode's
tools/listsize.
Acceptance criteria
- Baseline first: record the current
tools/listbyte size and thepreview_*share of it in the PR description. - Contracts:
packages/contracts/src/previewAutomation.test.tscovers the schema export:- every operation in
PREVIEW_AUTOMATION_OPERATIONSgets a schema; - no generated schema contains
additionalProperties: true, safe-integer bounds ornullbranches on optional fields; Open'stabId/reuseExistingTabrule is kept in its description.
- every operation in
-
vp run check:contractsregenerates and checks the new fixture underpackages/contracts/fixtures/. - Rust tests in
apps/server/src/production/connect_mcp/tests.rs:origin_snapshot_and_tool_metadata_cover_wire_variants(:396, asserts at:467-479) asserts eachpreview_*descriptor uses the fixture schema, with noadditionalProperties: true;mcp_json_rpc_and_preview_tools_preserve_wire_results(:1189, thetools/listcall at:1283) still passes;- a new test bounds the serialized
tools/listsize so it can't silently regress.
- Web:
apps/web/src/components/preview/PreviewAutomationHosts.test.tsxcovers an invalid input (e.g.clickwithout a target), which returns a typed argument error instead of a runtime failure. - Desktop e2e:
vp run test:ui:desktop, includingapps/desktop/e2e/specs/platform-capabilities.e2e.tsandmain-window.e2e.ts. - Manual: a Codex or Claude thread drives
preview_open→preview_click→preview_snapshoton a local page with no argument-retry errors. - Gates:
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test -p bibcode-server connect_mcp,vp check(zero warnings),vp run typecheck,vp run check:contracts, Release Smoke. - UI.md and
vercel-react-best-practicesreviews are recorded if any UI changes (none expected).docs/testing/runbooks are reviewed and updated or stated "remain accurate". - Profiler coverage line in the delivery report. Tool arguments (URLs, typed text, evaluated scripts) never reach profiler records or logs.
Living docs to update
docs/architecture/overview.md(the MCP /preview_*section near:2553): the schema source and the compaction rules.docs/superpowers/specs/2026-10-09-desktop-preview-automation-design.md: a note that MCP schemas are generated from the contracts.docs/plans/2026-10-24-mcp-operate-server-design.md(MCP server so AI agents can operate BiBCode without the UI #139): reference these schemas.
Not in scope
- Merging tools into action tools the way T3 did (84 → 66). That's a separate decision once we have our own size numbers.
- Exposing
preview_*/device_*on/mcpto remote clients, and per-call scope checks (MCP server so AI agents can operate BiBCode without the UI #139). - Changing
device_*or profiler MCP schemas, which are already explicit.
Related
- MCP server so AI agents can operate BiBCode without the UI #139: MCP operate-server design; it lists
preview_*/device_*on/mcpand should adopt these schemas.
Open questions
- Should the advertised schema live in a committed fixture (reviewable diffs) or be generated at build time? This issue assumes a fixture checked by
check:contracts. - Does the desktop preview host validate automation input today? I only traced the web host's casts.
- Should status, snapshot and recording ops advertise the tab-target input (
:65) or an empty object?
Activity
mubeda commentedon Oct 31, 2026
Triage, 2026-10-31. Not going into PR #213 (#139 MCP batch). It goes in a follow-up PR after that release. Batch 3 (MCP), the first MCP follow-up.
connect_mcp.rs. They now live inapps/server/src/mcp/tools/previews.rs(preview_tool_descriptors, open schema at about:483). That function serves both the provider endpoint and the new remote/mcpendpoint, so one change fixes both. Theconnect_mcp.rsline references above are stale against BiBCode v0.14.0: MCP server for outside agents, turn checkpoints, timeline and AppImage fixes #213.docs/reference/mcp.md(the Previews and devices section, "Unknown arguments") says the twins accept any arguments. Update it when the schemas land, and extend themcp::reference_docsdrift test if it checks argument tables.Planned order after the release: (1) #222 copy lint; (2) quick fixes #228, #221, #229, #231, #232; (3) MCP #220; (4) performance #225, then #223, #226, #227; (5) features #230, #224, #211, #212; (6) #210 after a Windows repro.