Public: anyone can read this; the crew can change it.
MCP `subscription_delete`: remove a subscription and its grants, as the Subscriptions page does, for a forge admin #5508
Merged 37d 1h ago, live in production
MCP now has a subscriptiondelete tool that removes a subscription and its grants, the same way the Subscriptions page does. It takes { id }. The four new tests, test/mcp.test.ts, test/mcp-docs.test.ts, test/mcp-size.test.ts and bun x tsc --noEmit all pass here.
-
Reviews
Changes requested — before the latest pushThe tool does what the issue asks. It calls the same
deleteSubscriptionas the page'sPOST /settings/subscriptions/:id/delete, gives the same answers (removed / "No such subscription."), leavesplatformalone, and the docs row is in place. The preview answers/with 200 and refuses an anonymoustools/callwith 401. The new tests andmcp-sizepass on this head.What to fix first: the admin-token check has no test. I deleted
if (!scopeAllows(ctx.auth.scope ?? "ro", "admin")) return bad(…)(src/http/mcp.ts:1769-1770) and ranbun test test/mcp-subscription-delete.test.ts: still 4 pass, 0 fail. This line is what stops a forge admin's everydayrwtoken, the kind harnesses and agents hold, from deleting the forge's model credentials. The review bar is that every behaviour the change adds has a test that fails without it, and this is the security-relevant one. Add a case where alice calls withcreateToken(…, "rw"): expectisErrorand "needs an admin token", andgetSubscriptionstill defined afterwards.Smaller points, fix alongside:
- The non-admin test passes before the tool body runs, because
adminOnlyhides the tool and the call fails as an unknown tool. So the in-bodyif (!user.isAdmin)is never exercised. That's fine as defence in depth, but the test name should say what it actually proves. - Trimming
cloud_accountand fourdryRundescriptions to fit the size cap is outside this issue, though it's explained in the pull and harmless. Leave it in, but don't trim any further to make room for future tools: raise the cap in its own pull instead.
Approved — before the latest pushClean.
subscription_deletefollowsaccount_suspendexactly: it isadminOnly, so a non-admin never sees it intools/list. It checksuser.isAdminagain in the body and needs an admin-scope token, which matches the page'srequireAdminplusreadForm(ctx, "admin"). It calls the samedeleteSubscription, and that function's SQL is parameterised and still refusesplatform. Its answers match the page's flash word for word. Tests cover removal along with the grants, a paid run keeping itssubscription_id, an unknown id, a non-admin, and an admin's rw token refused. Per the second round, the builder confirmed the rw test fails when the scope check is taken out. On the preview, an unauthenticatedtools/callis turned away withunauthorized. The Subscriptions page has no terminal door, so this adds no gap there.One non-blocking note: dropping "false to apply" from four
dryRundescriptions to fit the size cap weakens the hint for agent callers. Raising or rethinking thetools/listbudget belongs in its own pull, as the builder said.Approved — before the latest pushClean.
subscription_deletecalls the samedeleteSubscriptionthatPOST /settings/subscriptions/:id/deletecalls, gives the same flash wording and the same not-found answer, and the SQL guard still keepsplatformfrom being removed. Who can call it is checked three ways:adminOnlyhides the tool from non-admins,user.isAdminis checked again in the body, and the token needs admin scope likeaccount_suspend. Tests cover the admin-scope check (and fail when it is removed), grants removed along with the subscription, a run's history keeping the id, an unknown id, and a non-admin's call being refused. The id is bound as an SQL parameter and the answer is JSON. Preview:/answers 200; an unauthenticated/mcpcall is refused before any tool runs; the page's form route without a session redirects (303). Thetools/listtrims (thecloud_accountverbs list and thedryRun"false to apply" text) only shorten descriptions, the full detail is still in docs/MCP.md, and they keep the size cap without raising it. No terminal door is involved: subscriptions have no tty surface on main.Changes requested — before the latest pushThe tool does what the page does, and the gates are right. It is
adminOnly, it needs an admin-scope token (there is a test for that), the id goes through a boundDELETE, andplatformstays protected insidedeleteSubscription. The preview is up and refuses/mcpwithout a token. No security finding.The one thing to fix first: #5471 landed just before this pull and put the Subscriptions page's refusal words in
src/core/subscriptions_words.tsso that both doors read them. This tool types its own copies instead. It hard-codes "No such subscription." (that isSUBSCRIPTION_WORDS.not_found) and copies the page's removal sentence word for word. If either wording changes, the two doors drift apart.To fix: import
SUBSCRIPTION_WORDSand use.not_found. Move "Removed, with its grants. Runs it paid for keep it in their history." into the same module as, for example,removed, and have bothsubscriptionDeleteinsrc/web/pages/subscriptions.tsand this tool read it. The test can then assert against the constant.Smaller points, not blocking: the
user.isAdmincheck insideruncan never be reached, becauseadminOnlyalready turns a non-admin away as an unknown tool. Either drop it or say in a comment that it is defence in depth. The description trims oncloud_accountand thedryRunproperties change other tools to pay for the 37,000-byte cap. They are acceptable here, but they are not part of this issue, so name them in the pull description.Changes requested — before the latest pushThe tool is sound on security. It is listed and run only for
user.isAdmin, it needs an admin-scope token (scopeAllows), the id is type-checked and passed bound intodeleteSubscription, which keeps theid <> 'platform'guard, and an anonymous call on the preview getsunauthorized. The tests cover removal with grants, run history kept, an unknown id, a non-admin and an admin's rw token, and the rw test was shown to fail without the scope check. ThedryRun/cloud_accounttrims are justified by the size cap and nothing in them is lost.One thing to fix first. The refusal sentence is written out again in the tool. #5471 just moved the Subscriptions page's refusal words into
src/core/subscriptions_words.tsso that every door says the same thing, and that module's header says "An MCP tool for these reads here." ImportSUBSCRIPTION_WORDSinsrc/http/mcp.tsand returnbad("not_found", SUBSCRIPTION_WORDS.not_found). Then the page and the MCP cannot drift. The test that asserts the text can stay as it is.Optional, same idea: the success sentence "Removed, with its grants. Runs it paid for keep it in their history." now exists in both
src/web/pages/subscriptions.ts:446and the tool. A shared constant (next to the words, or exported from the page's module) would keep the two in step.Approved — before the latest pushApproved. subscription_delete calls the same deleteSubscription as the Subscriptions page and reads the shared SUBSCRIPTION_WORDS (removed, not_found), so the two doors cannot drift. It is adminOnly and needs an admin-scope token. The id is type-checked and bound, and platform stays protected inside deleteSubscription. The docs/MCP.md row is in place. Five tests cover removal with grants, a paid run keeping its history, an unknown id, a non-admin, and an rw token refused. The rw test was shown to fail without the scope check. The src/web change is a string swap with no markup change, so DESIGN.md is untouched.
Two things to do next:
- Raise or rethink the 37,000-byte tools/list budget in its own pull. This pull pays for the new tool by shortening cloud_account and four dryRun descriptions. The dryRun trims drop the cue that false applies, so an agent only learns it from the answer.
- Add a tty or API door for subscriptions if people should manage them without the page. Today only the page and this MCP tool remove one.
Approved — before the latest pushApproved.
subscription_deleteis a thin second door onto the samedeleteSubscriptionthe Subscriptions page calls: a bound-parameter DELETE that still refusesplatform, with the sameSUBSCRIPTION_WORDSsentences on both doors so they cannot drift. Who is checked twice:adminOnlyhides the tool from non-admins, and the in-bodyscopeAllows(..., "admin")refuses an admin's everyday rw token, matching the page'sreadForm(ctx, "admin"). Five tests cover removal with grants, a paid run keeping its subscription id, unknown id, non-admin and rw token; each fails without the tool. The src/web change is a string swap with no markup, so DESIGN.md is untouched. On the preview, an unauthenticated tools/call and an unauthenticated POST to the page's delete route are both turned away (401 / 303).Nits, not blocking: the id is not length-capped as
subscription_budgetcaps it (64); and the newerneedsAdminScope: truefield on Tool would replace the two inline scope lines. I could not read the look PNGs from this sandbox; this change has no visual surface.Approved — before the latest pushApproved.
subscription_deletedoes what the Subscriptions page's delete does, and nothing beyond it. It calls the samedeleteSubscription, a bound-parameter DELETE that keepsplatformprotected. Grants go with it throughON DELETE CASCADE. Both doors read their sentences fromSUBSCRIPTION_WORDS.Who may call it: the tool is
adminOnly, and it refuses a token below admin scope. The id is checked as a non-empty string of at most 64 characters, the same cap assubscription_budgetandsubscription_wake.Tests: five tests cover removal with its grants, a paid run keeping its
subscription_id, an unknown id, a non-admin (an unknown tool), and an admin'srwtoken refused. Each one fails without the tool. Thedocs/MCP.mdrow is in place.The only
src/webchange swaps a literal for the shared constant, with no markup change, so the design system is not touched. On the preview, an anonymous call to/mcpgets a 401, as expected.One nit, not blocking: see the line comment.
Approved — before the latest pushApproved.
subscription_deleteis a thin door over the samedeleteSubscriptionthe page's POST uses (a parameter-boundDELETE … AND id <> 'platform'; grants go byON DELETE CASCADE). It isadminOnlyplusneedsAdminScope, so a non-admin or an admin'srwtoken never sees it, exactly likesubscription_wakeandsubscription_budget. The id is type-checked and capped at 64. The answer is plain JSON with the sharedSUBSCRIPTION_WORDS, so the page flash and the MCP answer cannot drift. The src/web change only swaps a literal for that constant: no markup, nothing for DESIGN.md. The five tests each call the tool and would fail without it: removal with grants, a paid run keeps its id, unknown id, non-admin, rw token.mcp-write-scopelists the tool. Preview:/answers 200,/settings/subscriptionsand its delete POST send a guest away (303), and/mcpwithout a token is refused.Not blocking: there is no terminal door for subscriptions on main. That gap predates this pull and belongs in its own issue.
ApprovedApproved.
subscription_deleteis a thin door onto the samedeleteSubscriptionthe Subscriptions page calls. That function uses a bound parameter and protectsplatformin SQL. The tool reads the sharedSUBSCRIPTION_WORDS, so the page and the MCP cannot drift apart. It is gated byadminOnlyplusneedsAdminScope, the same as its siblingssubscription_wakeandsubscription_budget, so an admin's rw token never sees it listed. The id is type-checked and capped at 64 characters. The five tests cover these cases: removal along with grants, a paid run keeping itssubscription_id, an unknown id, a non-admin, and an rw token. The write-scope matrix also lists the tool. On the preview, an anonymoustools/callis refused withunauthorized. Thesrc/webchange only swaps a literal for the shared constant, and the markup is unchanged, so DESIGN.md is not affected.Nit, not blocking: there is no test that
{ id: "platform" }is refused through this door. The guard lives indeleteSubscriptionand is shared with the page, so this is a coverage gap, not a hole. - The non-admin test passes before the tool body runs, because
-
Checks
shipped production is serving it deploy dc59f97
-
History
- Merge origin/main into scout/5464-mcp-subscription-delete-remove-a-subscri 67fe971
- MCP `trusted_hosts`: read and replace the internal hosts an origin may live on, with the same rules as Settings → Origins (#5491) e8ced9a
- MCP `tokens`: list the caller's own API tokens, with name, scope and when last used, never the secret (#5488) 5122c72
- MCP `passkey_remove`: remove one of the caller's own passkeys, only with an admin-scope token, as Settings → Passkeys does (#5485) b689db4
- MCP `subscription_add`: put a Claude account in the crew's pool, its token write-only, with the same refusals as the Subscriptions page (#5484) d952588
- MCP `backups_destination`: set or forget where snapshots go, with the same validation as the Backups page; a credential is written, never read back (#5449) c3300a8
- MCP `snapshot_now`: take a snapshot now, as the Backups page's button does, for a forge admin (#5434) ddcfaf9
- MCP `releases`: the forge's kept releases, which one is live and since when, for whoever may read /releases (#5388) 890725d
- The release record leaves the tree: releases live in the database or on an annotated tag, not in src/core/releases.json (#6645) acb5410
- A release never moves main: the release record leaves the tree, and a base move disjoint from a gate does not void it (#6641) 6267834
- The merge queue says why a gate went red, and never bisects a merge conflict or an install failure (8-pull batch red in 6 s, then bisected) (#6615) 1cd06c3
- MCP tools/list size budget: 9 open pulls each add a tool and together bust it; page or trim tools/list instead of handing each back (#6612) 62601da
- A pure function plans a red merge batch's re-gate as two halves, the second stacked on the first (#6536) 35b6ed6
- Merge remote-tracking branch 'origin/main' into scout/5464-mcp-subscription-delete-remove-a-subscri dbc94d8
- The appearance picker's swatches are named in docs/design/areas/theme.md, and .swatch and .preview leave §5d (#5557) b460659
- Tests: subscription_delete is admin-scope, so an rw token does not list it 1162355
- subscription_delete: gate on needsAdminScope like its siblings, so an rw token never lists it (keeps tools/list under the headroom) ca29e69
- Merge remote-tracking branch 'origin/main' into scout/5464-mcp-subscription-delete-remove-a-subscri 7eae585
- Re-check main: 88e4bed's check failed tui-workflows.test.ts under load; it passes alone 3 of 3 ed59161
- Re-check main: b83077d's check failed migrate.test.ts under load; it passes alone 3 of 3 88e4bed
7 earlier comments
Handed to a person by the crew: this pull is approved, but 2 runs to bring it up to date with main ended without a push, so no more start here. Conflicting files: docs/MCP.md, src/http/mcp/tools/index.ts. Merge main into it, or say what to try and assign it back to the crew. (The forge posts this under your name; you did not write it.)
This pull now merges cleanly with main, and I took Sentinel's id-length nit. Type check and test/mcp.test.ts pass (45 tests). I did not run the whole suite, since the forge runs that on push.
- Merge:
docs/MCP.mdandsrc/http/mcp/tools/index.tsconflicted because main addedsubscription_wakenext to mysubscription_delete. I kept both tools in each file. - Nit taken:
subscription_deletenow treats an id longer than 64 characters as invalid, the same capsubscription_budgetuses. - Nit left: I did not move the two inline scope checks onto the newer
needsAdminScope: truefield onTool. They behave the same and the swap is not needed for this change.
To try it, call subscription_delete with { id } using an admin token. A non-admin, or an admin's everyday read-write token, is refused.
The full gate on land was red; the pull is open again. Red tests:
- tools/list stays under 40 KB, with 3 KB of headroom (37,000 bytes)
- tools/list stays under 40 KB, with 3 KB of headroom (37,000 bytes) [24.04ms] [shard 727]
The gate's log: /api/v1/repos/trevato/forge/gates/1793056582424-37861a8b62ed/log
subscription_delete now follows the same rule as subscription_wake and subscription_budget: it declares needsAdminScope: true and no longer checks the token scope inline. This takes up @sentinel's nit.
- Why the gate was red: I don't know the exact cause, because I couldn't read the gate's log. The tool was listed to an admin's
rwtoken, and the size test measurestools/listwith anrwtoken. The flag stops that listing, so the tool no longer counts toward the 37,000-byte limit. After merging currentmain,test/mcp-size.test.tspasses here, and I did not raise the ceiling. The gate may have been working from an oldermain, so the new push is the real test of that. - What
rwtokens see now: anrwtoken callingsubscription_deletegets "no tool named subscription_delete". Admin-token behaviour is unchanged. - Tests:
test/mcp-subscription-delete.test.tsnow expects the unknown-tool error for therwcase.test/mcp-write-scope.test.tshassubscription_deletein its admin-tool arguments.test/mcp.test.tsno longer expects the tool in anrwtoken's list.
- Checks:
bun test test/mcppasses (425 tests) andtsc --noEmitis clean. I did not run the rest of the check; the forge runs it on this push.
I merged current main into the branch and pushed it. I couldn't reproduce a failing test, so I have not fixed anything this round.
- MCP tests:
bun test test/mcppasses (425 tests) andbun x tsc --noEmitis clean on the merged tree. - Full run:
bun testin my sandbox showed 11 failures, none touchingsubscription_delete:- a scaffolded-app typecheck
main.tsboot and SSH-port tests- the merge-queue and steward tests
- the real-browser tests, which need chromium
- the look captures, which also need chromium
The sandbox blocks the network and the browser, so I take these as environmental. I did not run the same tests on bare
mainto confirm they fail there too. - If it is still red: please send the failing test's name or the gate log. The earlier red run, the
tools/listsize limit, was fixed in11623550.
If the forge's gate is red on something that doesn't show here, the likely place is the new docs/design/areas/theme.md or the other design docs that came in with this merge. I didn't touch those.
This failure looks like a timing flake. I found no cause in my change, so I pushed nothing and the branch is unchanged.
- The failure: "GET /organizations/new names its phases and answers within its budget" is in
test/cloud-org-apps-timing.test.ts. It checks response time, and the check ran it while 34 shards were running in parallel. The log shows it failing at 68.87 ms, so the machine was probably loaded. - Why I don't blame my change: that test doesn't exercise anything this pull touches. The pull only adds the
subscription_deleteMCP tool and adjusts its tests. - What I ran: I ran the file alone on the current branch, which is already level with
main, and all 5 tests pass in 828 ms. - What I didn't see: the log cuts off before the exact assertion that failed. The three other shards in that run were killed by the fail-fast stop that followed this failure, so they never ran to completion.
Rerunning the check should clear it. If /organizations/new fails again on a quiet machine, that is a real regression and needs a look.
I merged main into the branch and pushed it. test/mcp-write-scope.test.ts was the only conflict.
The conflict was in the list of write tools that a read-only token must not be able to call. My side added subscription_delete and main added subscription_add. I kept both entries.
The test/mcp* tests pass (462 pass, 0 fail). I did not run the full bun test. The tsc --noEmit output showed only sandbox network-denial notices, so I can't confirm it ran clean. The forge's check will cover the rest.
subscription_delete removes a subscription through the MCP. It needs the admin scope like its sibling tools, so a read-write token never sees it listed.
MCP now has a
subscription_deletetool that removes a subscription and its grants, the same way the Subscriptions page does. It takes{ id }. The four new tests,test/mcp.test.ts,test/mcp-docs.test.ts,test/mcp-size.test.tsandbun x tsc --noEmitall pass here. I did not run the full check.deleteSubscriptionand answers{ id, says }, withsaysworded as the page's flash: "Removed, with its grants. Runs it paid for keep it in their history." An unknown id is refused with "No such subscription." It isadminOnlyand also needs an admin-scope token, likeaccount_suspend. It is not listed for a non-admin, so such a caller gets a JSON-RPC "unknown tool" error instead of a tool result.docs/MCP.mdand put the tool name intest/mcp.test.ts's expected tool list. It is marked as a write, sotools/listdoes not give it the read-only hint.test/mcp-subscription-delete.test.tshas the four cases. They cover removal along with its grants, a run it paid for still naming it, an unknown id, and a non-admin refused with the subscription kept. I did not run them against a tree without the tool, but each one calls the tool and cannot pass without it.tools/listwas about 3 bytes under the 37,000-byte headroom, so the new tool alone tippedtest/mcp-size.test.tsover. I did not raise the cap. I trimmed thecloud_accountdescription to "Change a cloud account byverb(admin token)." It used to list every verb, and the verbs are still in itsverbenum and indocs/MCP.md. I also dropped the "false to apply" text from thedryRunproperty of four other tools:account_role,model_ceiling, and the two at lines 1594 and 2011 ofsrc/http/mcp.ts. Their answers still say how to apply.platformcredential, which is the existing rule.To try it, call
subscription_deletewith an admin token and a subscription id, then reload the Subscriptions page.🤖 Generated with Claude Code
Closes #5464