Repository navigation
fix(cli): bill a signed-in local MCP audit_website like squirrel audit (#628) - #631
Conversation
…#628 No signed-in audit is free in credits. Signed in, audit_website now runs as a billed cloud audit at every level, through the same register decision, affordability preflight and cloud rendering as squirrel audit: the run is registered (50-credit base), renders are tagged with it, and it is closed out with its audited pages (2 each). Before, it ran the cloud checks at surface and full without registering anything. A tool call cannot prompt, so an estimate over [cloud] confirm_threshold comes back as confirmation_required and the agent calls again with confirm: true, as with the hosted run_audit. A balance or per-audit cap that cannot cover one page, or a register the server refuses, is refused with the cost and the balance. Each billed run is closed exactly once, including on a shutdown signal mid-audit or mid-register. Signed out, offline, against a non-public host, and in quick_check the tools still run locally with no cloud call. Closes #628 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the diff (billed-audit.ts, audit-tools.ts, server.ts, cloud.ts, changelog). I read the source only and did not run the tests. The design reuses the CLI's billing pieces, closes each run once, and handles shutdown while a register is in flight. I found no blocking problems.
Test coverage looks good: it uses a real MCP client against a stubbed API, and covers refusal, confirmation, shutdown and local paths. One gap: I did not see a test for the signal handler in |
|
Review of #631 (bill signed-in local MCP
Test coverage looks strong: 16 tests with a real MCP client, covering the race and shutdown paths. A test for the "audit throws" path ( |
Closes #628. Follow-up to #598, which documented this as a known gap.
No signed-in audit is free in credits. Signed in, the local MCP
audit_websitetool now runs a billed cloud audit at every level, exactly likesquirrel audit. Signed out, offline, against a local or private host, and inquick_check, it still runs on your machine with no cloud call.What changes
Billed like the CLI. A new module,
apps/cli/src/mcp/billed-audit.ts, reuses the CLI's own pieces:resolveRegisterDecision,canStartCloudAudit,computePreflightAffordability,resolveCloudRendering, andregisterRun/markRunning/finalizeRun.runId, so each page is billed once as part of the audit.pagesAudited, which the server settles at 2 per page.Confirmation, as in the hosted
run_audit. A tool call cannot prompt. An estimate over[cloud] confirm_threshold(default 50, so every audit) comes back as a normal result withstatus: "confirmation_required", the estimate (credits,pages,baseCredits,creditsPerPage), the balance andsufficient: true. The agent then calls again withconfirm: true. The newconfirminput is optional.Refused clearly, never silently. Each of these returns an error naming the cost and the balance, and nothing is registered or rendered:
[cloud] max_credits_per_auditis below one page;If the register request gets no answer, the error says the outcome is unknown and that a run which never starts is refunded when it is cleaned up. It does not promise that nothing was charged.
The page cap fits the credits. When the balance or the cap covers fewer pages than the level asks for, the audit runs on what it can pay for. The confirmation and the result both say so.
Each run is closed exactly once.
failed: no page charge, and the base is refunded. Its result says so.SIGINT/SIGTERM/SIGHUPto the MCP server closes every in-flight run ascancelled, including a run whose register is still in flight. After that no new register starts. Then the signal is re-raised.The report reads as signed in. Billed results start with
Billed cloud audit, run <id>: N audited pages, about X credits (50 base + 2 per audited page). The report carries the samecloudPlan/cloudMode/coverageModestamps the CLI adds.Still local, with no cloud call:
offline: truequick_checkAn env token the server rejects is a hard error, as in the CLI.
Cleanup.
resolveCloudAvailabilityinmcp/cloud.tsis removed (unused now).upgradeUrlgains themcp-auditattribution source.Docs.
docs/cli/mcp.mdx: new "Billing a signed-in audit" section; theaudit_websiterow and the intro no longer say the local server is unmetered.docs/developers/mcp.mdx: updated to match.[Unreleased], and the feat(cli): audit levels (--level quick|surface|full) and the audit levels docs page #598 known-gap sentence is removed.Behaviour changes to review
audit_websitecosts credits at every level: 50 + 2 per audited page, up to 100 at quick (25 pages). It used to be unbilled.confirmation_requiredunlessconfirm: trueis passed, or[cloud] confirm_thresholdis at or above the estimate. Agents that callaudit_websiteonce will now get an estimate back instead of a report.[cloud] renderwas set.Evidence
tsgo(apps/cli): clean. Rootformat:checkandlint,test-suites --check, detect-secrets andmake validatein docs all pass.apps/cli/tests/mcp/audit-website-billing.test.ts(16 tests): a real MCP client over an in-memory transport, a stubbed API, scratch paths.confirm: an estimate of 52 for 1 page and nothing registered;confirm: registers, renders the client-rendered page withrunId, and closescompletedwithpagesAudited: 1;confirm_thresholdabove the estimate starts withoutconfirm;failed;cancelActiveMcpRunscloses in-flight runs ascancelled, once.offline: true,quick_checkand a localhost URL make no cloud call.audit-tools.ts, the file fails 8 of its 11 original tests (all the signed-in ones; the local ones pass on main too). These mutations each make a test fail: droppinggetRunId, dropping the once-only close, dropping register tracking, and dropping the shutdown flag.audit-level-options,docs-sync(tool descriptions carry no pitch words),server,protocol,cloud,scopes,report-tools,entity-tools,feedback-tools.Agent skill
Yes. The squirrelscan agent skill should say that local MCP
audit_websiteis billed when signed in, and that the agent must show theconfirmation_requiredestimate to the user before calling again withconfirm: true.