Public: anyone can read this; the crew can change it.
MCP release_keeper answers the crew's run token on the forge's own repository, the same body as GET /api/v1/keeper #15455
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15453-mcp-release-keeper-answers-the-crew-s-ru → main 0 commits fork
3 files
changed +56
−3
src/http/mcp.ts +4
| @@ -50,6 +50,7 @@ import { claimDone, completeWrite, dropWrite, recordWrite } from "../core/conver | ||
| 50 | 50 | import { type Args, alreadyDone, notAdminTool, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, readThrough, type ToolShape } from "./mcp/shared.ts"; |
| 51 | 51 | import { CONVERSATION_BRIEF } from "../crew/conversation_brief.ts"; |
| 52 | 52 | import { TOOLS } from "./mcp/tools.ts"; |
| 53 | import { runMcpRefusal } from "./run_gate.ts"; | |
| 53 | 54 | import { NO_TOOL_HINT, READ_ONLY_REFUSAL, hintOf, hintOfText, noToolNamed, withNextStep } from "./mcp/hints.ts"; |
| 54 | 55 | import { DEFAULT_TOOLS, GUEST_TOOLS, wantsAll } from "./mcp/catalog.ts"; |
| 55 | 56 | import { roleOf, type Role } from "../core/roles.ts"; |
| @@ -736,6 +737,9 @@ export function mcpRoutes(router: Router<Handler>): void { | ||
| 736 | 737 | const fault = rpcFault(value, undefined); |
| 737 | 738 | if (fault !== undefined) return fault; |
| 738 | 739 | const message = asRpcObject(value); |
| 740 | // A run token calls `release_keeper` here and nothing else (`http/run_gate.ts`, #15453). | |
| 741 | const runRefusal = runMcpRefusal(ctx.auth, message); | |
| 742 | if (runRefusal !== undefined) return runRefusal; | |
| 739 | 743 | const reported = openToolCall(ctx, message, true); |
| 740 | 744 | if (reported !== undefined) return json(await reported); |
| 741 | 745 | const answer = await rpcOne(ctx, user, message); |
src/http/run_gate.ts +23 −3
| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | * `explore` and the OpenAPI address, whose handlers answer from those two repositories alone. Every |
| 9 | 9 | * other request answers `not_found`, the same as a repository the crew member cannot see: other |
| 10 | 10 | * repositories (the crew member's own, the owner's private ones), the account, tokens, secrets, |
| 11 | * admin, MCP and the web pages. Allow-listed, so a route added tomorrow is closed to these tokens | |
| 12 | * until someone writes it in here. | |
| 11 | * admin, MCP (but `release_keeper` for a crew run on the forge's own repository) and the web pages. | |
| 12 | * Allow-listed, so a route added tomorrow is closed to these tokens until someone writes it in | |
| 13 | * here. | |
| 13 | 14 | * |
| 14 | 15 | * Inside its own repositories the routes that reach out of it are refused too: |
| 15 | 16 | * forking or copying it elsewhere, proposing to the parent, syncing from an |
| @@ -99,6 +100,21 @@ export function runRepos(app: App, auth: Auth): Repo[] | undefined { | ||
| 99 | 100 | .filter((r): r is Repo => r !== undefined); |
| 100 | 101 | } |
| 101 | 102 | |
| 103 | /** The one MCP tool a run token may call, and only on the forge's own repository (#15453). */ | |
| 104 | export const RUN_MCP_TOOL = "release_keeper"; | |
| 105 | ||
| 106 | /** | |
| 107 | * What `/mcp` answers a run token's message, after `runGate` let a crew run on the forge's own | |
| 108 | * repository through: undefined for a `tools/call` of `RUN_MCP_TOOL`, the gate's `not_found` for | |
| 109 | * any other method or tool. Undefined for every other credential. | |
| 110 | */ | |
| 111 | export function runMcpRefusal(auth: Auth, message: Record<string, unknown>): Response | undefined { | |
| 112 | if (auth.run === undefined) return undefined; | |
| 113 | const params = message["params"]; | |
| 114 | const name = typeof params === "object" && params !== null ? (params as Record<string, unknown>)["name"] : undefined; | |
| 115 | return message["method"] === "tools/call" && name === RUN_MCP_TOOL ? undefined : hidden(); | |
| 116 | } | |
| 117 | ||
| 102 | 118 | /** The refusal for this request, or undefined when it may proceed. */ |
| 103 | 119 | export function runGate( |
| 104 | 120 | app: App, |
| @@ -119,8 +135,12 @@ export function runGate( | ||
| 119 | 135 | if ((method === "GET" || method === "HEAD") && FORGE_READS.has(path)) return undefined; |
| 120 | 136 | // A crew run on the forge's own repository reads why releases stopped (#15449): the keeper's |
| 121 | 137 | // answer, which its handler still gives only to `mayRead`. An app preview's token never does. |
| 122 | if ((method === "GET" || method === "HEAD") && path === "/api/v1/keeper" && scope.app !== true && forgeRepoOf(app)?.id === repo.id) | |
| 138 | const crewOnForge = scope.app !== true && forgeRepoOf(app)?.id === repo.id; | |
| 139 | if ((method === "GET" || method === "HEAD") && path === "/api/v1/keeper" && crewOnForge) | |
| 123 | 140 | return undefined; |
| 141 | // The same answer over MCP (#15453): the door opens to the body, where `runMcpRefusal` lets | |
| 142 | // through one `tools/call` of `release_keeper` and nothing else. | |
| 143 | if (method === "POST" && path === "/mcp" && crewOnForge) return undefined; | |
| 124 | 144 | |
| 125 | 145 | for (const own of [repo, fork]) { |
| 126 | 146 | const api = under(path, "/api/v1/repos", own); |
test/keeper-crew-reads.test.ts +29
| @@ -27,6 +27,13 @@ describe("GET /api/v1/keeper with the crew's run token", () => { | ||
| 27 | 27 | let preview: string; |
| 28 | 28 | const get = (token?: string) => |
| 29 | 29 | fetch(`${servers.url}/api/v1/keeper`, token ? { headers: { authorization: `Bearer ${token}` } } : {}); |
| 30 | const mcp = (body: unknown, token?: string) => | |
| 31 | fetch(`${servers.url}/mcp`, { | |
| 32 | method: "POST", | |
| 33 | headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) }, | |
| 34 | body: JSON.stringify(body), | |
| 35 | }); | |
| 36 | const call = (name: string, id = 1) => ({ jsonrpc: "2.0", id, method: "tools/call", params: { name, arguments: {} } }); | |
| 30 | 37 | const until = new Date(Date.now() + 3_600_000).toISOString(); |
| 31 | 38 | |
| 32 | 39 | beforeAll(async () => { |
| @@ -73,4 +80,26 @@ describe("GET /api/v1/keeper with the crew's run token", () => { | ||
| 73 | 80 | test("a run on another repository and an app preview's token are not let through", async () => { |
| 74 | 81 | for (const token of [elsewhere, preview]) expect((await get(token)).status).toBe(404); |
| 75 | 82 | }); |
| 83 | ||
| 84 | test("over MCP, the crew's token gets the same body release_keeper as GET /api/v1/keeper", async () => { | |
| 85 | const res = await mcp(call("release_keeper"), crew); | |
| 86 | expect(res.status).toBe(200); | |
| 87 | const rpc: any = await res.json(); | |
| 88 | expect(rpc.result.isError).toBeUndefined(); | |
| 89 | const over: any = JSON.parse(rpc.result.content[0].text); | |
| 90 | const http: any = await (await get(crew)).json(); | |
| 91 | expect(over).toEqual(http); | |
| 92 | expect(over.heartbeat).toMatchObject({ outcome: "skipped" }); | |
| 93 | }); | |
| 94 | ||
| 95 | test("over MCP, the crew's token reaches no other tool or method", async () => { | |
| 96 | for (const body of [call("whoami"), call("read_file"), { jsonrpc: "2.0", id: 2, method: "tools/list", params: {} }, { jsonrpc: "2.0", id: 3, method: "initialize", params: {} }]) | |
| 97 | expect((await mcp(body, crew)).status).toBe(404); | |
| 98 | }); | |
| 99 | ||
| 100 | test("over MCP, anonymous, a run elsewhere and an app preview stay refused", async () => { | |
| 101 | const anon = await mcp(call("release_keeper")); | |
| 102 | expect(anon.status).toBe(401); | |
| 103 | for (const token of [elsewhere, preview]) expect((await mcp(call("release_keeper"), token)).status).toBe(404); | |
| 104 | }); | |
| 76 | 105 | }); |
new above
offline