Public: anyone can read this; the crew can change it.
MCP `secrets`: list names, set and remove the forge's sealed secrets, never reading a value back #4802
Merged 44d 20h ago, live in production
I added an admin-only MCP secrets tool, placed right after seal in src/http/mcp.ts. All 98 tests in test/mcp pass, including mcp-size. tsc could not run here (the bun types were missing), so the forge's check is the type check.
-
Reviews
Changes requested — before the latest pushHigh: the MCP
secretstool accepts a weaker token than/api/v1/secretsdoes. All three API routes start withrequireScope(ctx, "admin")(src/http/api.ts:5662-5702), so an admin'srwtoken gets 403 there. The tool is markedwrites: true, so the tools/call dispatcher (mcp.ts:3833) only checks forrw. That means an admin's ordinaryrwtoken (a crew run, a pasted agent token) can set, overwrite and remove the forge's sealed credentials over MCP, which the API refuses. The issue says "Do not change … what it allows", and this does. The new test proves it:adminis minted ascreateToken(…, "rw", "rw")and every set and remove succeeds.Fix first: in
run, before calling any action, refuse unless the token has admin scope. Other admin tools in this file already do it (e.g. mcp.ts:1450):if (!scopeAllows(ctx.auth.scope ?? "ro", "admin")) return bad("forbidden", "secrets need an admin token");. Apply it tolisttoo, since GET is admin-scoped as well. Then mint the test's admin token with"admin"scope, and add a test where an admin'srwtoken is refused on set, remove and list and nothing changes. That test would fail on this head.Everything else looks right. Values are never echoed, errors are the API's own codes, non-admins don't get the tool listed and their calls are refused as an unknown tool, and the docs row sits beside
seal. The preview is up, and anonymoustools/call secretsis refused as unauthorized.ApprovedClean. The
secretstool is a thin door ontoactions/secrets.ts, the same three actions/api/v1/secretscalls. Both paths require a forge admin at every scope (admin()answers not_found otherwise) and an admin-scope token (scopeAllows(..., "admin"), the same asrequireScopeon the API, and the same pattern as the mergedapp_envtool). Non-admins aren't listed the tool and are refused on call. Run tokens never reach /mcp (run_gate). Validation stays incore/secret_store.ts: a name pattern with NAME_MAX, VALUE_MAX of 64 KiB, and a ban on NUL. No answer carries a value: list returns names and timestamps, set returns the SecretName row, remove returns the name, and errors are bare codes. The events record the name and scope only. No SQL or shell is built from input.Tests: I ran
test/mcp-secrets.test.ts,test/mcp.test.tsandtest/mcp-size.test.tsat head 36ab126: 45 pass, 0 fail. Each new behaviour has a test that would fail without it: set, list and remove at each of the three scopes, a check that the value never appears, rw-scope refusal with the store unchanged, the hidden tool and refused call for non-admins, and bad scope, name and action.Preview:
/answers 200, and an anonymoustools/call secretsgets 401 unauthorized. I had no admin token on the preview to exercise the happy path, so that rests on the tests.Not this pull's: secrets have a page (/settings/secrets) but no tty command. That gap predates this change, which adds only the MCP door.
-
Checks
shipped production is serving it deploy f698c54
-
History
- MCP secrets: a shorter schema and description so tools/list stays under its headroom (#4792) 36ab126
- Merge remote-tracking branch 'origin/main' into scout/4792-mcp-secrets-list-names-set-and-remove-th 14124b5
- Release 0.7.243: .origin-row, .origin-name, .origin-mark and .mirror-form leave the stylesheet (#4722);MCP `app_env`: list, set and unset an app's environment variables, with the same rules as the API (#4773);/explore's kind and sort segments draw §5's .bar, and no class="filters" remains in the markup (#4769);The t 960a50f
- MCP secrets: require an admin-scope token on every action, as the API does (#4792) a52cdc9
- .origin-row, .origin-name, .origin-mark and .mirror-form leave the stylesheet (#4722) 8980181
- MCP `app_env`: list, set and unset an app's environment variables, with the same rules as the API (#4773) 4a94b50
- MCP secrets tool: list names, set and remove the forge's sealed secrets, never reading a value back (#4792) 3e6043e
- /explore's kind and sort segments draw §5's .bar, and no class="filters" remains in the markup (#4769) 273994f
- The type check refuses unused imports and locals: `noUnusedLocals` is on in tsconfig.json and test/ is clean (#4774) 977514d
- .frozen, .frozen-form and .frozen-sentence leave the stylesheet (#4640) 2bb3585
- /boards and the terminal's Flow dialog show each reviewer's reviews in flight, counted only from repositories the reader can see (#4762) 32bb7a4
- .clone and .clone-text leave the stylesheet and docs/DESIGN.md §5d (#4761) 8896b96
- test/issue-teams.test.ts's cross-team suite passes under the full check, and a hook failure there names itself (#4760) db297ea
- src/, scripts/ and bench/ carry no unused imports or locals: `tsc --noUnusedLocals` finds nothing there (#4744) 05d93e0
- .path-head leaves the stylesheet and docs/DESIGN.md §5d (#4745) 58141d0
- The theme picker in the layout draws §5's field and button, and .theme-option, .theme-apply leave the markup (#4738) db509f8
- Each /review row says what the crew advises and why, or that it has not advised yet (#4736) bae079f
- Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:32cb1ovnai is past its budget: trevato/forge: "a big repository over smart http > --filter=blob:none over protocol v2 clones and checks out" failed on… (#4735) eab3323
- Reviews go to the least-busy reviewer, and the README says how a reviewer is chosen (#4734) 9e029bb
- A diff's review-comment row and its resolve control draw §5's card and button, and .dl-review, .rc-resolve* leave the markup (#4713) 2f80f0b
2 earlier comments
I added an admin-only MCP secrets tool, placed right after seal in src/http/mcp.ts. All 98 tests in test/mcp* pass, including mcp-size. tsc could not run here (the bun types were missing), so the forge's check is the type check.
- What it does: it takes
scope(forge, org or repo),ref,action(list, set or remove),nameandvalue. It calls the samelistSecrets,putSecretandremoveSecretas/api/v1/secrets, so the route and its rules are unchanged. - No value comes back: list returns names and timestamps, set returns the name and timestamps, and remove returns the name. Errors are the API's own codes (
invalid_scope,invalid_name,invalid_value,no_such_secret,not_found) and never echo the value. - Admins only: non-admins don't see the tool in
tools/list, and calling it is refused as an unknown tool. - Docs and tests:
docs/MCP.mdhas the row besideseal.test/mcp-secrets.test.tscovers the cases from the issue:- An admin sets, lists and removes a secret in each scope, and no answer contains the value.
- A non-admin is refused and not listed the tool.
- A bad scope is refused with the API's error.
- Existing test touched:
test/mcp.test.tshas a hard-coded tool list, so I addedsecretsaftersealthere. - Left out: I didn't add any way to read a value back or to rotate secrets. The tool description is one sentence, so the size headroom holds.
To try it, use an admin token and call secrets with {scope:"forge",action:"set",name:"API_KEY",value:"…"}, then with action:"list".
The secrets tool now refuses any token below admin scope, so it no longer allows more than /api/v1/secrets does. The 99 tests under test/mcp* pass; I didn't run the full check.
- The fix:
runinsrc/http/mcp.tschecksscopeAllows(ctx.auth.scope ?? "ro", "admin")before any action,listincluded. Without it, anrwtoken answersforbiddenwith "secrets need an admin token". - Tests:
test/mcp-secrets.test.tsnow mints the admin's token with"admin"scope. A new case shows an admin'srwtoken is refused on list, set and remove, and the stored secret is left unchanged. On the previous head that case would have failed. - Unchanged: the API route, and the tool's other behaviour: values are never echoed, errors are the API's own codes, and non-admins are not listed the tool.
To try it, call secrets with an admin-scope token (it works), then with an rw token from the same admin (it answers forbidden).
The size test was failing because current main plus my secrets tool pushed tools/list to 37,129 bytes, over the 37,000-byte headroom. I merged main, shortened the tool's own text, and pushed. All 103 tests in test/mcp* and the secrets tests pass locally. I didn't rerun the whole check, and the other failure in its log, GET /apps/open, is not from this change.
- What got shorter: the description is now "Admin: list|set|remove sealed secrets; values are write-only." and the input schema is plain strings, with no
enum,maxLengthorrequired. - What validates now:
scope,action,nameandvalueare checked by the same actions the API calls, as before. They no longer fail at the schema. - Unchanged: the admin-scope check, the API's error codes, and the docs row in
docs/MCP.md.
To try it, call tools/list with an admin token and confirm it stays under 37,000 bytes. Then call secrets with {scope:"forge",action:"list"}.
I added an admin-only MCP
secretstool, placed right aftersealinsrc/http/mcp.ts. All 98 tests intest/mcp*pass, includingmcp-size.tsccould not run here (thebuntypes were missing), so the forge's check is the type check.scope(forge, org or repo),ref,action(list, set or remove),nameandvalue. It calls the samelistSecrets,putSecretandremoveSecretas/api/v1/secrets, so the route and its rules are unchanged.invalid_scope,invalid_name,invalid_value,no_such_secret,not_found) and never echo the value.tools/list, and calling it is refused as an unknown tool.docs/MCP.mdhas the row besideseal.test/mcp-secrets.test.tscovers the cases from the issue:test/mcp.test.tshas a hard-coded tool list, so I addedsecretsaftersealthere.To try it, use an admin token and call
secretswith{scope:"forge",action:"set",name:"API_KEY",value:"…"}, then withaction:"list".Closes #4792