Repository navigation
fix(backend-claude): disallow the in-worker Apify tools in every session - #4021
Merged
Merged
Conversation
A hosted interactive Claude turn loads the brain's .mcp.json, whose core server registers brain_apify_* unconditionally. A worker holds neither the token nor the ledger, so every mcp__brain__brain_apify_* call refused with ledger_unset, under the same names and descriptions as the host's working mcp__brain-ui__brain_apify_* tools. IN_WORKER_APIFY_TOOLS, derived from APIFY_TOOL_NAMES, joins IN_WORKER_COMPUTE_TOOLS in every session's disallowedTools, whatever the configuration, so the tool list never depends on it. The roster test now asserts the exclusion in every interactive mode and across autonomous, hosted, voice and Apify-enabled turns; the SDK options snapshot records the ten added names and nothing else. Closes #3788 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
7 tasks done
9 tasks done
schlessera
marked this pull request as ready for review
November 15, 2026 17:02
Merged
8 of 9 tasks
9 tasks done
schlessera
marked this pull request as draft
November 15, 2026 19:01
schlessera
marked this pull request as ready for review
November 15, 2026 19:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3788
What changed
A hosted Claude turn no longer exposes the in-worker core server's
mcp__brain__brain_apify_*tools. An interactive turn loads the brain's.mcp.json, whosebrain mcpserver registers all tenbrain_apify_*tools whatever the configuration. A worker never receivesAPIFY_TOKENorBRAIN_APIFY_LEDGER, so every call to those copies refused withledger_unset, under the same names and descriptions as the workingmcp__brain-ui__brain_apify_*tools.IN_WORKER_APIFY_TOOLSis derived fromAPIFY_TOOL_NAMESand sits next toIN_WORKER_COMPUTE_TOOLSinpackages/ui-backend-claude/src/sdk-options.ts. Every Claude session now disallows it, whatever the host configures, as it already does compute. The host'smcp__brain-ui__brain_apify_*tools and standalonebrain mcp/brain apifyare unchanged.Why this shape
This is the issue's stated approach and the core: expose external compute through CLI, MCP and agent guidance #3107/ui-server: admit and observe external jobs through existing worker governance #3108 compute precedent. The exclusion is unconditional, so the tool list never depends on configuration (provider history).
The name list is derived from the shared contract (
APIFY_TOOL_NAMES, the same objectregisterApifyToolsregisters from), so a new operation is excluded without a second list.disallowedToolsdoes remove the tools from the model's list on the production path. I checked this against the installed CLI rather than assuming it. I ran a temporary, uncommitted variant ofscripts/capture-turn-surface.tsthat serves core as a real stdio server, as.mcp.jsondoes, and scriptsToolSearch select:mcp__brain__brain_apify_approvalsfollowed by a call:origin/main:mcp__brain__brain_apify_runwas in the deferred listing, ToolSearch answeredTool loaded., and the call went through;brain_searchstill was), ToolSearch answeredNo matching deferred tools found, and the call gotNo such tool available: mcp__brain__brain_apify_approvals.The committed capture serves core in-process (an SDK server). There the CLI keeps listing disallowed MCP tools and only refuses the call (
Permission to use … has been denied), which is whytests/installed-turn-surface.test.tsstill lists both the compute and Apify copies. I added a comment there saying so; its assertions are unchanged.Pi: not exposed. Pi has no MCP client and never reads
.mcp.json. Its core tools are curated custom tools, and itsbrain_apify_*tools are host bridge tools forwarded to the host (packages/ui-backend-pi/src/bridge-tools.ts:353-360), which the fixedapifycapability enables (currentCaps,packages/ui-backend-pi/src/session-pool.ts:70-75). Only a third-party MCP extension, which an operator would have to turn on, could add an MCP server, and that is outside this backend's roster.Proof
packages/ui-backend-claude/tests/stable-roster.test.ts). The existing every-mode roster test gains anapify(enabled) mode. In every mode it asserts that nomcp__brain__+APIFY_TOOL_NAMESname is missing fromdisallowedTools, and that the enabled mode still auto-allowsmcp__brain-ui__brain_apify_run. The byte-identical native-exclusion check now covers the Apify names too. A new matrix covers interactive or autonomous × hosted or unhosted × Apify enabled or disabled × typed or voice (16 cases). It asserts the same exclusion and that nomcp__brain-ui__tool is ever disallowed.sdk-options.tsfromorigin/main): 33 pass, 17 fail. All failures are on the named assertion: 16 ×IN_WORKER_APIFY_DISALLOWEDand 1 ×IN_WORKER_APIFY_DISALLOWED_voice, each listing the ten missing names.brain_apify_revokefromIN_WORKER_APIFY_TOOLS, restored afterwards): 33 pass, 17 fail on the same assertions. Each received["mcp__brain__brain_apify_revoke"]where it expected[].sdkOptionsSnapshot) for this one reviewed change. The diff is exactly the tenmcp__brain__brain_apify_*names appended todisallowedToolsin each of the six modes. Nothing else moves, and the provenance comment insdk-options-snapshot.test.tsrecords it.packages/ui-backend-claude,bun run test), base against this change in the same sandbox: the failing sets are identical (51 sandbox-only real-CLI/bwrap failures, including the provider-history capture, which cannot spawn a worker here). The only extra failures were the six snapshot modes, before they were re-recorded.tests/installed-turn-surface.test.tspasses locally against the installed CLI.bun run typecheckandbun run build: clean (new export).bun run lint: clean.listTools(brain.tools) plus the bridge peer (scripts/measure-turn-surface-live.ts:145), anddisallowedToolsnever touches either.{"version":1,"kind":"brain-check-pr-receipt","head":"4e5260d8062768cbf756f402bb6af0588bbcb1c0","base":"origin/main","mode":"focused","startedAt":"2026-11-15T14:37:03.564Z","finishedAt":"2026-11-15T14:38:13.147Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12507.265190999999},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":104.22086900000068},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":101.05285200000071},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.019437999999354},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":56833.450362}]}Checklist
mcp__brain__brain_apify_*; holds in every configuration; derived roster test with mutation receipt)..changeset/3788-in-worker-apify-disallowed.md,@schlessera/brain-backend-claudepatch).docs/reflect the change (docs/decisions/apify-capability.md, "Front doors and memberships").disallowedTools.Anything left open
Collision check (
bun scripts/collisions.ts --json --pr 4021) at head4e5260d8062768cbf756f402bb6af0588bbcb1c0: no path collisions. The overlaps are closure-only, with #3056, #3059, #3069, #3116, #3437, #3581, #3622, #3806, #4002, #4007, #4008, #4012, #4013, #4016, #4018 and #4020.The issue's live verification (a real hosted interactive turn with Apify enabled) is covered by the offline installed-CLI stdio check above, not by a paid live turn.
🤖 Generated with Claude Code