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

An MCP tool call with an argument of the wrong type or an unknown name is refused naming the argument, not answered as if it were absent #15377

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15362-an-mcp-tool-call-with-an-argument-of-the → main 0 commits fork 4 threads · 4 unresolved

  • Merged. scout/15362-an-mcp-tool-call-with-an-argument-of-the was merged into main as 0c1edc6.

Review

Sign in to review this change.
77 files changed +426 −125
docs/MCP.md +16
@@ -223,6 +223,22 @@ reached this way only by a person who is an admin.
223223
224224 ## Arguments, in full
225225
226 Every call is held to the tool's own `inputSchema` before anything is held, asked, recorded or
227 run, a stranger's `explore` and `search` as well (`badArgument` in `src/http/mcp/shared.ts`). The
228 first argument that does not fit is refused naming it, with what was expected and one corrected
229 example; nothing runs:
230
231 - a wrong type: `invalid: argument "limit" is "many"; expected integer from 1 to 100. Example: {"limit": 1}`
232 - outside `enum`: `invalid: argument "kind" is "bogus"; expected one of "all", "issues", "repos", "code". Example: {"kind": "all"}`
233 - outside `minimum`/`maximum`: `invalid: argument "limit" is 0; expected integer from 1 to 100. Example: {"limit": 1}`
234 - over `maxLength`: `invalid: argument "q" is 201 characters long; expected string of at most 200 characters. Example: {"q": "text"}` (a long value is measured, never echoed; one named like a secret or token is never shown)
235 - a name the tool does not take: `invalid: unknown argument "bogus": this tool takes q, kind, repo, … Example: {"q": "text"}`
236 - a `required` one left out: `invalid: argument "repo" is missing; expected string. Example: {"repo": "text"}`
237
238 Each is followed by the tool's usual `Next:` step. Only the top level is read; nested shapes
239 (items of a list, keys of an object) are the tool's own to refuse, and `spawn`, whose schema says
240 `additionalProperties: true`, takes extra keys.
241
226242 `tools/list` keeps every argument description to 60 bytes (`test/mcp-size.test.ts`
227243 enforces it); `dryRun` reads `false to apply` on every tool that takes it. The
228244 longer sentences:
src/http/mcp.ts +20 −1
@@ -47,7 +47,7 @@ import { CONTRIBUTE_TOKEN_HINT, CONTRIBUTE_TOKEN_WORDS, mintContributeToken } fr
4747 import { BODY_MAX, REQUEST_MAX, TITLE_MAX } from "../core/reports.ts";
4848 import { adminRefusal, everydayOf } from "../core/everyday.ts";
4949 import { claimDone, completeWrite, dropWrite, recordWrite } from "../core/conversation_writes.ts";
50 import { type Args, alreadyDone, notAdminTool, listable, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, destroysTo, readThrough, type ToolShape } from "./mcp/shared.ts";
50 import { type Args, badArgument, alreadyDone, notAdminTool, listable, visible, plansOnly, str, REPO_ARG, lean, fenceAnswer, heldWrite, askedFirst, destroysTo, readThrough, type ToolShape } from "./mcp/shared.ts";
5151 import { CONVERSATION_BRIEF } from "../crew/conversation_brief.ts";
5252 import { readWidget as readKept, recordCard, recordWidget, shownLine } from "../core/talk_voice.ts";
5353 import { stepOf } from "../core/talk_steps.ts";
@@ -290,6 +290,21 @@ function rpcOne(
290290 ctx.auth.through === undefined || tool === undefined ? undefined : (tool.refusedToAgent?.(args) ?? destroysTo(user, tool, args));
291291 if (never !== undefined)
292292 return reply({ content: [{ type: "text", text: `forbidden: ${never}` }], isError: true, hint: hintForCode("forbidden") });
293 // Every argument is held to the tool's own schema, a read as a write, before anything is
294 // held, asked, recorded or run: a call that does not fit is refused by name and never runs.
295 // Only a tool this caller may see says so, and a write a read-only token may not make is
296 // still the scope floor's to refuse below.
297 const shapeRead =
298 tool !== undefined &&
299 visible(tool, ctx, user) &&
300 !(tool.writes && !plansOnly(tool, args) && !scopeAllows(ctx.auth.scope ?? "ro", "rw"));
301 const wrongArg = shapeRead ? badArgument(tool.inputSchema, args) : undefined;
302 if (tool !== undefined && wrongArg !== undefined)
303 return reply({
304 content: [{ type: "text", text: `invalid: ${withNextStep(tool, "invalid", wrongArg)}` }],
305 isError: true,
306 hint: hintForCode("invalid"),
307 });
293308 // A write the tool would refuse this person anyway is answered as refused now, in its own
294309 // words, and never held for a yes that could only fail.
295310 const askable =
@@ -477,6 +492,10 @@ async function readAnswer(ctx: Ctx, id: unknown, name: string, args: Args): Prom
477492 id,
478493 result: { content: [{ type: "text", text: t }], ...(isError ? { isError, hint: hintOfText(t) } : {}), ...extra },
479494 });
495 // A stranger's arguments are held to the same schema as a signed-in caller's.
496 const schema = TOOLS.find((t) => t.name === name)?.inputSchema;
497 const wrongArg = schema === undefined ? undefined : badArgument(schema, args);
498 if (wrongArg !== undefined) return text(`invalid: ${wrongArg}`, true);
480499 let held: ReturnType<typeof strangerCodeSearch> | undefined;
481500 if (name === "search" && typeof args["q"] === "string") {
482501 const kind = searchKind(typeof args["kind"] === "string" ? args["kind"] : null);
src/http/mcp/shared.ts +113
@@ -518,3 +518,116 @@ export function boardFailed(e: BoardError): Answer {
518518 */
519519 export const byName = (a: { readonly name: string }, b: { readonly name: string }): number =>
520520 a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
521
522 type Schema = Record<string, unknown>;
outdated

This doc comment documents badArgument but sits above type Schema. It also says enum and range are not read here, which contradicts box 1. Read them (enum, minimum, maximum, maxLength) in the loop and drop this caveat. Then remove the now-unreachable per-tool checks.

523
524 const typeOf = (v: unknown): string =>
525 v === null ? "null" : Array.isArray(v) ? "array" : Number.isInteger(v) ? "integer" : typeof v;
526
527 const accepts = (t: string, v: unknown): boolean => {
528 const have = typeOf(v);
529 return t === have || (t === "number" && have === "integer");
530 };
531
532 /** Arguments whose value is never written back: a refusal names them and says no more. */
533 const SECRET_NAME = /secret|token|password|passphrase/i;
534
535 /**
536 * The value as the refusal shows it: an over-long string by its length, never its text, and any
537 * other value cut to 40 characters.
538 */
539 const shown = (name: string, sch: Schema, v: unknown): string => {
540 if (SECRET_NAME.test(name)) return "not accepted";
541 const max = sch["maxLength"];
542 if (typeof v === "string" && typeof max === "number" && [...v].length > max) return `${[...v].length} characters long`;
543 const s = JSON.stringify(v) ?? String(v);
544 return s.length > 40 ? `${s.slice(0, 40)}…` : s;
545 };
546
547 function example(name: string, s: Schema): string {
548 const en = s["enum"];
549 if (Array.isArray(en) && en.length > 0) return `{"${name}": ${JSON.stringify(en[0])}}`;
550 const t = [s["type"]].flat()[0];
551 const min = typeof s["minimum"] === "number" ? s["minimum"] : 1;
552 const sample =
553 t === "integer" || t === "number"
554 ? min
555 : t === "boolean"
556 ? true
557 : t === "array"
558 ? []
559 : t === "object"
560 ? {}
561 : "text";
562 return `{"${name}": ${JSON.stringify(sample)}}`;
563 }
564
565 /** A value of the right type the schema still refuses: not in `enum`, out of range, too long. */
566 function outside(s: Schema, v: unknown): boolean {
567 const en = s["enum"];
568 if (Array.isArray(en) && !en.some((e) => e === v)) return true;
569 if (typeof v === "number") {
570 const lo = s["minimum"];
571 const hi = s["maximum"];
572 if (typeof lo === "number" && v < lo) return true;
573 if (typeof hi === "number" && v > hi) return true;
574 }
575 const max = s["maxLength"];
576 return typeof v === "string" && typeof max === "number" && [...v].length > max;
577 }
578
579 function expected(s: Schema): string {
580 const en = s["enum"];
581 if (Array.isArray(en)) return `one of ${en.map((e) => JSON.stringify(e)).join(", ")}`;
582 const t = [s["type"]].flat().join(" or ");
583 const lo = s["minimum"];
584 const hi = s["maximum"];
585 const range =
586 typeof lo === "number" && typeof hi === "number"
587 ? ` from ${lo} to ${hi}`
588 : typeof lo === "number"
589 ? ` of at least ${lo}`
590 : typeof hi === "number"
591 ? ` of at most ${hi}`
592 : "";
593 const max = s["maxLength"];
594 const long = typeof max === "number" ? ` of at most ${max} characters` : "";
595 return `${t === "" ? "a value" : t}${range}${long}`;
596 }
597
598 /**
599 * One check for every tool, from the tool's own `inputSchema`, before anything runs: an argument
600 * that is not in `properties`, has the wrong JSON type, is outside its `enum`, below `minimum`,
601 * above `maximum` or longer than `maxLength` is refused by name, with what was expected and one
602 * corrected example, instead of being dropped as if absent or answered in the tool's own words. A
603 * schema that says `additionalProperties: true` stays open to extra keys. Only the top level is
604 * read; nested shapes are the tool's own. Returns the refusal's text, or undefined when the call
605 * fits.
606 */
607 export function badArgument(schema: Record<string, unknown>, args: Args): string | undefined {
608 // A schema that names no properties says nothing to hold the arguments to.
609 if (schema["properties"] === undefined) return undefined;
610 const props = schema["properties"] as Record<string, Schema>;
611 const open = schema["additionalProperties"] === true;
612 for (const [name, v] of Object.entries(args)) {
613 const s = Object.hasOwn(props, name) ? props[name] : undefined;
614 if (s === undefined) {
615 if (open) continue;
616 const known = Object.keys(props);
617 const first = known[0];
618 return `unknown argument "${name}": this tool takes ${known.length === 0 ? "no arguments" : known.join(", ")}${first === undefined ? "" : `. Example: ${example(first, props[first] ?? {})}`}`;
619 }
620 const types = [s["type"]].flat().filter((t): t is string => typeof t === "string");
621 const wrong =
622 types.length > 0 && !types.some((t) => accepts(t, v));
623 if (wrong || outside(s, v))
624 return `argument "${name}" is ${shown(name, s, v)}; expected ${expected(s)}. Example: ${example(name, s)}`;
625 }
626 const required = Array.isArray(schema["required"]) ? (schema["required"] as unknown[]) : [];
627 for (const name of required)
628 if (typeof name === "string" && args[name] === undefined) {
629 const s = Object.hasOwn(props, name) ? props[name] ?? {} : {};
630 return `argument "${name}" is missing; expected ${expected(s)}. Example: ${example(name, s)}`;
631 }
632 return undefined;
633 }
src/http/mcp/tools/app_deploy.ts +1 −1
@@ -9,7 +9,7 @@ export const tool: Tool = {
99 name: "app_deploy",
1010 doc: "`{ repo, env, action }`: `redeploy` or `stop` an app's `production` or a pull's `pull-N` preview; a writer's, queued as `POST …/app/:env/redeploy` and `…/stop` are; answers `{ queued, run }` or `{ stopped }`. `{ repo, action: \"pull\" }` runs an adapter's pull now as `POST …/app/pull` does; answers `{ run }`. `{ repo, action: \"schedules\" }` lists the app's schedules (`{ items }`, as `GET …/schedules`); `run_schedule`, `pause_schedule` or `resume_schedule` with `name` steers one, a writer's, as `POST …/schedules/:name/:action` does. `jobs` lists the durable job runs (`{ items }`, as `GET …/jobs`); `cancel_job` or `retry_job` with `name` the run id steers one, as `POST …/jobs/:id/:action` does",
1111 description:
12 "Redeploy or stop an env, pull, list and steer schedules and jobs.",
12 "Redeploy or stop an env, pull, steer schedules and jobs.",
1313 inputSchema: {
1414 type: "object",
1515 properties: {
src/http/mcp/tools/apps.ts +2 −2
@@ -18,14 +18,14 @@ export const tool: Tool = {
1818 name: "apps",
1919 doc: "`{ action: \"restore\", repo? }` brings an archived app back (admin token); `{ archived? }`: your apps (`ui://forge/app` card): live or not, what is working, running `previews`, `crew` with a run now, and in migration mode `mode` and `migration {origin, done, total, state}` (`origin` is null to someone who may not see a private source). `{ repo, pulls: true, limit? }`: an adapter's pull runs, as `GET …/app/pulls` (`limit`); a reader's",
2020 description:
21 "Apps you can see: live or not, where served, how each runs, what works.",
21 "Apps you can see: live, where served, how each runs, what works.",
2222 inputSchema: {
2323 type: "object",
2424 properties: {
2525 archived: { type: "boolean" },
2626 repo: { type: "string" },
2727 pulls: { type: "boolean" },
28 limit: { type: "integer" },
28 limit: { type: "integer", minimum: 1, maximum: 100 },
2929 action: { type: "string" },
3030 },
3131 },
src/http/mcp/tools/assign.ts +3 −5
@@ -23,11 +23,9 @@ export const tool: Tool = {
2323 run(ctx, user, args) {
2424 const repo = repoArg(ctx, user, args);
2525 if (isAnswer(repo)) return repo;
26 const kind = args["kind"];
27 if (kind !== "issue" && kind !== "pull") return bad("invalid", "kind is issue or pull");
28 const name = args["assignee"];
29 if (name !== null && typeof name !== "string")
30 return bad("invalid_assignee", "assignee must be a username or null");
26 // `kind` and `assignee` were held to the schema before this runs (`badArgument`).
27 const kind = args["kind"] as "issue" | "pull";
28 const name = args["assignee"] as string | null;
3129 const issue = issueArg(ctx, repo, args, "number");
3230 if ("ok" in issue) return issue;
3331 if (issue.kind !== kind) return bad("no_such_issue", `no ${kind} #${issue.number}`);
src/http/mcp/tools/backups_destination.ts +1 −1
@@ -10,7 +10,7 @@ export const tool: Tool = {
1010 inputSchema: {
1111 type: "object",
1212 properties: {
13 action: { enum: ["set", "forget"] },
13 action: { type: "string", enum: ["set", "forget"] },
1414 endpoint: { type: "string" },
1515 bucket: { type: "string" },
1616 region: { type: "string" },
src/http/mcp/tools/boards.ts +1 −1
@@ -16,7 +16,7 @@ export const tool: Tool = {
1616 panel: { type: "integer", minimum: 0, maximum: 23, description: "Panel from 0." },
1717 from: { type: "string", maxLength: 64 },
1818 to: { type: "string", maxLength: 64 },
19 step: { type: "string", maxLength: 16, description: "With panel: bucket seconds, or 5m." },
19 step: { type: ["string", "integer"], maxLength: 16, description: "With panel: bucket seconds, or 5m." },
2020 },
2121 },
2222 writes: false,
src/http/mcp/tools/events.ts +1 −1
@@ -11,7 +11,7 @@ export const tool: Tool = {
1111 properties: {
1212 repo: REPO_ARG,
1313 kind: { type: "string" },
14 limit: { type: "integer" },
14 limit: { type: "integer", minimum: 1, maximum: 200 },
1515 cursor: { type: "string" },
1616 after: { type: "string" },
1717 },
src/http/mcp/tools/find_tool.ts +1 −1
@@ -4,7 +4,7 @@ import { FIND_MAX, matching, QUERY_MAX, talkLists } from "../catalog.ts";
44 export const tool: Tool = {
55 name: "find_tool",
66 doc: "`{ query }`: the tools whose name, description or plain-word keywords match every word (else the most words); filler words are ignored, with their one-line description and schema; a tool found is callable at once, listed or not; Talk's own agent, which can call only what it is listed, is found only those. `tools/list` with `{\"all\": true}` is the full list",
7 description: "Find a tool by what it does; returns name, description and schema. Any tool is callable by name.",
7 description: "Find a tool by what it does: name, description, schema. Any tool is callable by name.",
88 inputSchema: {
99 type: "object",
1010 properties: { query: { type: "string", maxLength: QUERY_MAX } },
src/http/mcp/tools/forges.ts +3 −4
@@ -18,10 +18,10 @@ const sentSays = (n: number) => (n === 0 ? "This forge has sent no forges yet."
1818 export const tool: Tool = {
1919 name: "forges",
2020 listedTo: "admin",
21 doc: "an admin's list of the forges sent from here: name, address, whom for, apps, claimed, stage (link not opened/opened/signed in/crew working/last tell, with stageAt; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large) or, with `plan`, grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge out of this forge's own process into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven and put back on any failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused lists the last 20 refused first asks; `kind` clients lists each client in the page's words, with runs and pulls so far, and tellAt while the crew is working; `action` resend + `forge`: previews, with `dryRun: false` replaces its link",
21 doc: "the forges sent from here: name, address, whom for, apps, claimed, stage (link not opened/opened/signed in/crew working/last tell, with stageAt; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large); `plan` grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven, put back on failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused: the last 20 refused first asks; `kind` clients lists each client in the page's words, with runs, pulls, tellAt while working; `action` resend + `forge`: previews, with `dryRun: false` replaces its link",
2222 description:
23 "Forges sent from here (admin), clients, a forge plan or size.",
24 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["refused", "clients"] }, forge: { type: "string" }, plan: { type: "string" }, codes: { type: "boolean" }, code: { type: "object" }, revoke: { type: "string" }, archive: { type: ["string", "array"], items: { type: "string" } }, restore: { type: "string" }, sandbox: { type: "boolean" }, size: { type: "string" }, acknowledge: { type: "boolean" }, dryRun: { type: "boolean" } } },
23 "Forges sent from here (admin): clients, plans, sizes.",
24 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["refused", "clients"] }, action: { enum: ["resend"] }, forge: { type: "string" }, plan: { type: "string" }, codes: { type: "boolean" }, code: { type: "object" }, revoke: { type: "string" }, archive: { type: ["string", "array"], items: { type: "string" } }, restore: { type: "string" }, sandbox: { type: "boolean" }, size: { type: "string" }, acknowledge: { type: "boolean" }, dryRun: { type: "boolean" } } },
2525 writes: true,
2626 tier: "delete",
2727 deletes: (args) => args["archive"] !== undefined,
@@ -32,7 +32,6 @@ export const tool: Tool = {
3232 if (!user.isAdmin)
3333 return bad("forbidden", "only an admin of this forge sees the forges it sent");
3434 if (args["action"] !== undefined) {
35 if (args["action"] !== "resend") return bad("invalid", "action is resend");
3635 const name = str(args["forge"]);
3736 if (args["dryRun"] !== false) {
3837 const seen = await previewDoor(ctx, user, name);
src/http/mcp/tools/hooks.ts +1 −1
@@ -32,7 +32,7 @@ export const tool: Tool = {
3232 secret: { type: "string", maxLength: 200 },
3333 id: { type: "string", maxLength: 64 },
3434 delivery: { type: "string", maxLength: 64 },
35 limit: { type: "number" },
35 limit: { type: "integer", minimum: 1, maximum: 200 },
3636 cursor: { type: "string" },
3737 },
3838 required: ["repo", "action"],
src/http/mcp/tools/pinned_forge.ts +1 −1
@@ -19,7 +19,7 @@ export const tool: Tool = {
1919 app: { type: "string", maxLength: 140 },
2020 source: { type: "string", maxLength: 300 },
2121 version: { type: "string", maxLength: 40, description: "Commit id or tag." },
22 place: { type: "string", maxLength: 200, description: "provider:datacenter:size, an orderable place of the account's provider; omit for the default." },
22 place: { type: "string", maxLength: 200, description: "provider:datacenter:size; omit for the default." },
2323 config: { type: "object", description: "NAME: value; no secrets." },
2424 },
2525 required: ["verb"],
src/http/mcp/tools/repo_labels.ts +1 −1
@@ -19,7 +19,7 @@ export const tool: Tool = {
1919 name: { type: "string" },
2020 color: { type: "string" },
2121 id: { type: "string" },
22 limit: { type: "number" },
22 limit: { type: "integer", minimum: 1, maximum: 200 },
2323 cursor: { type: "string" },
2424 },
2525 required: ["repo"],
src/http/mcp/tools/search.ts +1 −1
@@ -12,7 +12,7 @@ export const tool: Tool = {
1212 properties: {
1313 q: { type: "string", maxLength: MAX_QUERY_CHARS },
1414 kind: { type: "string", enum: ["all", "issues", "repos", "code"] },
15 limit: { type: "integer" },
15 limit: { type: "integer", minimum: 1, maximum: 100 },
1616 repo: { type: "string", maxLength: 140 },
1717 all: { type: "boolean" },
1818 },
src/http/mcp/tools/signup.ts −2
@@ -36,8 +36,6 @@ export const tool: Tool = {
3636 const links = readBillingLinks(ctx.app, user);
3737 return links.ok ? good({ ...read.value, billingLinks: links.value }) : bad("not_found", "no such tool here");
3838 }
39 if (!(SIGNUP_MODES as readonly unknown[]).includes(args["mode"]))
40 return bad("invalid_signup", SIGNUP_WORDS);
4139 if (args["dryRun"] !== false)
4240 return good({
4341 says: `Would set signup from ${read.value.signup} to ${String(args["mode"])}. Send dryRun: false to change it.`,
src/http/mcp/tools/spawn.ts +2
@@ -10,6 +10,8 @@ export const tool: Tool = {
1010 "Spawn a child forge. Plans first.",
1111 inputSchema: {
1212 type: "object",
13 // Open on purpose: a `modelKey` is refused in its own words, never as an unknown name.
14 additionalProperties: true,
1315 properties: {
1416 name: {
1517 type: "string",
src/http/mcp/tools/wait_for.ts −2
@@ -19,8 +19,6 @@ export const tool: Tool = {
1919 },
2020 writes: true,
2121 run(ctx, user, args) {
22 if (args["stop"] !== undefined && typeof args["stop"] !== "boolean")
23 return bad("invalid_stop", "stop is true or false");
2422 const repo = planRepo(ctx, user, args);
2523 if (isAnswer(repo)) return repo;
2624 const issue = issueArg(ctx, repo, args, "issue");
test/archive-mcp.test.ts +1 −1
@@ -105,7 +105,7 @@ test("an admin needs an admin token; then archives and wakes", async () => {
105105 const small = await mcp(tok["founderRw"]!, { repo: "acme/svc", archived: true, dryRun: false });
106106 expect(small.error).toContain("forbidden");
107107 expect(archived()).toBe(false);
108 expect((await mcp(tok["founder"]!, { repo: "acme/svc", archived: "yes" })).error).toContain("true or false");
108 expect((await mcp(tok["founder"]!, { repo: "acme/svc", archived: "yes" })).error).toContain('argument "archived"');
109109 const set = await mcp(tok["founder"]!, { repo: "acme/svc", archived: true, dryRun: false });
110110 expect(set.value).toMatchObject({ dryRun: false, archived: true, was: false });
111111 expect(archived()).toBe(true);
test/ask-filters.test.ts +1 −1
@@ -161,7 +161,7 @@ describe("ask filters", () => {
161161 const done = await call({ filter: "hide_app_day", app: "alice/plain" });
162162 expect(done.value.rows).toHaveLength(1);
163163 expect(done.value.filters).toEqual({ hidden: 1, line: "1 hidden by your filters" });
164 expect((await call({ filter: "hide_kind", kind: "nope" })).error).toContain("kind is");
164 expect((await call({ filter: "hide_kind", kind: "nope" })).error).toContain('argument "kind" is "nope"');
165165 expect((await call({ filter: "hide_app", app: "alice/none" })).error).toBeDefined();
166166 const cleared = await call({ filter: "clear" });
167167 expect(cleared.value.rows).toHaveLength(2);
test/asks-mute.test.ts +1 −1
@@ -291,7 +291,7 @@ describe("muting a repository's asks", () => {
291291 // Bad filters are refused, not guessed at.
292292 expect(((await tool(token, "asks", { hide_kinds: ["nope"] })) as any).error).toContain("hide_kinds");
293293 expect(((await tool(token, "asks", { hide_people: ["nobody"] })) as any).error).toContain("hide_people");
294 expect(((await tool(token, "asks", { hide_kinds: "reviews" })) as any).error).toContain("lists");
294 expect(((await tool(token, "asks", { hide_kinds: "reviews" })) as any).error).toContain('argument "hide_kinds"');
295295 // The manifest says so.
296296 const tools = (await listAt(servers.url, token)).result.tools as any[];
297297 for (const name of ["asks", "feed"]) {
test/attach-look.test.ts +1 −1
@@ -256,7 +256,7 @@ describe("attaching a look to a pull", () => {
256256 expect(dry.value.dryRun).toBe(true);
257257 expect(kept().length).toBe(before);
258258 const bad = await mcp(tokens["alice"]!, { ...good, width: "tablet", dryRun: false });
259 expect(bad.error).toContain("phone or desktop");
259 expect(bad.error).toContain('argument "width" is "tablet"');
260260 const done = await mcp(tokens["alice"]!, { ...good, dryRun: false });
261261 expect(done.value.dryRun).toBe(false);
262262 expect(done.value.url).toContain("/alice/garden/looks/");
test/conversation-confirm.test.ts +2 −2
@@ -188,7 +188,7 @@ describe("the one list of what asks first", () => {
188188 test("an asked-first call too large to read is refused through the MCP and kept nowhere (#8230)", async () => {
189189 const w = await world(alice);
190190 const before = waitingFor(app.db, alice.id).length;
191 const over = await call(w.token, "archive", { repo: w.repo, archived: true, dryRun: false, pad: "z".repeat(9000) });
191 const over = await call(w.token, "archive", { repo: w.repo, archived: true, dryRun: false, repos: Array(1000).fill("zzzzzzzzz") });
192192 expect(over.isError).toBe(true);
193193 expect(JSON.parse(over.text).needs_confirm).toBeNull();
194194 expect(over.text).toContain("too large for the person to read");
@@ -395,7 +395,7 @@ describe("the yes, reached by a person", () => {
395395 test("Settings → Confirms folds open on the full arguments, escaped, a secret hidden (#8230)", async () => {
396396 const w = await world(alice);
397397 const asked = JSON.parse(
398 (await call(w.token, "secrets", { scope: "repo", ref: w.repo, action: "set", name: "K", value: "hunter2", note: "<img src=x onerror=alert(1)>" })).text,
398 (await call(w.token, "secrets", { scope: "repo", ref: w.repo, action: "set", name: "<img src=x onerror=alert(1)>", value: "hunter2" })).text,
399399 );
400400 expect(asked.needs_confirm).toBeString();
401401 const listed = await (await page(alice, "/settings/confirms")).text();
test/conversation-fence.test.ts +1 −1
@@ -258,7 +258,7 @@ describe("text read by the forge's agent is fenced as data", () => {
258258 test("a held write too large to read is refused through the MCP and kept nowhere (#8230)", async () => {
259259 const w = await world();
260260 await call(w.token, "issue", { repo: w.repo, number: 1 });
261 const over = await call(w.token, "close", { repo: w.repo, number: 3, pad: "z".repeat(9000) });
261 const over = await call(w.token, "close", { repo: w.repo, number: 3, into: Array(5000).fill(1) });
262262 expect(over.isError).toBe(true);
263263 expect(JSON.parse(over.text).needs_confirm).toBeNull();
264264 expect(over.text).toContain("too large for the person to read");
test/crew-teams.test.ts +1 −1
@@ -171,7 +171,7 @@ describe("crew teams", () => {
171171
172172 test("the teams tool plans by default, changes with dryRun false, and is not for a non-admin", async () => {
173173 expect(JSON.stringify(await mcp(alice, "teams", { slug: "security", dial: 101 }))).toContain(
174 "A dial is a whole number from 0 to 100.",
174 'argument \\"dial\\" is 101',
175175 );
176176 const dryOver = JSON.stringify(await mcp(alice, "teams", { slug: "security", dial: 90 }));
177177 expect(dryOver).toContain("The dials together may not pass 100%.");
test/decisions-by-doors.test.ts +1 −1
@@ -182,7 +182,7 @@ describe("the standing rule over MCP", () => {
182182 expect(rule()).toBe("me");
183183 }
184184 const odd = await mcp(admin["founder"]!, "decisions_by", { repo: "acme/svc", by: "x" });
185 expect(odd.error).toContain("me, decider or decider_tell");
185 expect(odd.error).toContain('argument "by" is "x"');
186186 });
187187
188188 test("the admin needs an admin token to set it", async () => {
test/feed-interact.test.ts +7 −3
@@ -3,6 +3,8 @@
33 * and `readInteraction` (src/feed/interact.ts) are the one rule, and the
44 * route and MCP `feed_dismiss` refuse the same inputs with the same error.
55 */
6 import { badArgument } from "../src/http/mcp/shared.ts";
7 import { TOOLS } from "../src/http/mcp/tools.ts";
68 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
79 import { mkdtemp, rm } from "node:fs/promises";
810 import { tmpdir } from "node:os";
@@ -178,7 +180,9 @@ describe("the route and MCP feed_dismiss refuse the same things", () => {
178180 const tool = await mcp(input);
179181 expect({ input, code: web.error }).toEqual({ input, code });
180182 expect(web.status).toBe(code === "not_found" ? 404 : 422);
181 expect(tool).toEqual({ isError: true, text: expect.stringContaining(`${web.error}: ${web.message}`) });
183 // What the tool's schema refuses, the MCP names by argument; the rest, in the route's words.
184 const shape = badArgument(TOOLS.find((t) => t.name === "feed_dismiss")!.inputSchema, input);
185 expect(tool).toEqual({ isError: true, text: expect.stringContaining(shape === undefined ? `${web.error}: ${web.message}` : `invalid: ${shape}`) });
182186 }
183187 });
184188
@@ -188,10 +192,10 @@ describe("the route and MCP feed_dismiss refuse the same things", () => {
188192 const tool = await mcp(input);
189193 expect(web.status).toBe(422);
190194 expect(web.error).toBe("invalid_kind");
191 expect(tool).toEqual({ isError: true, text: expect.stringContaining("invalid_kind: kind is one of dismissed, muted") });
195 expect(tool).toEqual({ isError: true, text: expect.stringContaining('invalid: argument "kind" is "bogus"; expected one of "dismissed", "muted"') });
192196 // The route records every act a card reports; the tool only dismisses or mutes.
193197 expect((await route({ item: openEvent, kind: "opened" })).status).toBe(201);
194 expect((await mcp({ item: openEvent, kind: "opened" })).text).toStartWith("invalid_kind:");
198 expect((await mcp({ item: openEvent, kind: "opened" })).text).toStartWith('invalid: argument "kind" is "opened"');
195199 });
196200
197201 test("what one door accepts, the other does too", async () => {
test/feed-like.test.ts +1 −1
@@ -350,7 +350,7 @@ describe("one ledger from every door", () => {
350350 const before = ledgerRows(secretEvent);
351351 expect(String(await mcp(bobTok, { item: secretEvent, act: "like" }))).toContain("not visible");
352352 expect(ledgerRows(secretEvent)).toBe(before);
353 expect(String(await mcp(bobTok, { item: openEvent, act: "nope" }))).toContain("act is one of");
353 expect(String(await mcp(bobTok, { item: openEvent, act: "nope" }))).toContain('argument "act" is "nope"');
354354 });
355355
356356 test("newest first, a page at a time, with `more` and a `before` cursor, over API and MCP", async () => {
test/growth.test.ts +2 −2
@@ -371,8 +371,8 @@ describe("growth and the planner switch", () => {
371371
372372 test("until with resume, and a confirm that is not a boolean, are refused", async () => {
373373 expect(((await mcp(owner, { action: "resume", until: soon() })) as any).error).toContain("until is a UTC time, for pause");
374 expect(((await mcp(owner, { action: "pause", confirm: "yes" })) as any).error).toContain("confirm is true or false");
375 expect(((await mcp(owner, { action: "stop" })) as any).error).toContain("pause or resume");
374 expect(((await mcp(owner, { action: "pause", confirm: "yes" })) as any).error).toContain('argument "confirm"');
375 expect(((await mcp(owner, { action: "stop" })) as any).error).toContain('argument "action" is "stop"');
376376 expect(pausedUntil(app.db, repo.id, new Date())).toBeNull();
377377 });
378378
test/holds.test.ts +1 −1
@@ -819,7 +819,7 @@ describe("a hold is set, shown and lifted", () => {
819819 until: "red",
820820 dryRun: false,
821821 });
822 expect(typo.error).toContain("bad_until");
822 expect(typo.error).toContain('argument "until" is "red"');
823823 expect(getHold(f.app.db, mine.id)).toBeUndefined();
824824 holdPull(f.app, f.alice, f.repo, mine, "red alone", false, "green");
825825 const check = createRun(f.app.db, {
test/issue-teams-doors.test.ts +1 −1
@@ -233,7 +233,7 @@ describe("naming teams, at every door", () => {
233233 expect((await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number })).teams).toEqual(["platform"]);
234234 const many = await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number, teams: ["design", "security", "platform"] });
235235 expect(JSON.stringify(many)).toContain("at most 2");
236 expect(JSON.stringify(await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number, teams: "design" }))).toContain("list of team slugs");
236 expect(JSON.stringify(await mcp(alice, "issue_teams", { repo: "alice/garden", number: issue.number, teams: "design" }))).toContain("expected array");
237237 expect(teamsOfIssue(app.db, issue.id)).toEqual(["platform"]);
238238 expect(JSON.stringify(await mcp(bob, "issue_teams", { repo: "alice/garden", number: issue.number, teams: ["design"] }))).toContain("no such");
239239 });
test/mcp-app-deploy.test.ts +1 −1
@@ -157,7 +157,7 @@ describe("MCP app_deploy", () => {
157157 const before = runCount();
158158 for (const action of ["restart", "burn", "", "REDEPLOY"]) {
159159 const a = await tool(aliceRw, { repo: "alice/hello", env: "production", action });
160 expect(a.error).toContain("invalid_action");
160 expect(a.error).toContain('argument "action"');
161161 }
162162 expect(runCount()).toBe(before);
163163 });
test/mcp-app-env.test.ts +2 −2
@@ -110,9 +110,9 @@ describe("MCP app_env", () => {
110110 const reserved = await tool(aliceAdmin, { repo: "alice/game", action: "set", name: "FORGE_X", value: SECRET });
111111 expect(reserved.error).toContain("reserved_name");
112112 const scope = await tool(aliceAdmin, { repo: "alice/game", action: "set", name: "A", value: SECRET, scope: "x" });
113 expect(scope.error).toContain("invalid_scope");
113 expect(scope.error).toContain('argument "scope"');
114114 const gone = await tool(aliceAdmin, { repo: "alice/game", action: "unset", name: "NOPE" });
115115 expect(gone.error).toContain("no_such_var");
116 expect((await tool(aliceAdmin, { repo: "alice/game", action: "burn" })).error).toContain("list, set or unset");
116 expect((await tool(aliceAdmin, { repo: "alice/game", action: "burn" })).error).toContain('argument "action" is "burn"');
117117 });
118118 });
test/mcp-args.test.ts added +146
@@ -0,0 +1,146 @@
1 /**
2 * Every MCP argument is held to its tool's own inputSchema (#15362): a wrong type or a name the
3 * tool does not take is refused naming the argument, never dropped as if absent.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createToken } from "../src/core/tokens.ts";
11 import { createUser } from "../src/core/users.ts";
12 import { askingOf } from "../src/perf/asking.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { badArgument } from "../src/http/mcp/shared.ts";
15 import { TOOLS } from "../src/http/mcp/tools.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17
18 quietLogs();
19
20 /** Tools whose schema names no properties, so there is nothing to hold their arguments to. */
21 const SCHEMALESS = ["backups_test"];
22
23 /** Tools offered only behind a switch this forge has off (`needsSwitch`: SSH). */
24 const HIDDEN = ["ssh_keys"];
25
26 /** Tools whose schema says `additionalProperties: true`. */
27 const OPEN = ["spawn"];
28
29 test("an unknown name is refused, and the tool's own names are listed", () => {
30 const said = badArgument({ type: "object", properties: { limit: { type: "integer" } } }, { bogus: 1 });
31 expect(said).toContain('unknown argument "bogus"');
32 expect(said).toContain("limit");
33 expect(badArgument({ type: "object", properties: {}, additionalProperties: true }, { bogus: 1 })).toBeUndefined();
34 expect(badArgument({ type: "object", properties: { limit: { type: "integer" } } }, { limit: 5 })).toBeUndefined();
35 expect(badArgument({ type: "object", properties: { n: { type: "number" } } }, { n: 5 })).toBeUndefined();
36 });
37
38 let dir: string, app: App, servers: Servers, token: string;
39 beforeAll(async () => {
40 dir = await mkdtemp(join(tmpdir(), "forge-mcp-args-"));
41 app = createApp({ dataDir: dir, port: 0 });
42 servers = await serve(app);
43 const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
44 if (!u.ok) throw new Error("user");
45 token = createToken(app.db, u.value.id, "t", "admin").token;
46 });
47 afterAll(async () => {
48 askingOf(app).forget();
49 await servers.stop();
50 await rm(dir, { recursive: true, force: true });
51 });
52
53 const call = async (name: string, args: object) => {
54 const res = await fetch(`${servers.url}/mcp`, {
55 method: "POST",
56 headers: { "content-type": "application/json", accept: "application/json", authorization: `Bearer ${token}` },
57 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }),
58 });
59 const body = (await res.json()) as any;
60 return body.result ?? { hidden: body.error?.message };
61 };
62
63 test("search with limit \"many\" and explore with an unknown name are refused, not answered empty", async () => {
64 const bad = await call("search", { q: "a", limit: "many" });
65 expect(bad.isError).toBe(true);
66 expect(bad.content[0].text).toContain('invalid: argument "limit" is "many"; expected integer from 1 to 100');
67 const unknown = await call("explore", { bogus: 1 });
68 expect(unknown.isError).toBe(true);
69 expect(unknown.content[0].text).toContain('unknown argument "bogus"');
70 expect((await call("explore", {})).isError).not.toBe(true);
71 });
72
73 const WRONG: unknown[] = [{ nope: 1 }, "wrong", 12345, true, []];
74 /** A value the property refuses, or undefined when its schema accepts anything. */
75 const wrongFor = (schema: any): unknown => {
76 const types = [schema.type].flat().filter((t) => typeof t === "string");
77 if (types.length === 0) return Array.isArray(schema.enum) ? { nope: 1 } : undefined;
78 return WRONG.find((v) => {
79 const have = v === null ? "null" : Array.isArray(v) ? "array" : Number.isInteger(v) ? "integer" : typeof v;
80 return !types.includes(have) && !(have === "integer" && types.includes("number"));
81 });
82 };
83
84 test("over /mcp, every tool refuses its first property given the wrong type, and an unknown name, naming each", async () => {
85 const untyped: string[] = [];
86 const open: string[] = [];
87 const hidden: string[] = [];
88 for (const t of TOOLS) {
89 const schema = t.inputSchema as any;
90 const props = schema.properties as Record<string, any> | undefined;
91 if (props === undefined) {
92 open.push(t.name);
93 continue;
94 }
95 const first = Object.keys(props)[0];
96 if (first !== undefined) {
97 const wrong = wrongFor(props[first]);
98 if (wrong === undefined) untyped.push(t.name);
99 else {
100 const said = await call(t.name, { [first]: wrong });
101 if (said.hidden !== undefined) {
102 hidden.push(t.name);
103 continue;
104 }
105 expect(said.isError, t.name).toBe(true);
106 expect(said.content[0].text, t.name).toContain(`invalid: argument "${first}" is `);
107 expect(said.content[0].text, t.name).toContain("Example:");
108 }
109 }
110 if (schema.additionalProperties === true) continue;
111 const unknown = await call(t.name, { zz_not_an_argument: 1 });
112 expect(unknown.isError, t.name).toBe(true);
113 expect(unknown.content[0].text, t.name).toContain('invalid: unknown argument "zz_not_an_argument"');
114 }
115 expect(open).toEqual(SCHEMALESS);
116 // Tools this admin token is not offered answer as no such tool, the schema unread.
117 expect(hidden).toEqual(HIDDEN);
118 // A first property whose schema takes any value cannot be given a wrong one: named, so none is
119 // added unseen.
120 expect(untyped).toEqual([]);
121 // Genuinely open: `spawn` keeps its own refusal of a `modelKey`.
122 expect(TOOLS.filter((t) => (t.inputSchema as any).additionalProperties === true).map((t) => t.name)).toEqual(OPEN);
123 });
124
125 test("a value of the right type outside enum, minimum, maximum or maxLength is refused naming it", async () => {
126 const show = await call("search", { q: "a", limit: 0 });
127 expect(show.content[0].text).toContain('argument "limit" is 0; expected integer');
128 expect(badArgument({ properties: { k: { type: "string", enum: ["a", "b"] } } }, { k: "c" })).toBe(
129 'argument "k" is "c"; expected one of "a", "b". Example: {"k": "a"}',
130 );
131 expect(badArgument({ properties: { n: { type: "integer", minimum: 1, maximum: 9 } } }, { n: 0 })).toBe(
132 'argument "n" is 0; expected integer from 1 to 9. Example: {"n": 1}',
133 );
134 expect(badArgument({ properties: { n: { type: "integer", minimum: 1, maximum: 9 } } }, { n: 10 })).toContain('argument "n" is 10');
135 expect(badArgument({ properties: { q: { type: "string", maxLength: 3 } } }, { q: "abcd" })).toBe(
136 'argument "q" is 4 characters long; expected string of at most 3 characters. Example: {"q": "text"}',
137 );
138 expect(badArgument({ properties: { secret: { type: "string", maxLength: 3 } } }, { secret: "hunter2" })).not.toContain("hunter2");
139 expect(badArgument({ properties: { k: { enum: ["a"] }, n: { type: "integer", minimum: 1 } } }, { k: "a", n: 1 })).toBeUndefined();
140 });
141
142 test("a required argument left out is refused naming it", () => {
143 expect(badArgument({ properties: { repo: { type: "string" } }, required: ["repo"] }, {})).toBe(
144 'argument "repo" is missing; expected string. Example: {"repo": "text"}',
145 );
146 });
test/mcp-asked-args.test.ts +3 −3
@@ -110,9 +110,9 @@ describe("MCP asked arguments", () => {
110110 });
111111
112112 test("an unknown show or order is refused", async () => {
113 expect((await call(aliceTok, { show: "everything" })).error).toContain("invalid_show");
114 expect((await call(aliceTok, { order: "random" })).error).toContain("invalid_order");
115 expect((await call(aliceTok, { show: "all", order: "random" })).error).toContain("invalid_order");
113 expect((await call(aliceTok, { show: "everything" })).error).toContain('argument "show"');
114 expect((await call(aliceTok, { order: "random" })).error).toContain('argument "order"');
115 expect((await call(aliceTok, { show: "all", order: "random" })).error).toContain('argument "order"');
116116 });
117117
118118 test("a repository the caller cannot read lists nothing about it", async () => {
test/mcp-assign.test.ts +2 −2
@@ -134,8 +134,8 @@ describe("MCP assign", () => {
134134 test("an unknown user, a wrong kind and a bad shape are refused", async () => {
135135 expect((await call(aliceTok, args("nobody"))).error).toStartWith("no_such_user");
136136 expect((await call(aliceTok, args("bob", { kind: "pull" }))).error).toStartWith("no_such_issue");
137 expect((await call(aliceTok, args("bob", { kind: "thing" }))).error).toStartWith("invalid");
138 expect((await call(aliceTok, args(5 as any))).error).toStartWith("invalid_assignee");
137 expect((await call(aliceTok, args("bob", { kind: "thing" }))).error).toContain('argument "kind"');
138 expect((await call(aliceTok, args(5 as any))).error).toContain('argument "assignee"');
139139 expect(assigneeOf()).toBeNull();
140140 });
141141
test/mcp-cloud-account.test.ts +1 −1
@@ -111,7 +111,7 @@ describe("MCP cloud_account", () => {
111111 test("verb delete is bad_verb", async () => {
112112 const r = await call(adminToken, { verb: "delete" });
113113 expect(r.error).toBe(true);
114 expect(r.text).toContain("bad_verb");
114 expect(r.text).toContain('argument "verb"');
115115 });
116116
117117 test("a non-admin and an rw token are refused for every verb, the account unchanged", async () => {
test/mcp-confirm-wait.test.ts +2 −2
@@ -150,8 +150,8 @@ describe("confirm_wait over MCP", () => {
150150 const w = (args: Record<string, unknown>) =>
151151 tool(rw, "confirm_wait", { app: "alice/game", ...args });
152152 expect((await w({ issue: 1, blocker: 9999 })).error).toContain("no_such_issue");
153 expect((await w({ issue: "1", blocker: 1 })).error).toContain("no_such_issue");
154 expect((await w({ issue: 1, blocker: 1.5 })).error).toContain("no_such_issue");
153 expect((await w({ issue: "1", blocker: 1 })).error).toContain('argument "issue"');
154 expect((await w({ issue: 1, blocker: 1.5 })).error).toContain('argument "blocker"');
155155 expect((await tool(rw, "confirm_wait", { issue: 1, blocker: 1 })).error).toBeDefined();
156156 });
157157 });
test/mcp-flag-set.test.ts +1 −1
@@ -122,7 +122,7 @@ describe("MCP flag_set", () => {
122122 expect(r.error).toBe(true);
123123 expect(r.text).toContain("Flags are set by a forge admin.");
124124 const junk = await call(bob, { name: 7, value: 3 });
125 expect(junk.text).toContain("Flags are set by a forge admin.");
125 expect(junk.text).toContain('invalid: argument "name" is 7; expected string');
126126 expect(reg.value("alpha")).toBeUndefined();
127127 });
128128
test/mcp-fleet-act.test.ts +1 −1
@@ -105,7 +105,7 @@ test("someone who administers none of the rows is refused each row; bad input an
105105 expect(tried.value.rows.every((r: any) => r.outcome === "refused")).toBe(true);
106106 expect(ceilings()).toEqual(before);
107107 expect((await call(tok["admin"]!, { q: query, action: { verb: "nope" } })).error).toContain("bad_action");
108 expect((await call(tok["admin"]!, { q: query, action, apply: "yes" })).error).toContain("apply is true or false");
108 expect((await call(tok["admin"]!, { q: query, action, apply: "yes" })).error).toContain('argument "apply"');
109109 expect((await call(tok["admin"]!, { action })).error).toContain("needs q");
110110 expect((await call(tok["admin"]!, { q: query, apply: true })).error).toContain("needs an action");
111111 expect(ceilings()).toEqual(before);
test/mcp-flow-why.test.ts +1 −1
@@ -146,7 +146,7 @@ describe("MCP flow with a subject", () => {
146146
147147 test("a reader is refused, and bad numbers are invalid", async () => {
148148 expect((await call(readerTok, { repo: "alice/one", issue: 1 })).error).toContain("can write");
149 expect((await call(ownerTok, { repo: "alice/one", issue: "x" })).error).toContain("numbers");
149 expect((await call(ownerTok, { repo: "alice/one", issue: "x" })).error).toContain('argument "issue"');
150150 expect((await call(ownerTok, { repo: "alice/one", issue: 1, pull: 2 })).error).toContain("not both");
151151 expect((await call(ownerTok, { repo: "alice/one", issue: 99 })).error).toContain("no issue");
152152 });
test/mcp-forge-tell.test.ts +2 −2
@@ -214,8 +214,8 @@ describe("the forge over MCP: tell", () => {
214214 expect(closed.value).toMatchObject({ state: "closed", closeReason: "done" });
215215
216216 // The boundary: bad words are refused before the action.
217 expect((await tool(rw, "close", { repo: "alice/game", number: own.number, state: "x" })).error).toContain("invalid_state");
218 expect((await tool(rw, "close", { repo: "alice/game", number: own.number, reason: "x" })).error).toContain("invalid_reason");
217 expect((await tool(rw, "close", { repo: "alice/game", number: own.number, state: "x" })).error).toContain('argument "state"');
218 expect((await tool(rw, "close", { repo: "alice/game", number: own.number, reason: "x" })).error).toContain('argument "reason"');
219219 expect((await tool(rw, "close", { repo: "alice/game", number: own.number, into: [0] })).error).toContain("invalid_reason");
220220 expect((await tool(ro, "close", { repo: "alice/game", number: own.number })).error).toContain(READ_ONLY_REFUSAL);
221221 });
test/mcp-hook-deliveries.test.ts +1 −1
@@ -96,6 +96,6 @@ describe("MCP hook deliveries", () => {
9696 expect((await tool(bobAdmin, { repo: "alice/game", action: "deliveries", id: hookId })).error).toContain("not_found");
9797 expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: otherHookId })).error).toContain("not_found");
9898 expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: "nope" })).error).toContain("not_found");
99 expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: "i".repeat(65) })).error).toContain("id is text");
99 expect((await tool(aliceAdmin, { repo: "alice/game", action: "deliveries", id: "i".repeat(65) })).error).toContain('argument "id" is 65 characters long');
100100 });
101101 });
test/mcp-hooks.test.ts +6 −6
@@ -100,7 +100,7 @@ describe("MCP hooks", () => {
100100 expect(second.value.items.map((h: any) => h.id)).toEqual([ids[2]]);
101101 expect(second.value.next_cursor).toBeNull();
102102 for (const limit of [0, 201, 1.5, "5"])
103 expect((await tool(aliceAdmin, { repo: "alice/game", action: "list", limit })).error).toContain("invalid_limit");
103 expect((await tool(aliceAdmin, { repo: "alice/game", action: "list", limit })).error).toContain('argument "limit"');
104104 expect((await tool(aliceAdmin, { repo: "alice/game", action: "list", cursor: "gone" })).error).toContain("invalid_cursor");
105105 for (const id of ids) await tool(aliceAdmin, { repo: "alice/game", action: "remove", id });
106106 });
@@ -117,17 +117,17 @@ describe("MCP hooks", () => {
117117 test("an invalid URL is refused with the API's error", async () => {
118118 for (const url of ["http://example.com/h", "nonsense", ""])
119119 expect((await tool(aliceAdmin, { repo: "alice/game", action: "add", url, secret: "0123456789abcdef" })).error).toContain("invalid_url");
120 expect((await tool(aliceAdmin, { repo: "alice/game", action: "nope" })).error).toContain("action is list");
120 expect((await tool(aliceAdmin, { repo: "alice/game", action: "nope" })).error).toContain('argument "action" is "nope"');
121121 });
122122
123123 test("lengths are enforced, and a secret of 16 or more is required", async () => {
124124 const base = { repo: "alice/game", action: "add", secret: "0123456789abcdef" };
125125 const long = await tool(aliceAdmin, { ...base, url: "https://example.com/" + "a".repeat(2048) });
126 expect(long.error).toContain("url is text of at most 2048");
126 expect(long.error).toContain('argument "url" is 2068 characters long');
127127 const kinds = await tool(aliceAdmin, { ...base, url: "https://example.com/h", kinds: "k".repeat(201) });
128 expect(kinds.error).toContain("kinds is text of at most 200");
129 expect((await tool(aliceAdmin, { ...base, url: "https://example.com/h", secret: "x".repeat(201) })).error).toContain("secret is text");
130 expect((await tool(aliceAdmin, { repo: "alice/game", action: "remove", id: "i".repeat(65) })).error).toContain("id is text");
128 expect(kinds.error).toContain('argument "kinds" is 201 characters long');
129 expect((await tool(aliceAdmin, { ...base, url: "https://example.com/h", secret: "x".repeat(201) })).error).toContain('argument "secret" is not accepted; expected string of at most 200 characters');
130 expect((await tool(aliceAdmin, { repo: "alice/game", action: "remove", id: "i".repeat(65) })).error).toContain('argument "id" is 65 characters long');
131131 for (const secret of [undefined, "short"])
132132 expect((await tool(aliceAdmin, { repo: "alice/game", action: "add", url: "https://example.com/h", secret })).error).toContain("secret is required");
133133 expect((await tool(aliceAdmin, { repo: "alice/game", action: "list" })).value).toEqual({ items: [], next_cursor: null });
test/mcp-issue.test.ts +4 −1
@@ -156,7 +156,10 @@ describe("MCP issue", () => {
156156 test("a bad number is refused", async () => {
157157 for (const n of [0, -1, 1.5, "1", null, 999]) {
158158 const r = await tool(aliceTok, { repo: "alice/game", number: n });
159 expect(r.error).toContain("no issue");
159 // Anything the schema refuses (a wrong type, below its minimum) is refused naming the
160 // argument; a whole number that fits but names no issue reaches the tool.
161 if (n === 999) expect(r.error).toContain("no issue");
162 else expect(r.error).toContain('argument "number"');
160163 }
161164 });
162165 });
test/mcp-labels.test.ts +4 −3
@@ -131,16 +131,17 @@ describe("MCP labels", () => {
131131 const removed = await tool(aliceRw, { repo: "alice/game", number, labels: ["FLOW"], action: "remove" });
132132 expect(removed.value.labels).toEqual(["ui"]);
133133 expect((await tool(aliceRw, { repo: "alice/game", number, labels: [], action: "toggle" })).error).toContain(
134 "action is set, add or remove",
134 'argument "action"',
135135 );
136136 });
137137
138138 test("bad input stops at the boundary", async () => {
139139 for (const labels of ["bug", [1], [{}], null, Array(51).fill("a"), ["x".repeat(65)]]) {
140140 const r = await tool(aliceRw, { repo: "alice/game", number, labels });
141 expect(r.error).toContain("labels is a list");
141 // A wrong type is the schema's to refuse; a list whose items or size are wrong, the tool's.
142 expect(r.error).toContain(typeof labels === "string" || labels === null ? 'argument "labels"' : "labels is a list");
142143 }
143144 expect((await tool(aliceRw, { repo: "alice/game", number: 999, labels: [] })).error).toContain("no issue #999");
144 expect((await tool(aliceRw, { repo: "alice/game", number: "1", labels: [] })).error).toContain("no issue");
145 expect((await tool(aliceRw, { repo: "alice/game", number: "1", labels: [] })).error).toContain('argument "number"');
145146 });
146147 });
test/mcp-limit.test.ts +3 −3
@@ -65,7 +65,7 @@ const maxOf = (name: string): number => {
6565 };
6666
6767 for (const name of ["pulls", "commits", "issues", "queue_gates"]) {
68 test(`${name}: the schema's maximum passes; outside it is invalid_limit naming it`, async () => {
68 test(`${name}: the schema's maximum passes; outside it is refused naming limit`, async () => {
6969 const max = maxOf(name);
7070 const base = { repo: "ada/svc" };
7171 // An empty repository has no commits to list: that is a refusal of a different kind, not of the
@@ -74,8 +74,8 @@ for (const name of ["pulls", "commits", "issues", "queue_gates"]) {
7474 for (const limit of [max + 1, 0, 1.5, "7"]) {
7575 const r = await call(name, { ...base, limit });
7676 expect(r.ok).toBe(false);
77 expect(r.error).toContain("invalid_limit");
78 expect(r.error).toContain(`limit is a whole number from 1 to ${max}`);
77 // The boundary refuses every one by name, with the schema's own bounds.
78 expect(r.error).toContain(`argument "limit" is ${JSON.stringify(limit)}; expected integer from 1 to ${max}`);
7979 }
8080 });
8181 }
test/mcp-limits.test.ts +1 −1
@@ -124,7 +124,7 @@ describe("MCP limits", () => {
124124 for (const dryRun of [true, false]) {
125125 const res = await call(adaAdmin, { key: "no_such_thing", value: "5", dryRun });
126126 expect(res.error).toBe(true);
127 expect(res.text).toContain("no_such_limit");
127 expect(res.text).toContain('argument "key"');
128128 expect(res.text).toContain("no_such_thing");
129129 }
130130 });
test/mcp-merge.test.ts +2 −2
@@ -199,10 +199,10 @@ describe("the merge tool over MCP", () => {
199199 const pull = await pullOf("bad-input");
200200 const base = { repo: "alice/game", number: pull.number, dryRun: false };
201201 expect((await tool(aliceRw, { ...base, strategy: "rebase" })).error).toContain(
202 "strategy is merge or squash",
202 'argument "strategy"',
203203 );
204204 expect((await tool(aliceRw, { ...base, number: 9999 })).error).toContain("no pull #9999");
205 expect((await tool(aliceRw, { ...base, number: "1" })).error).toContain("no_such_pull");
205 expect((await tool(aliceRw, { ...base, number: "1" })).error).toContain('argument "number"');
206206 expect((await tool(aliceRw, { ...base, repo: "nope" })).error).toStartWith("not_found:");
207207 expect(getPull(app.db, repo.id, pull.number)!.mergedAt).toBeNull();
208208 });
test/mcp-open-explore.test.ts +1 −1
@@ -117,7 +117,7 @@ describe("open explore and search over MCP", () => {
117117 for (const key of ["q", "query", "cursor"]) {
118118 for (const token of [null, aliceRw]) {
119119 const r = await call(token, "explore", { [key]: "x".repeat(201) });
120 expect(r.error).toContain(`\`${key}\` is a string of at most 200 characters`);
120 expect(r.error).toContain(`argument "${key}" is 201 characters long; expected string of at most 200 characters`);
121121 }
122122 }
123123 });
test/mcp-orgteams.test.ts +1 −1
@@ -99,7 +99,7 @@ describe("MCP org_teams", () => {
9999 await tool(owner, { org: "acme", action: "add_member", team: "crew", user: "carol", role: "reviewer" });
100100 const bad = await tool(owner, { org: "acme", action: "remove_member", team: "crew", user: "carol", role: "boss" });
101101 expect(bad.isError).toBe(true);
102 expect(bad.text).toContain("bad_role");
102 expect(bad.text).toContain('argument "role"');
103103 const off = await tool(owner, { org: "acme", action: "remove_member", team: "crew", user: "carol", role: "reviewer" });
104104 expect(off.isError).toBe(false);
105105 const kept = JSON.parse((await tool(owner, { org: "acme", action: "members", team: "crew" })).text);
test/mcp-origins.test.ts +1 −1
@@ -125,7 +125,7 @@ describe("MCP origins", () => {
125125 (await tool(aliceAdmin, { action: "repos", id: "nope" })).error,
126126 ).toContain("not_found");
127127 expect((await tool(aliceAdmin, { action: "sync" })).error).toContain("invalid");
128 expect((await tool(aliceAdmin, { action: "x" })).error).toContain("bad_action");
128 expect((await tool(aliceAdmin, { action: "x" })).error).toContain('argument "action"');
129129 });
130130
131131 test("a token short of admin is refused", async () => {
test/mcp-passkeys.test.ts +1 −1
@@ -88,6 +88,6 @@ describe("MCP whoami_can kind passkeys", () => {
8888 expect(r.items).toBeUndefined();
8989 const bad = await call(alice, { kind: "teapots" });
9090 expect(bad.error).toBe(true);
91 expect(bad.text).toContain("role, passkeys");
91 expect(bad.text).toContain('one of "role", "passkeys"');
9292 });
9393 });
test/mcp-person.test.ts +1 −3
@@ -105,9 +105,7 @@ describe("MCP person", () => {
105105
106106 test("a limit outside 1 to 200 is refused, 1 and 200 pass", async () => {
107107 for (const bad of [0, -5, 9999, 201, 1.5, "x"])
108 expect((await tool(bobRo, { username: "guild", limit: bad })).error).toContain(
109 "invalid_limit",
110 );
108 expect((await tool(bobRo, { username: "guild", limit: bad })).error).toContain('argument "limit"');
111109 expect((await tool(bobRo, { username: "guild", limit: 1 })).value.repos.items).toHaveLength(1);
112110 expect((await tool(bobRo, { username: "guild", limit: 200 })).value).toBeDefined();
113111 });
test/mcp-pins.test.ts +3 −3
@@ -131,9 +131,9 @@ describe("MCP pins", () => {
131131 const second = (await tool(bobRw, { limit: 2, cursor: first.next_cursor })).value;
132132 expect(second.pins.map((p: any) => p.repo)).toContain("alice/pc");
133133 expect(second.next_cursor).toBeNull();
134 expect((await tool(bobRw, { limit: "x" })).error).toContain("invalid");
134 expect((await tool(bobRw, { limit: "x" })).error).toContain('argument "limit" is "x"');
135135 for (const bad of [0, -5, 9999, 201, 1.5, "x"])
136 expect((await tool(bobRw, { limit: bad })).error).toContain("invalid_limit");
136 expect((await tool(bobRw, { limit: bad })).error).toContain('argument "limit"');
137137 expect((await tool(bobRw, { limit: 1 })).value.pins).toHaveLength(1);
138138 expect((await tool(bobRw, { limit: 200 })).value.pins.length).toBeGreaterThan(0);
139139 for (const n of ["pa", "pb", "pc"]) await tool(bobRw, { action: "unpin", repo: `alice/${n}` });
@@ -143,6 +143,6 @@ describe("MCP pins", () => {
143143 expect(await listed(bobRo)).toEqual([]);
144144 expect((await tool(bobRo, { action: "pin", repo: "alice/open" })).error).toContain("forbidden");
145145 expect((await tool(bobRo, { action: "unpin", repo: "alice/open" })).error).toContain("forbidden");
146 expect((await tool(bobRw, { action: "nuke", repo: "alice/open" })).error).toContain("invalid");
146 expect((await tool(bobRw, { action: "nuke", repo: "alice/open" })).error).toContain('argument "action" is "nuke"');
147147 });
148148 });
test/mcp-prompts.test.ts +1 −1
@@ -127,7 +127,7 @@ describe("MCP prompts", () => {
127127 test("an unknown kind is refused with the API's error, and the token is not echoed", async () => {
128128 const r = await tool(admin, { repo: "alice/game", action: "add", kind: "tiktok", token: TOKEN, at: "15:00" });
129129 expect(r.error).toBe(true);
130 expect(r.text).toContain("invalid_kind");
130 expect(r.text).toContain('argument "kind"');
131131 expect(r.text).not.toContain(TOKEN);
132132 expect((await tool(admin, { repo: "alice/game", action: "nope" })).error).toBe(true);
133133 });
test/mcp-repo-labels.test.ts +1 −1
@@ -116,7 +116,7 @@ describe("MCP repo_labels", () => {
116116 expect(second.value.items.map((l: any) => l.name)).toEqual(["pc", "ui"]);
117117 expect(second.value.next_cursor).toBeNull();
118118 for (const limit of [0, 201, 1.5, "5"])
119 expect((await call(admin, { repo: R, action: "list", limit })).error).toContain("invalid_limit");
119 expect((await call(admin, { repo: R, action: "list", limit })).error).toContain('argument "limit"');
120120 expect((await call(admin, { repo: R, action: "list", cursor: "gone" })).error).toContain("invalid_cursor");
121121 for (const l of (await call(admin, { repo: R, action: "list" })).value.items)
122122 await call(admin, { repo: R, action: "remove", id: l.id });
test/mcp-reposet.test.ts +1 −1
@@ -86,7 +86,7 @@ describe("MCP repo_settings", () => {
8686 test("an invalid visibility is refused", async () => {
8787 const set = await call(admin, "repo_settings", { repo: "acme/game", visibility: "secret" });
8888 expect(set.isError).toBe(true);
89 expect(set.text).toContain("visibility is public or private");
89 expect(set.text).toContain('argument "visibility"');
9090 });
9191
9292 test("newOwner moves a repository; a non-admin and a missing owner are refused", async () => {
test/mcp-restore-drill.test.ts +1 −1
@@ -152,7 +152,7 @@ describe("MCP restore_drill", () => {
152152 });
153153 test("an unknown action is refused", async () => {
154154 const r = await call(token("alice"), "bogus");
155 expect(r.text).toContain("action is start or status");
155 expect(r.text).toContain('argument "action"');
156156 });
157157 test("an admin's read-only token is refused and nothing runs", async () => {
158158 const r = await call(token("alice", "ro"));
test/mcp-review.test.ts +2 −2
@@ -162,7 +162,7 @@ describe("the review tool over MCP", () => {
162162 const pull = await pullBy("four", bob);
163163 const base = { repo: "alice/game", number: pull.number };
164164 expect((await tool(aliceRw, { ...base, verdict: "lgtm" })).error).toContain(
165 "verdict is approve or changes",
165 'argument "verdict"',
166166 );
167167 expect(
168168 (await tool(aliceRw, { ...base, verdict: "changes", reason: " " })).error,
@@ -172,7 +172,7 @@ describe("the review tool over MCP", () => {
172172 ).toContain("no pull #9999");
173173 expect(
174174 (await tool(aliceRw, { ...base, number: "1", verdict: "approve" })).error,
175 ).toContain("no pull");
175 ).toContain('argument "number"');
176176 expect(
177177 (await tool(aliceRw, { repo: "nope", number: 1, verdict: "approve" })).error,
178178 ).toContain("not_found");
test/mcp-search.test.ts +3 −4
@@ -111,12 +111,11 @@ describe("MCP search", () => {
111111 });
112112
113113 test("an unknown kind or a bad limit is refused in the API's words; every kind answers", async () => {
114 expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain("invalid_kind");
115 expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain("all, repos, issues or code");
114 expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain('argument "kind" is "bogus"');
115 expect((await tool(aliceRo, { q: "a", kind: "bogus" })).error).toContain('one of "all", "issues", "repos", "code"');
116116 for (const limit of [0, 101, 1.5, "5"]) {
117117 const r = await tool(aliceRo, { q: "a", limit });
118 expect(r.error).toContain("invalid_limit");
119 expect(r.error).toContain("1 to 100");
118 expect(r.error).toContain(`argument "limit" is ${JSON.stringify(limit)}; expected integer from 1 to 100`);
120119 }
121120 for (const kind of ["all", "repos", "issues", "code"]) expect((await tool(aliceRo, { q: "a", kind, limit: 5 })).error).toBeUndefined();
122121 });
test/mcp-signup.test.ts +2 −2
@@ -115,11 +115,11 @@ describe("MCP signup", () => {
115115 setSignup(app.db, "open", "system");
116116 });
117117
118 test("an unknown mode is invalid_signup", async () => {
118 test("an unknown mode is refused naming mode", async () => {
119119 for (const mode of ["public", 3, ""]) {
120120 const res = await call(adminToken, { mode, dryRun: false });
121121 expect(res.error).toBe(true);
122 expect(res.text).toContain("invalid_signup");
122 expect(res.text).toContain('argument "mode"');
123123 }
124124 expect(getSignup(app.db)).toBe("open");
125125 });
test/mcp-ssh-keys.test.ts +1 −1
@@ -136,7 +136,7 @@ describe("MCP ssh_keys", () => {
136136 });
137137
138138 test("an unknown action is invalid_action", async () => {
139 expect((await tool(aliceRw, { action: "rotate" })).error).toStartWith("invalid_action");
139 expect((await tool(aliceRw, { action: "rotate" })).error).toContain('argument "action"');
140140 });
141141
142142 test("malformed key lines are invalid_key and store nothing", async () => {
test/mcp-tags.test.ts +1 −1
@@ -100,6 +100,6 @@ test("kind tags with name or action, and an unknown kind, are refused", async ()
100100 const w = tok["owner"]!;
101101 expect((await mcp(w, { repo: "ada/svc", kind: "tags", name: "v1" })).error).toContain("only lists");
102102 expect((await mcp(w, { repo: "ada/svc", kind: "tags", action: "delete" })).error).toContain("only lists");
103 expect((await mcp(w, { repo: "ada/svc", kind: "refs" })).error).toContain("branches or tags");
103 expect((await mcp(w, { repo: "ada/svc", kind: "refs" })).error).toContain('argument "kind"');
104104 expect((await mcp(w, { repo: "ada/svc", kind: "branches" })).value.branches[0].name).toBe("main");
105105 });
test/mcp-take-back.test.ts +1 −3
@@ -118,9 +118,7 @@ test("a pull the caller cannot see, or no pull at all, is not found", async () =
118118 expect((await takeBack(tok["sam"]!, { repo: "ada/svc", number: shipped.number })).error).toStartWith("not_found:");
119119 const none = await takeBack(tok["ada"]!, { repo: "ada/svc", number: 999 });
120120 expect(none.error).toStartWith(`not_found: That could not be taken back: ${takeBackWords("not_found")}.`);
121 expect((await takeBack(tok["ada"]!, { repo: "ada/svc", number: "1" })).error).toStartWith(
122 `not_found: That could not be taken back: ${takeBackWords("not_found")}.`,
123 );
121 expect((await takeBack(tok["ada"]!, { repo: "ada/svc", number: "1" })).error).toContain('argument "number"');
124122 });
125123
126124 test("a shipped pull opens the pull that undoes it; a second call is already taken back", async () => {
test/mcp-talk-tools.test.ts +1
@@ -247,6 +247,7 @@ describe("a newly listed write is held as before", () => {
247247 await call("assign", {
248248 repo: "alice/held",
249249 number: 1,
250 kind: "issue",
250251 assignee: "mallory",
251252 }),
252253 ).toContain("needs_confirm");
test/mcp-teams.test.ts +1 −1
@@ -118,7 +118,7 @@ describe("MCP teams", () => {
118118 expect(r.isError).toBe(true);
119119 expect(team()).toEqual(before);
120120 }
121 expect((await tool(admin, { slug, dial: "50" })).text).toContain("invalid_body");
121 expect((await tool(admin, { slug, dial: "50" })).text).toContain('argument "dial"');
122122 expect((await tool(admin, { slug: "nope", dial: 5 })).isError).toBe(true);
123123 });
124124
test/mcp-tell.test.ts +9 −5
@@ -9,7 +9,7 @@ import { tmpdir } from "node:os";
99 import { join } from "node:path";
1010 import { createApp, type App } from "../src/app.ts";
1111 import { newApp } from "../src/actions/apps.ts";
12 import { refusalWords, tellAnswer } from "../src/actions/tell_answer.ts";
12 import { refusalWords } from "../src/actions/tell_answer.ts";
1313 import { SAY_SOMETHING_WORDS } from "../src/actions/tell_words.ts";
1414 import { listIssues } from "../src/core/issues.ts";
1515 import { getRepo } from "../src/core/repos.ts";
@@ -79,11 +79,13 @@ describe("MCP tell refusals", () => {
7979 expect(bad.error).toBe(true);
8080 });
8181
82 test("an over-long tell is refused in the words the terminal and the page say", async () => {
82 test("an over-long tell is refused naming the argument, with the schema's limit", async () => {
8383 const body = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000);
8484 const r = await call({ repo: "alice/notes", text: body });
8585 expect(r.error).toBe(true);
86 expect(r.text).toContain(tellAnswer({ ok: false, error: "body_too_long" }, body).text);
86 // Held to the schema's maxLength before the tool runs: named, measured, never echoed.
87 expect(r.text).toContain('argument "text" is 68002 characters long; expected string of at most 4000 characters');
88 expect(r.text).not.toContain("xxxx");
8789 });
8890
8991 /** The feed composer's own action (the studio's POST /:owner/:name/tell), asked for JSON. */
@@ -98,7 +100,7 @@ describe("MCP tell refusals", () => {
98100 return ((await res.json()) as { error: string }).error;
99101 };
100102
101 test("the composer and the MCP refuse the same input in the same words", async () => {
103 test("the composer and the MCP refuse an empty tell in the same words; an over-long one names the argument", async () => {
102104 const long = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000);
103105 for (const [text, said] of [
104106 [" ", refusalWords("empty", "")],
@@ -106,7 +108,9 @@ describe("MCP tell refusals", () => {
106108 ] as const) {
107109 const web = await composer(text);
108110 expect(web).toBe(said);
109 expect((await call({ repo: "alice/notes", text })).text).toContain(web);
111 const mcp = (await call({ repo: "alice/notes", text })).text;
112 // An over-long text is the schema's to refuse on the MCP door, naming the argument.
113 expect(mcp).toContain(text === long ? 'argument "text"' : web);
110114 }
111115 app.db.query("UPDATE email_check SET verified_at = NULL").run();
112116 try {
test/mcp-threads.test.ts +1 −1
@@ -165,6 +165,6 @@ describe("the threads tool over MCP", () => {
165165 expect((await tool(aliceRw, { ...base, anchor: 5 })).error).toStartWith("invalid:");
166166 expect((await tool(aliceRw, { ...base, resolved: true })).error).toStartWith("invalid:");
167167 expect((await tool(aliceRw, { repo: "alice/game", number: 9999 })).error).toStartWith("no_such_pull:");
168 expect((await tool(aliceRw, { repo: "alice/game", number: "1" })).error).toStartWith("no_such_pull:");
168 expect((await tool(aliceRw, { repo: "alice/game", number: "1" })).error).toContain('argument "number"');
169169 });
170170 });
test/mcp-variant.test.ts +1 −1
@@ -154,7 +154,7 @@ describe("MCP variant", () => {
154154 for (const answer of ["meh", "", "LIKE"]) {
155155 const r = await call(cyToken, { repo: "cy/lib", number: target.number, answer });
156156 expect(r.error).toBe(true);
157 expect(r.text).toContain("invalid_answer");
157 expect(r.text).toContain('argument "answer"');
158158 }
159159 expect(votes(pub, target.id)).toHaveLength(0);
160160 expect(getPull(app.db, pub.id, target.number)!.state).toBe("open");
test/mcp-wait-for.test.ts +3 −3
@@ -127,9 +127,9 @@ describe("wait_for over MCP", () => {
127127 tool(rw, "wait_for", { app: "alice/game", ...args });
128128 expect((await w({ issue: a, blockedBy: a })).error).toContain("itself");
129129 expect((await w({ issue: a, blockedBy: 9999 })).error).toContain("no_such_issue");
130 expect((await w({ issue: "1", blockedBy: a })).error).toContain("no_such_issue");
131 expect((await w({ issue: a, blockedBy: a + 0.5 })).error).toContain("no_such_issue");
132 expect((await w({ issue: a, blockedBy: 1, stop: "yes" })).error).toContain("invalid_stop");
130 expect((await w({ issue: "1", blockedBy: a })).error).toContain('argument "issue"');
131 expect((await w({ issue: a, blockedBy: a + 0.5 })).error).toContain('argument "blockedBy"');
132 expect((await w({ issue: a, blockedBy: 1, stop: "yes" })).error).toContain('argument "stop"');
133133 expect((await tool(rw, "wait_for", { issue: a, blockedBy: 1 })).error).toBeDefined();
134134 });
135135 });
test/planner-pause-chapter.test.ts +3 −1
@@ -167,7 +167,9 @@ describe("the page and MCP", () => {
167167 expect(done.value.says).toBe("The planner is paused until the open chapter closes.");
168168 expect(pausedUntil(app.db, repo.id, new Date())).not.toBeNull();
169169 for (const bad of [{ action: "resume", chapter: true }, { action: "pause", chapter: true, until: "2099-01-01T00:00:00Z" }, { action: "pause", chapter: false }, { action: "pause", chapter: "yes" }])
170 expect(((await mcp(bad)) as any).error).toContain("chapter is true");
170 // A chapter that is not a boolean is the schema's to refuse; a boolean in the wrong place,
171 // the tool's.
172 expect(((await mcp(bad)) as any).error).toContain(typeof bad.chapter === "boolean" ? "chapter is true" : 'argument "chapter"');
171173 await mcp({ action: "resume", confirm: true });
172174 closeChapter("v4.0.0");
173175 });
test/repo-template-flag.test.ts +4 −3
@@ -163,15 +163,16 @@ describe("the template mark", () => {
163163 });
164164
165165 describe("the same words over the API and the MCP tool", () => {
166 test("junk is bad_template in both, with one sentence", async () => {
166 test("junk is refused in both, the API as bad_template and the tool naming the argument", async () => {
167167 const api = await patch(tok["maker"]!, "starter", { template: "yes" });
168168 const said = (await api.json()) as { error: { code: string; message: string } | string; code?: string; message?: string };
169169 const text = JSON.stringify(said);
170170 expect(text).toContain("bad_template");
171171 expect(text).toContain("template is true or false");
172172 const via = await mcp(tok["maker"]!, { repo: "maker/starter", template: "yes" });
173 expect(via.error).toContain("bad_template");
174 expect(via.error).toContain("template is true or false");
173 // The MCP boundary refuses the wrong type first, naming the argument (#15362).
174 expect(via.error).toContain('argument "template"');
175 expect(via.error).toContain("expected boolean");
175176 });
176177 });
177178
test/spawn-api.test.ts +1 −1
@@ -86,7 +86,7 @@ describe("spawn over the API and MCP", () => {
8686 expect(((await bad.json()) as any).message).toContain("size:");
8787 const viaMcp = await mcp(rw, { name: "kid", apps: ["alice/notes"], size: "huge" });
8888 expect(viaMcp.error).toBe(true);
89 expect(viaMcp.text).toContain("size:");
89 expect(viaMcp.text).toContain('argument "size" is "huge"');
9090 });
9191
9292 test("dry-run is the default: the plan comes back and nothing is made", async () => {
test/spend-words.test.ts +6 −5
@@ -63,32 +63,33 @@ afterAll(async () => {
6363 await rm(dir, { recursive: true, force: true });
6464 });
6565
66 test("a grant out of range answers the module's sentence from the API and MCP", async () => {
66 test("a grant out of range answers the module's sentence from the API and names days over MCP", async () => {
6767 const viaApi = await api("/api/v1/admin/accounts/bob/model-grant", { usdPerMonth: 20000 });
6868 expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.usdPerMonth } });
6969 const viaMcp = await tool("model_grant", { username: "bob", usdPerMonth: 20000, dryRun: false });
7070 expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.usdPerMonth}`) });
7171 });
7272
73 test("a role's allowance out of range answers the module's sentence from the API and MCP", async () => {
73 test("a role's allowance out of range answers the module's sentence from the API and names days over MCP", async () => {
7474 const viaApi = await api("/api/v1/admin/accounts/bob/role", { role: "member", usdPerMonth: 20000 });
7575 expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.usdPerMonth } });
7676 const viaMcp = await tool("account_role", { username: "bob", role: "member", usdPerMonth: 20000, dryRun: false });
7777 expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.usdPerMonth}`) });
7878 });
7979
80 test("a ceiling out of range answers the module's sentence from the API and MCP", async () => {
80 test("a ceiling out of range answers the module's sentence from the API and names days over MCP", async () => {
8181 const viaApi = await api("/api/v1/admin/accounts/bob/ceiling", { dailyUsd: 20000, perRunUsd: 1 });
8282 expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.ceilings } });
8383 const viaMcp = await tool("model_ceiling", { username: "bob", dailyUsd: 20000, perRunUsd: 1, dryRun: false });
8484 expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.ceilings}`) });
8585 });
8686
87 test("an invite's days out of range answers the module's sentence from the API and MCP", async () => {
87 test("an invite's days out of range answers the module's sentence from the API and names days over MCP", async () => {
8888 const viaApi = await api("/api/v1/admin/invites", { days: 31 });
8989 expect(viaApi).toMatchObject({ status: 422, body: { error: "invalid", message: SPEND_WORDS.inviteDays } });
9090 const viaMcp = await tool("mint_invite", { days: 31 });
91 expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining(`invalid: ${SPEND_WORDS.inviteDays}`) });
91 // The MCP holds `days` to its schema's 1 to 30 before the tool runs, naming the argument.
92 expect(viaMcp).toMatchObject({ error: true, text: expect.stringContaining('invalid: argument "days" is 31; expected integer from 1 to 30') });
9293 });
9394
9495 test("no file under src/ but the module types the sentences out", async () => {
test/teams-crew.test.ts +1 −1
@@ -265,7 +265,7 @@ describe("teams drive the crew", () => {
265265 test("MCP org_teams takes a role on add_member, refuses a bad one, and lists members with roles", async () => {
266266 const bad = await mcp(rw, { org: "acme", action: "add_member", team: "Crew", user: "mason", role: "king" });
267267 expect(bad.isError).toBe(true);
268 expect(bad.text).toContain("bad_role");
268 expect(bad.text).toContain('argument "role" is "king"');
269269 const added = await mcp(rw, { org: "acme", action: "add_member", team: "Crew", user: "mason", role: "builder" });
270270 expect(added.isError).toBe(false);
271271 expect(JSON.parse(added.text)).toEqual({ added: true, role: "builder" });
test/usage.test.ts +1 −1
@@ -498,6 +498,6 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
498498 expect(no.result.isError).toBe(true);
499499 expect(no.result.content[0].text).toContain("forbidden");
500500 const odd = await mcp(owner, { repo: "alice/garden", days: "7" });
501 expect(odd.result.content[0].text).toContain("invalid_days");
501 expect(odd.result.content[0].text).toContain('argument "days"');
502502 }, 60_000);
503503 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs