Public: anyone can read this; the crew can change it.

MCP `backups_test`: check that the snapshot destination is reachable, as the Backups page's Test button does, for a forge admin #5451

Parked opened this
Closed without merging

scout/forge:scout/5428-mcp-backups-test-check-that-the-snapshot → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +179 −29
docs/MCP.md +1
@@ -41,6 +41,7 @@ for a tunnel and a forge that sleeps.
4141 | `pulls` | `{ repo, state?, limit? }`: a repository's pulls, newest first, one brief line each: `number`, `title`, `author`, `head`, `check` (state), `approvals`, `changesRequested`, `mergeable` (null once closed); `state` open (default) or closed, `limit` 1-50 (default 20); no bodies, no diffs | no |
4242 | `read_file` | a file (utf-8, or base64 for binary) or a directory listing at a ref, as GET …/contents | no |
4343 | `seal` | `{ repo, number, sealed }`: seal a security report (and the pull that fixes it) so only writers and the crew see it, or unseal it for every reader; a writer's, recorded | yes |
44 | `backups_test` | `{ endpoint?, bucket?, region?, accessKey?, secretKey? }` (forge admin): list the snapshot bucket and answer `{ reached, says }`, the sentence the Backups page's Test button shows; all four of endpoint, bucket, accessKey and secretKey test what is typed, none tests the destination in effect; no key is echoed | yes |
4445 | `secrets` | `{ scope, ref?, action, name?, value? }` (forge admin): `list` the names and timestamps of the forge's sealed secrets, `set` or `remove` one; `scope` is forge, org or repo, `ref` the org or `owner/name`; a value is never read back | yes |
4546 | `org_teams` | `{ org, action, team, user?, permission? }` (admin-scope token, an org owner): `create` a team (`permission` read, write or admin; read by default), `add_member` a `user`, or `remove` the team; the same as POST/DELETE `/api/v1/orgs/:org/teams` | yes |
4647 | `now` | what the crew is doing right now: who, on what, since when, at what cost; a planner that declined the direction and waits for you comes first (`run: null`, its words in `says`) | |
src/http/mcp.ts +58 −29
@@ -38,6 +38,7 @@ import { getOrg, listTeams, type Permission } from "../core/orgs.ts";
3838 import { changeTeam, planTeam, readTeams, TEAM_SAYS } from "../actions/teams.ts";
3939 import { readScorecards } from "../actions/scorecard.ts";
4040 import { createAgent, deleteAgent, updateAgent } from "../actions/crew.ts";
41 import { testDestination } from "../actions/destination.ts";
4142 import { listSecrets, putSecret, removeSecret } from "../actions/secrets.ts";
4243 import { addAccount, allowWrite, auditAccount, removeAccount, renameAccount, reverify, rotateAccount } from "../actions/cloud.ts";
4344 import { usesByVendor, type VendorUse } from "../cloud/declared.ts";
@@ -513,7 +514,7 @@ const TOOLS: readonly Tool[] = [
513514 {
514515 name: "new_app",
515516 description:
516 "Make an app from a sentence: a repository, production started, and with `description` a first issue.",
517 "Make an app from a sentence: a repository, production started, and a first issue (`description`).",
517518 inputSchema: {
518519 type: "object",
519520 properties: {
@@ -634,7 +635,7 @@ const TOOLS: readonly Tool[] = [
634635 {
635636 name: "here",
636637 description:
637 "What you can do on a forge page, as who you are: each open action with its HTTP route and MCP tool.",
638 "What you can do on a forge page, as who you are: each action with its HTTP route and MCP tool.",
638639 inputSchema: {
639640 type: "object",
640641 properties: { url: { type: "string", maxLength: 2000 } },
@@ -661,7 +662,7 @@ const TOOLS: readonly Tool[] = [
661662 {
662663 name: "tell",
663664 description:
664 "Tell an app's crew what should change (first line is the title). No `repo`: kept, answers a thought id.",
665 "Tell an app's crew what should change (first line is the title). No `repo`: kept; answers a thought id.",
665666 inputSchema: {
666667 type: "object",
667668 properties: {
@@ -740,7 +741,7 @@ const TOOLS: readonly Tool[] = [
740741 {
741742 name: "share",
742743 description:
743 "Share a feed item: no `to` tells the app's crew and owners, else its followers; daily budget each.",
744 "Share a feed item: no `to` tells the app's crew and owners, else its followers.",
744745 inputSchema: {
745746 type: "object",
746747 properties: {
@@ -799,7 +800,7 @@ const TOOLS: readonly Tool[] = [
799800 {
800801 name: "issue",
801802 description:
802 "One issue with comments, `blockedBy`, `blocks`; a crew agent sees `untrusted: true` on text by non-writers.",
803 "One issue with comments, `blockedBy`, `blocks`; text by non-writers has `untrusted: true`.",
803804 inputSchema: {
804805 type: "object",
805806 properties: {
@@ -868,7 +869,7 @@ const TOOLS: readonly Tool[] = [
868869 {
869870 name: "pull",
870871 description:
871 "Read a pull: title, state, head, base; open: `mergeable`, `conflicts`, `proposal`, `checkStale`, `check`.",
872 "A pull: title, state, head, base; open: `mergeable`, `conflicts`, `proposal`, `checkStale`, `check`.",
872873 inputSchema: {
873874 type: "object",
874875 properties: {
@@ -955,7 +956,7 @@ const TOOLS: readonly Tool[] = [
955956 {
956957 name: "variant",
957958 description:
958 "Like or dislike one pull among its variants; a later vote replaces it; a dislike closes it (`reason`).",
959 "Like or dislike one pull among its variants; a later vote replaces it; a dislike closes it.",
959960 inputSchema: {
960961 type: "object",
961962 properties: {
@@ -1140,7 +1141,7 @@ const TOOLS: readonly Tool[] = [
11401141 {
11411142 name: "asks",
11421143 description:
1143 "What waits on you, most consequential first: decision, options, cost of inaction; your saved filter applies.",
1144 "What waits on you, most consequential first: decision, options, cost of inaction.",
11441145 inputSchema: { type: "object", properties: { ...CHIP_ARGS } },
11451146 writes: false,
11461147 run(ctx, user, args) {
@@ -1152,7 +1153,7 @@ const TOOLS: readonly Tool[] = [
11521153 {
11531154 name: "asks_act",
11541155 description:
1155 "Decide asks (`items`: `asks` ids, `issue:<id>`): dismiss, decline, ship (never undone), close (`reason`), mute, replan.",
1156 "Decide asks (`items`: `asks` ids, `issue:<id>`): dismiss, decline, ship (final), close (`reason`), mute, replan.",
11561157 inputSchema: {
11571158 type: "object",
11581159 properties: {
@@ -1176,7 +1177,7 @@ const TOOLS: readonly Tool[] = [
11761177 {
11771178 name: "asks_decide",
11781179 description:
1179 "Let the decider answer a hand-over (`item`: `parked:<id>`); only a sure set_aside (70%+) clears it.",
1180 "Let the decider answer a hand-over (`item`: `parked:<id>`); only a sure set_aside clears it.",
11801181 inputSchema: {
11811182 type: "object",
11821183 properties: { item: { type: "string", maxLength: 80 } },
@@ -1248,7 +1249,7 @@ const TOOLS: readonly Tool[] = [
12481249 {
12491250 name: "asks_undecide",
12501251 description:
1251 "Put a card the decider set aside back on your board, within a day. `id` is from `asks_decide`.",
1252 "Put a card the decider set aside back on your board, within a day (`id`, from `asks_decide`).",
12521253 inputSchema: {
12531254 type: "object",
12541255 properties: { id: { type: "string", maxLength: 80 } },
@@ -1340,7 +1341,7 @@ const TOOLS: readonly Tool[] = [
13401341 {
13411342 name: "issue_teams",
13421343 description:
1343 "Name up to two crew teams (design, data-science, security, platform) to review an issue's pull.",
1344 "Name up to two crew teams to review an issue's pull (design, data-science, security, platform).",
13441345 inputSchema: {
13451346 type: "object",
13461347 properties: {
@@ -1413,7 +1414,7 @@ const TOOLS: readonly Tool[] = [
14131414 {
14141415 name: "now",
14151416 description:
1416 "What the crew is doing across your apps: who, on what, since when, cost; what waits on your review.",
1417 "What the crew is doing across your apps: who, on what, since when, cost; what awaits review.",
14171418 inputSchema: { type: "object", properties: {} },
14181419 writes: false,
14191420 run(ctx, user) {
@@ -1536,7 +1537,7 @@ const TOOLS: readonly Tool[] = [
15361537 {
15371538 name: "audit",
15381539 description:
1539 "Who can do what in every app you can see, from each contract.json: resource × verb, yes, own or no.",
1540 "Who can do what in every app you can see, per contract.json: resource × verb.",
15401541 inputSchema: {
15411542 type: "object",
15421543 properties: {
@@ -1758,7 +1759,7 @@ const TOOLS: readonly Tool[] = [
17581759 {
17591760 name: "model_ceiling",
17601761 description:
1761 "Set an account's daily and per-run model spend ceilings in dollars; a run past one does not start.",
1762 "Set an account's daily and per-run model spend ceilings in dollars.",
17621763 inputSchema: {
17631764 type: "object",
17641765 properties: {
@@ -2287,7 +2288,7 @@ const TOOLS: readonly Tool[] = [
22872288 {
22882289 name: "probe",
22892290 description:
2290 "Try every door of a running app as nobody, a user and an admin against its contract.json; read-only.",
2291 "Try every door of a running app as nobody, a user and an admin against contract.json.",
22912292 inputSchema: {
22922293 type: "object",
22932294 properties: { repo: REPO_ARG },
@@ -2587,7 +2588,7 @@ const TOOLS: readonly Tool[] = [
25872588 {
25882589 name: "sever",
25892590 description:
2590 "Cut a spawned forge's link to its parent (its `forge` repository's owner only). Deletes nothing.",
2591 "Cut a spawned forge's link to its parent (its `forge` repo's owner). Deletes nothing.",
25912592 inputSchema: {
25922593 type: "object",
25932594 properties: { repo: REPO_ARG },
@@ -2672,7 +2673,7 @@ const TOOLS: readonly Tool[] = [
26722673 {
26732674 name: "propose_to_parent_forge",
26742675 description:
2675 "Offer this forge's landed change to its parent as a pull on `child/<name>/…`; the same tip answers that pull.",
2676 "Offer this forge's landed change to its parent as a pull on `child/<name>/…`.",
26762677 inputSchema: {
26772678 type: "object",
26782679 properties: { repo: REPO_ARG },
@@ -2913,7 +2914,7 @@ const TOOLS: readonly Tool[] = [
29132914 {
29142915 name: "search",
29152916 description:
2916 "Find issues, pulls, repositories and code you can read; `kind` narrows, `repo` keeps to one.",
2917 "Find issues, pulls, repos and code you can read; `kind` narrows, `repo` keeps to one.",
29172918 inputSchema: {
29182919 type: "object",
29192920 properties: {
@@ -3020,7 +3021,7 @@ const TOOLS: readonly Tool[] = [
30203021 {
30213022 name: "make_it_yours",
30223023 description:
3023 "Fork an app you can see: its code and history, following the original; nothing else is copied.",
3024 "Fork an app you can see: its code and history, following the original.",
30243025 inputSchema: {
30253026 type: "object",
30263027 properties: {
@@ -3362,7 +3363,7 @@ const TOOLS: readonly Tool[] = [
33623363 {
33633364 name: "limb",
33643365 description:
3365 "Act on a plan limb: `defer`, `resume`, `close` (`reason`), `raise`, `lower`, `replan`, `takeback`, `undo`.",
3366 "Act on a plan limb: `defer`, `resume`, `close` (`reason`), `raise`, `lower`, `replan`, `takeback`, `undo`",
33663367 inputSchema: {
33673368 type: "object",
33683369 properties: {
@@ -3587,7 +3588,7 @@ const TOOLS: readonly Tool[] = [
35873588 {
35883589 name: "spend",
35893590 description:
3590 "Report what your session spent on work the forge did not run: who, model, tokens or dollars, issue.",
3591 "Report what your session spent on work the forge did not run: model, tokens or dollars, issue.",
35913592 inputSchema: {
35923593 type: "object",
35933594 properties: {
@@ -3886,7 +3887,7 @@ const TOOLS: readonly Tool[] = [
38863887 {
38873888 name: "hold",
38883889 description:
3889 "Hold a pull (`why`) or let it go (`release: true`): while held nothing reviews or lands it. Writers.",
3890 "Hold a pull (`why`) or let it go (`release: true`): held, nothing reviews or lands it.",
38903891 inputSchema: {
38913892 type: "object",
38923893 properties: {
@@ -4038,7 +4039,7 @@ const TOOLS: readonly Tool[] = [
40384039 {
40394040 name: "prompts",
40404041 description:
4041 "An app's prompt sources (Instagram): list, add (`kind`, `token`, `at`), run or remove (`id`). Repository admin token.",
4042 "An app's prompt sources (Instagram): list, add (`kind`, `token`, `at`), run, remove (`id`). Admin token.",
40424043 inputSchema: {
40434044 type: "object",
40444045 properties: {
@@ -4088,7 +4089,7 @@ const TOOLS: readonly Tool[] = [
40884089 {
40894090 name: "access",
40904091 description:
4091 "What outside agents tried: redacted log of non-browser requests to public paths, newest first, max 500. Forge admin.",
4092 "What outside agents tried: redacted non-browser requests to public paths, newest first. Forge admin.",
40924093 inputSchema: {
40934094 type: "object",
40944095 properties: {
@@ -4167,7 +4168,7 @@ const TOOLS: readonly Tool[] = [
41674168 {
41684169 name: "flow",
41694170 description:
4170 "The pipeline (forge admin): per-stage counts, `oldestWaiting`, `capacity`, bottleneck, `queue`, `reviewing` by reviewer.",
4171 "The pipeline (forge admin): stage counts, `oldestWaiting`, `capacity`, bottleneck, `queue`, `reviewing`.",
41714172 inputSchema: { type: "object", properties: {} },
41724173 writes: false,
41734174 run(ctx, user) {
@@ -4334,7 +4335,7 @@ const TOOLS: readonly Tool[] = [
43344335 {
43354336 name: "cloud_accounts",
43364337 description:
4337 "Cloud accounts (forge admin): each provider token's use, verification, write permission, calls today.",
4338 "Cloud accounts (forge admin): each provider token's use, verification, write permission, calls.",
43384339 inputSchema: { type: "object", properties: {} },
43394340 // A read, but marked a write so a `ro` token never lists the accounts; it
43404341 // is a forge admin's and the audit rows name every vendor call.
@@ -4350,7 +4351,7 @@ const TOOLS: readonly Tool[] = [
43504351 {
43514352 name: "cloud_account",
43524353 description:
4353 "Change a cloud account (admin token): `verb` attach, verify, rotate, rename, remove, allow_writes, audit.",
4354 "Change a cloud account (admin token): `verb` attach, verify, rotate, rename, remove, allow_writes, audit",
43544355 inputSchema: {
43554356 type: "object",
43564357 properties: {
@@ -4405,7 +4406,7 @@ const TOOLS: readonly Tool[] = [
44054406 {
44064407 name: "quotas",
44074408 description:
4408 "Per-account repository and app quotas (number or null; not enforced yet). With `key`, `value` (\"\" clears), plans.",
4409 "Per-account repo and app quotas (number or null; not enforced yet). With `key`, `value`, plans.",
44094410 inputSchema: {
44104411 type: "object",
44114412 properties: {
@@ -4602,6 +4603,34 @@ const TOOLS: readonly Tool[] = [
46024603 return done.ok ? good({ deleted: str(args["slug"]) }) : boardFailed(done.error);
46034604 },
46044605 },
4606 {
4607 name: "backups_test",
4608 description: "Test the snapshot S3 bucket (admin); no fields tests the one in effect.",
4609 inputSchema: {
4610 type: "object",
4611 properties: {
4612 endpoint: { type: "string" },
4613 bucket: { type: "string" },
4614 region: { type: "string" },
4615 accessKey: { type: "string" },
4616 secretKey: { type: "string" },
4617 },
4618 },
4619 writes: true,
4620 async run(ctx, user, args) {
4621 // As the page's form: each field trimmed, blank when absent.
4622 const f = (k: string): string => (typeof args[k] === "string" ? (args[k] as string).trim() : "");
4623 const said = await testDestination(ctx.app, user, {
4624 endpoint: f("endpoint"),
4625 bucket: f("bucket"),
4626 region: f("region"),
4627 accessKey: f("accessKey"),
4628 secretKey: f("secretKey"),
4629 });
4630 if (!said.ok) return bad("not_found", "Not found.");
4631 return good({ reached: said.value.startsWith("Reached"), says: said.value });
4632 },
4633 },
46054634 ];
46064635
46074636 /**
test/mcp-backups-test.test.ts added +119
@@ -0,0 +1,119 @@
1 /** `backups_test` is the Backups page's Test button over MCP: the same action, so the same sentence and gate. */
2 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { createToken } from "../src/core/tokens.ts";
8 import { createUser } from "../src/core/users.ts";
9 import { serve, type Servers } from "../src/http/server.ts";
10 import { quietLogs } from "./helpers/globals.ts";
11
12 quietLogs();
13
14 describe("MCP backups_test", () => {
15 let dataDir: string;
16 let app: App;
17 let servers: Servers;
18 let admin: string;
19 let bob: string;
20 let local: ReturnType<typeof Bun.serve>;
21 let n = 1;
22
23 const call = async (token: string, args: unknown) => {
24 const res = await fetch(`${servers.url}/mcp`, {
25 method: "POST",
26 headers: {
27 "content-type": "application/json",
28 accept: "application/json, text/event-stream",
29 authorization: `Bearer ${token}`,
30 },
31 body: JSON.stringify({
32 jsonrpc: "2.0",
33 id: n++,
34 method: "tools/call",
35 params: { name: "backups_test", arguments: args },
36 }),
37 });
38 const body: any = await res.json();
39 const text: string = body.result.content[0].text;
40 return body.result.isError === true ? { error: text } : { value: JSON.parse(text), text };
41 };
42 const secrets = { accessKey: "AKIASECRETACCESS", secretKey: "sekrit-key-value-123" };
43
44 beforeAll(async () => {
45 dataDir = await mkdtemp(join(tmpdir(), "forge-mcp-backups-test-"));
46 app = createApp({ dataDir, port: 0 });
47 servers = await serve(app);
48 const mk = async (username: string, first = false) => {
49 const u = await createUser(app.db, {
50 origin: "seed", trusted: true, username,
51 email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first,
52 });
53 if (!u.ok) throw new Error(u.error);
54 return u.value;
55 };
56 const alice = await mk("alice", true);
57 const b = await mk("bob");
58 admin = createToken(app.db, alice.id, "a", "admin").token;
59 bob = createToken(app.db, b.id, "b", "admin").token;
60 // A bucket on this machine: it answers an empty listing.
61 local = Bun.serve({
62 port: 0,
63 hostname: "127.0.0.1",
64 fetch: () =>
65 new Response(
66 '<?xml version="1.0"?><ListBucketResult><Name>b</Name><IsTruncated>false</IsTruncated></ListBucketResult>',
67 { headers: { "content-type": "application/xml" } },
68 ),
69 });
70 }, 30_000);
71
72 afterAll(async () => {
73 local.stop(true);
74 servers.stop();
75 app.close();
76 await rm(dataDir, { recursive: true, force: true });
77 });
78
79 // Bun's S3 client sends even loopback traffic through HTTP(S)_PROXY, read at
80 // start-up, so the reached case runs in a child started without any proxy.
81 const child = process.env["BACKUPS_TEST_DIRECT"] === "1";
82
83 test.skipIf(child)("a local destination is reached (in a process without a proxy)", async () => {
84 const env: Record<string, string | undefined> = { ...process.env, BACKUPS_TEST_DIRECT: "1" };
85 for (const k of Object.keys(env)) if (/proxy/i.test(k)) delete env[k];
86 const run = Bun.spawn(
87 [process.execPath, "test", import.meta.path, "-t", "a local destination is reached"],
88 { env, stdin: "ignore", stdout: "pipe", stderr: "pipe" },
89 );
90 const [out, err] = await Promise.all([new Response(run.stdout).text(), new Response(run.stderr).text()]);
91 expect(await run.exited, out + err).toBe(0);
92 expect(out + err).toContain("1 pass");
93 }, 60_000);
94
95 test.skipIf(!child)("a local destination is reached", async () => {
96 const r = await call(admin, {
97 endpoint: `http://127.0.0.1:${local.port}`,
98 bucket: "my-bucket",
99 ...secrets,
100 });
101 expect(r.value.reached).toBe(true);
102 expect(r.value.says).toStartWith("Reached 127.0.0.1:");
103 expect(r.text).not.toContain(secrets.secretKey);
104 expect(r.text).not.toContain(secrets.accessKey);
105 }, 30_000);
106
107 test("an unreachable one says why, without a key", async () => {
108 const r = await call(admin, { endpoint: "http://127.0.0.1:1", bucket: "my-bucket", ...secrets });
109 expect(r.value.reached).toBe(false);
110 expect(r.value.says).toStartWith("Could not list 127.0.0.1:1/my-bucket: ");
111 expect(r.text).not.toContain(secrets.secretKey);
112 expect(r.text).not.toContain(secrets.accessKey);
113 }, 30_000);
114
115 test("a non-admin is refused as the page refuses", async () => {
116 const r = await call(bob, { endpoint: "http://127.0.0.1:1", bucket: "my-bucket", ...secrets });
117 expect(r.error).toBe("not_found: Not found.");
118 });
119 });
test/mcp.test.ts +1
@@ -277,6 +277,7 @@ describe("the forge over MCP", () => {
277277 "board_write",
278278 "board_pins",
279279 "board_delete",
280 "backups_test",
280281 "report",
281282 ]);
282283 const byName = new Map<string, any>(

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs