Public: anyone can read this; the crew can change it.
The offer door over MCP, built on #12402 once it lands: a token-free offer that says the REST door's words #12829
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12705-the-offer-door-over-mcp-built-on-12402-o → main 6 commits fork 2 threads · 2 unresolved
2 files
changed +98
−1
src/web/standards.ts +2 −1
| @@ -509,7 +509,8 @@ function renderLlmsTxt(ctx: Ctx, o: string, tell: string | undefined, running: s | ||
| 509 | 509 | "", |
| 510 | 510 | "## Offer a change", |
| 511 | 511 | "", |
| 512 | `- Account only. Fork (MCP fork); source: ${o}/{owner}/{name}/archive/{ref}.tar.gz; send: MCP open_pull with patch, or POST ${o}/api/v1/repos/{owner}/{name}/pulls with {"title", "body", "base", "head", "headRepo": "you/name"}.`, | |
| 512 | `- No account: MCP offer {repo, title, patch}, or POST ${o}/api/v1/repos/{owner}/{name}/offers {title, patch}.`, | |
| 513 | `- Account: fork (MCP fork); source: ${o}/{owner}/{name}/archive/{ref}.tar.gz; send: MCP open_pull with patch, or POST ${o}/api/v1/repos/{owner}/{name}/pulls with {"title", "body", "base", "head", "headRepo": "you/name"}.`, | |
| 513 | 514 | "", |
| 514 | 515 | "## Use it from your harness", |
| 515 | 516 | "", |
test/offer-mcp.test.ts added +96
| @@ -0,0 +1,96 @@ | ||
| 1 | /** The offer door over MCP (#12705): `offer` with no token says the REST door's words. */ | |
| 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 { editFiles } from "../src/actions/contents.ts"; | |
| 8 | import { createRepo } from "../src/actions/repos.ts"; | |
| 9 | import { OFFER_RECEIVED, OFFER_WORDS } from "../src/actions/offer.ts"; | |
| 10 | import { getRepo } from "../src/core/repos.ts"; | |
| 11 | import { createUser } from "../src/core/users.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | ||
| 14 | const PATCH = `diff --git a/hello.txt b/hello.txt | |
| 15 | --- a/hello.txt | |
| 16 | +++ b/hello.txt | |
| 17 | @@ -1,2 +1,2 @@ | |
| 18 | hello | |
| 19 | -world | |
| 20 | +there | |
| 21 | `; | |
| 22 | const STALE = PATCH.replace("-world", "-nothing like it"); | |
| 23 | ||
| 24 | describe("offer over MCP", () => { | |
| 25 | let dataDir: string; | |
| 26 | let app: App; | |
| 27 | let servers: Servers; | |
| 28 | let n = 1; | |
| 29 | ||
| 30 | const call = async (name: string, args: unknown, pad = 0) => { | |
| 31 | const res = await fetch(`${servers.url}/mcp`, { | |
| 32 | method: "POST", | |
| 33 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "x-forwarded-for": `10.2.0.${n++}` }, | |
| 34 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args }, pad: "x".repeat(pad) }), | |
| 35 | }); | |
| 36 | return { status: res.status, body: (await res.json()) as any }; | |
| 37 | }; | |
| 38 | const said = (r: { body: any }): string => r.body.result.content[0].text; | |
| 39 | ||
| 40 | beforeAll(async () => { | |
| 41 | dataDir = await mkdtemp(join(tmpdir(), "forge-offer-mcp-")); | |
| 42 | app = createApp({ dataDir, port: 0 }); | |
| 43 | servers = await serve(app); | |
| 44 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 45 | if (!a.ok) throw new Error(a.error); | |
| 46 | for (const [name, visibility] of [["game", "public"], ["secret", "private"]] as const) { | |
| 47 | const made = await createRepo(app, a.value, { name, visibility }); | |
| 48 | if (!made.ok) throw new Error(String(made.error)); | |
| 49 | const seeded = await editFiles(app, a.value, getRepo(app.db, "alice", name)!, { files: [{ path: "hello.txt", content: "hello\nworld\n" }], message: "first" }); | |
| 50 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 51 | } | |
| 52 | }, 30_000); | |
| 53 | ||
| 54 | afterAll(async () => { | |
| 55 | servers.stop(); | |
| 56 | app.close(); | |
| 57 | await rm(dataDir, { recursive: true, force: true }); | |
| 58 | }); | |
| 59 | ||
| 60 | test("a patch with no token becomes a pull, in the REST door's words", async () => { | |
| 61 | const r = await call("offer", { repo: "alice/game", title: "Say there", patch: PATCH }); | |
| 62 | expect(r.body.result.isError).toBeUndefined(); | |
| 63 | const got = JSON.parse(said(r)); | |
| 64 | expect(got.message).toBe(OFFER_RECEIVED); | |
| 65 | expect(got.state).toBe("open"); | |
| 66 | expect(got.url).toContain("/alice/game/pulls/"); | |
| 67 | }); | |
| 68 | ||
| 69 | test("a patch that does not apply is refused with the REST door's reason", async () => { | |
| 70 | const r = await call("offer", { repo: "alice/game", title: "Stale", patch: STALE }); | |
| 71 | expect(r.body.result.isError).toBe(true); | |
| 72 | expect(said(r)).toContain(`patch_does_not_apply: ${OFFER_WORDS.patch_does_not_apply}`); | |
| 73 | }); | |
| 74 | ||
| 75 | test("a private or missing repository is not_found", async () => { | |
| 76 | for (const repo of ["alice/secret", "alice/none", "nobody"]) { | |
| 77 | const r = await call("offer", { repo, title: "x", patch: PATCH }); | |
| 78 | expect(r.body.result.isError).toBe(true); | |
| 79 | expect(said(r)).toStartWith("not_found:"); | |
| 80 | } | |
| 81 | }); | |
| 82 | ||
| 83 | test("only a call to offer may be larger than a stranger's usual limit", async () => { | |
| 84 | const big = await call("offer", { repo: "alice/game", title: "Big", patch: STALE }, 100 * 1024); | |
| 85 | expect(big.status).toBe(200); | |
| 86 | const other = await call("report", { repo: "alice/game", title: "Big" }, 100 * 1024); | |
| 87 | expect(other.status).toBe(413); | |
| 88 | const lying = await call("explore", {}, 100 * 1024); | |
| 89 | expect(lying.status).toBe(413); | |
| 90 | }); | |
| 91 | ||
| 92 | test("it is listed with the token-free tools", async () => { | |
| 93 | const res = await fetch(`${servers.url}/llms.txt`); | |
| 94 | expect(await res.text()).toContain("- offer: "); | |
| 95 | }); | |
| 96 | }); |
new above
offline