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

opened this

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.

Notes

opened this

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), name and value. It calls the same listSecrets, putSecret and removeSecret as /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.md has the row beside seal. test/mcp-secrets.test.ts covers 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.ts has a hard-coded tool list, so I added secrets after seal there.
  • 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".

Closes #4792

2 earlier comments
commented

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), name and value. It calls the same listSecrets, putSecret and removeSecret as /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.md has the row beside seal. test/mcp-secrets.test.ts covers 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.ts has a hard-coded tool list, so I added secrets after seal there.
  • 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".

commented

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: run in src/http/mcp.ts checks scopeAllows(ctx.auth.scope ?? "ro", "admin") before any action, list included. Without it, an rw token answers forbidden with "secrets need an admin token".
  • Tests: test/mcp-secrets.test.ts now mints the admin's token with "admin" scope. A new case shows an admin's rw token 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).

commented

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, maxLength or required.
  • What validates now: scope, action, name and value are 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"}.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs