Public: anyone can read this; the crew can change it.

The MCP token-free tool shortcut passes the same fence and scope floor as a token call #14974

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A signed-in call of report, start or offer through the token-free shortcut now gets the same checks as any other tool call. Before this, the forge's own agent, after reading untrusted text, could file a report under the person's name with no confirm, and an ro token could make that write (finding from #14765).

Notes

shipped production is serving it deploy 5b5da4d

opened this

A signed-in call of report, start or offer through the token-free shortcut now gets the same checks as any other tool call. Before this, the forge's own agent, after reading untrusted text, could file a report under the person's name with no confirm, and an ro token could make that write (finding from #14765).

What changed: in src/http/mcp.ts, openToolCall sends signed-in calls of these three tools through a new gatedShortcut. It runs the same steps in the same order as the ordinary tool-call path in rpcOne:

  • askedFirst and heldWrite, so a steered write is held as a confirm;
  • the rw scope floor, so an ro token gets READ_ONLY_REFUSAL;
  • readThrough;
  • the handler, then fenceAnswer on each text block of its answer.

Callers who are not signed in go straight to the handler as before. No tool was added and the ceilings are unchanged.

Look at: gatedShortcut treats all three tools as writes, since each one creates something (a report, an account, a patch offer). That means a signed-in ro token calling start or offer is now refused as read-only. I chose not to skip the duplicate-write record (claimDone/recordWrite) on purpose: these handlers return JSON-RPC answers rather than results that record expects.

Tests: the new test/mcp-shortcut-fence.test.ts checks two things: the forge's agent reads an issue Mallory wrote and then calls report, and gets needs_confirm with nothing filed; an ro token is refused the report while an rw token files it. Both tests fail without the change to mcp.ts and pass with it. bun test test/mcp-size.test.ts passes, along with the report, start, offer, contribute-token, refusal-hint, agent-card, conversation-fence and muse-journey suites (154 pass, 0 fail). bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean. scripts/fast.ts called the diff too broad to run in full here (2123 test files), so the full bun test is left to the forge's check on this push.

Try it: with an ro token, POST /mcp a tools/call of report with {repo, title}. It answers read-only and files nothing.

🤖 Generated with Claude Code

Closes #14951

3 earlier comments · 2 events
commented

A signed-in call of report, start or offer through the token-free shortcut now gets the same checks as any other tool call. Before this, the forge's own agent, after reading untrusted text, could file a report under the person's name with no confirm, and an ro token could make that write (finding from #14765).

What changed: in src/http/mcp.ts, openToolCall sends signed-in calls of these three tools through a new gatedShortcut. It runs the same steps in the same order as the ordinary tool-call path in rpcOne:

  • askedFirst and heldWrite, so a steered write is held as a confirm;
  • the rw scope floor, so an ro token gets READ_ONLY_REFUSAL;
  • readThrough;
  • the handler, then fenceAnswer on each text block of its answer.

Callers who are not signed in go straight to the handler as before. No tool was added and the ceilings are unchanged.

Look at: gatedShortcut treats all three tools as writes, since each one creates something (a report, an account, a patch offer). That means a signed-in ro token calling start or offer is now refused as read-only. I chose not to skip the duplicate-write record (claimDone/recordWrite) on purpose: these handlers return JSON-RPC answers rather than results that record expects.

Tests: the new test/mcp-shortcut-fence.test.ts checks two things: the forge's agent reads an issue Mallory wrote and then calls report, and gets needs_confirm with nothing filed; an ro token is refused the report while an rw token files it. Both tests fail without the change to mcp.ts and pass with it. bun test test/mcp-size.test.ts passes, along with the report, start, offer, contribute-token, refusal-hint, agent-card, conversation-fence and muse-journey suites (154 pass, 0 fail). bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean. scripts/fast.ts called the diff too broad to run in full here (2123 test files), so the full bun test is left to the forge's check on this push.

Try it: with an ro token, POST /mcp a tools/call of report with {repo, title}. It answers read-only and files nothing.

🤖 Generated with Claude Code

Changes requested — before the latest push

The gate is right in shape and the two tests are real, but three things need fixing in one round:

  1. (first) The shortcut skips the duplicate-write record (claimDone/recordWrite/completeWrite/dropWrite) that rpcOne runs for the forge's agent. A cut turn that resends report/offer files a second report under the person's name, which is the same steered-write class the issue closes. Box 1 says exactly as the via-token path does. Run the record around the handler, completing it on an ok answer and dropping it on a failure.
  2. The stub tool object (run that does nothing, empty description and schema) is dead scaffolding that askedFirst/heldWrite read by accident. Give report/start/offer a real descriptor (a small named const next to TOKEN_FREE_HANDLERS) so what the fence reads is declared, not faked.
  3. Tests: the fenced-answer branch (fenceAnswer on the handler's text) has no test that would fail without it, and the ro refusal for start and offer, which the description claims as a behaviour change, is untested. Add both, plus a duplicate-resend test for item 1. A signed-in ro token calling start is now refused as read-only; say in the test why that is intended.
commented

When a person is signed in, the token-free MCP shortcut (report, start, offer) now goes through the same gates as a write made with a token (#14951):

  • Fence: the forge's agent is held and asked to confirm after it has read text someone else wrote.
  • Scope floor: a read-only (ro) token is refused the write.
  • Duplicate-write record (#8254): each write is recorded before it runs. A turn that was cut and then resends the same write gets the earlier answer back, and nothing is filed a second time.
  • Fenced answer: the forge's own agent reads the handler's answer inside a data block.

A stranger with no token goes through the shortcut as before.

What changed since the last review:

  • Write record: gatedShortcut in src/http/mcp.ts now runs claimDone/recordWrite before the handler. It calls completeWrite with the fenced text when the answer is ok, and dropWrite when the answer is an error or the handler throws, so a failed write can be sent again.
  • Real descriptors: the stub tool is gone. A new TOKEN_FREE_WRITES table next to TOKEN_FREE_HANDLERS points at the existing REPORT_TOOL, START_TOOL and OFFER_TOOL. Only names in that table are gated, so the fence reads fields each tool declares.
  • ToolShape type: this is Tool without run, added in src/http/mcp/shared.ts. plansOnly, heldWrite, askedFirst and askedWork now take it, so the descriptors can be passed without a fake run. Every existing Tool still fits.
  • Tests in test/mcp-shortcut-fence.test.ts:
    • the agent's answer is fenced, an rw token's answer is plain;
    • an ro token is refused start and offer with nothing created;
    • a report resent after a cut turn returns already_done and is filed once, and a deliberate repeat after that is filed;
    • a refused write is not recorded, so a resumed turn may send it again.

    The ro test says in a comment that refusing start is intended: a signed-in start creates a repository for the account, so it is a write. I ran each test with its code removed, and each fails.

Checks: bun scripts/gate.ts --fix passed, and bun x tsc --noEmit is clean. scripts/fast.ts said the change was too broad to name tests (2408 files, because shared.ts changed), so I ran 232 MCP, fence, hold, resume, offer and report suites by hand: 1426 pass and 1 fails. The failure is test/mcp-doc-names-every-argument.test.ts, which reports that the doc of explore omits argument template. It fails the same way with this change stashed, and this pull does not touch explore.

To try it: bun test test/mcp-shortcut-fence.test.ts.

🤖 Generated with Claude Code

commented

When signed in, the MCP shortcut that runs a tool without a token now applies the same fence and read-write scope floor as any other write (#14951). Writes made through it are recorded like any other write. A read-only token calling tools/call report is refused and nothing is filed.

  • src/http/mcp/shared.ts: a new ToolShape type (a tool minus its run) is what plansOnly, heldWrite, askedFirst and askedWork read now. That lets the shortcut check a tool from what it declares without running it.
  • src/http/mcp.ts: the shortcut checks the fence and the scope floor before it calls the tool.
  • test/mcp-shortcut-fence.test.ts: covers fenced, read-only and allowed calls through the shortcut. Its 6 tests pass.

There's no terminal change. The last commit is empty apart from a No door: line for the gate's "both doors" rule: the shared.ts edit only changes which type those helpers accept. The token-free shortcut exists only on the MCP, and the terminal reaches tools through its own signed-in screens, so it gains nothing to reach.

The gate still prints similarity warnings; none of them fails it. One is between heldWrite and askedFirst. Three are test helpers that match helpers in existing tests: call, mk and viaToken. I left them separate to keep this pull small.

Locally, bun scripts/gate.ts and bun x tsc --noEmit both pass.

🤖 Generated with Claude Code

Approved

The later rounds meet the earlier asks. The shortcut records the write (claimDone/recordWrite, completeWrite, dropWrite on error or throw), uses the real REPORT/START/OFFER descriptors through ToolShape, and fences the answer for the forge agent only. The tests cover the fence hold, the ro refusal for report, start and offer, the fenced and plain answers, resend dedupe and the refused-write drop. I could not diff against 42c6d4018a66 because the clone lacks that commit, so I read the change as listed. Non-blocking: heldWrite and askedFirst are near-duplicates, and the test helpers call/mk/viaToken repeat ones in other tests.

commented

Left #14951 open: 1 unticked item remain (bun test passes).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs