iterate.com / kernel

git clone https://git.iterate.com/repos/kernel

The mind's MCP server tells its client which part of the config's class failed, and run does not wait for the class (#5)

## What

Two fixes to the mind's own MCP server (`iterate.<zone>/mcp`), from client runs on 26 Nov 2026.

1. **The client is told when the mind's MCP config failed.** When a part of the config's class (`mcpTarget`) throws, is late or answers the wrong shape, the server puts one note first in its instructions. When a later list of the tools fails, the note is first in the description of `run` in that list. Before, only the log line `mcp.config-target-failed` said so, and a broken config looked like a mind with no instructions and no skills of its own.
2. **A call of `run` does not wait for the config.** Each `tools/call` asked the class for its tools first, so a slow class added up to 5 seconds to every run. The platform's own `run` needs nothing of the class.

The note, for a class whose `skills()` throws:

```
THIS MIND'S OWN MCP SETTINGS FAILED, and the platform's defaults answer in their place. What failed: skills() threw an error. Tell the person you work for: the mind's own instructions, tools or skills can be missing here. `run` works. The class that failed is in the mind's config repo (`mcp.ts` in the default config), and the mind Worker's log says why (`mcp.config-target-failed`).

<the instructions of the class, or the platform's default>
```

## Why

Jonas, in Slack on 26 Nov 2026, about the answer when the config is broken: "there we would want to append something somewhere that says, by the way, the config worker is broken or this configuration is weird and wrong or something like that, like some diagnostic."

Jonas on the card `tasks/draft-pr-for-skills-over-mcp-support.md` of `/repos/task-board`, 26 Nov 2026 10:39 UTC, to "may I make the three small fixes from the skills test runs (tell every client about the skills, tell the client when the mind's MCP config failed, no 5-second wait on run), yes or no?": "yes". The fix that tells every client about the skills was in the default config's `mcp.ts`, which is not in this repo.

## Before and after

Measured on Beelink against a local fixture that runs `core/mind-worker/src/mcp.ts` and `callMcpTarget` unchanged, before and after these four files' change. The sign-in and the mind behind `run` are not real there.

| Case | Before | After |
|---|---|---|
| A class whose three methods throw: `initialize` | The default instructions alone | The note, then the default instructions |
| The same: `tools/list` | `run` with its default description | `run`, and its description begins with the note |
| The same: does the error's own text reach the client? | Not applicable | No. The answers hold the three fixed reasons alone |
| The same, asked "is anything wrong with this server?" (`claude -p` 2.1.332) | Not tested | The model named the three methods that threw |
| A class that never answers: `tools/call` of `run` | 5,004 ms | 2 ms |
| A class that never answers: `tools/list` | 5,003 ms | 5,003 ms (unchanged: a list needs the class) |
| A class with no fault | No note | No note |

## Risk map

- **The riskiest part is the note's text.** A client hands its instructions and its tool descriptions to a model. So the note holds no word of the config's code: it names one of the three methods (`instructions`, `tools`, `skills`) and one of three reasons that `askConfig` sets ("threw an error", "gave no answer in 5000 ms", "answered what the platform cannot use"). The error's own text stays in the log line. `mcp-config.test.ts` checks that an error's text is in no answer, on the mind's own server and on an app's. Only the mind's own server says the note; an app's server (`auth.mcpServer`) says nothing new.
- **A note can outlive its cause.** A client keeps the instructions for its session, and some clients keep a tool list until a person refreshes it. A class that failed once at that moment leaves the note there until the next connect or refresh.
- **A later failure of `skills()` is not explained.** A `skills/…` or `resources/…` request whose `skills()` fails answers "Method not found", as before.
- **`run` without the class.** `askedOf` now reads the tool's name of a `tools/call`. The class is skipped only when the server is the mind's own and every tools message of the request is a call of `run`. A call of a class's own tool still asks for the tools first. A batch that mixes them asks.
- **Order of the note.** It is first, because Claude Code cuts a server's instructions at 4,096 characters.
- **On merge:** nothing changes until the stack is deployed. A mind whose class works gets the same answers as before.

## Review

`/agents/reviewer` read these changes twice as iterate/private #1429. Its first read found that the note copied the error's own text into the instructions, and that a failed list of the tools carried no note; both are fixed. Its second read, at 4b06b8998 there: "No finding." The four files here have the same bytes as at that commit. #1429 is closed without a merge: `core/` is frozen there.

## Checks

On Beelink at the branch's commit 5bddc52, on main ac30cfa, 26 Nov 2026 15:53 to 15:56 UTC: `pnpm -r --no-bail typecheck` passed for every package, and `pnpm -r --no-bail test` passed: core/lib 1,091 tests, core/itx 538, core/auth-worker 571, core/secrets-worker 418, core/mind-worker 284, core/boundary-worker 241.

Not proven on a deployed mind. The fallback itself was proven on a dev mind for iterate/private #1403. These changes are decisions inside `mcpResponse` and one string.

Session: claude a0593ece-cd2e-4a3b-8174-1286357706db on beelink

jonas, 2026-11-26 15:57 UTC · 4933ddebd2090ead40845ad8ae3d764c2a897c77 · parent ac30cfa

4 files changed

M core/lib/src/mind-config.ts
@@ -66,7 +66,8 @@
      *  that answers an MCP server's class for the client that asks (iterate/sdk `McpServerTarget`):
      *  its instructions, the description of `run`, more tools, and the mind's skills. Absent: the
      *  platform's defaults. Set, and the method fails, is slow or answers what is no such class:
-     *  the failure is logged and the defaults answer. */
+     *  the failure is logged, the defaults answer, and the server tells the client which part
+     *  failed. */
     mcpTarget: z
       .string()
       .regex(/^[A-Za-z_$][\w$]{0,63}$/, "the name of a method")
M core/lib/src/sdk/mcp.ts
@@ -17,7 +17,8 @@
 //   - THE MIND'S OWN MCP SERVER, at its control-plane hostname, for members. The platform serves
 //     it, with its tool `run`. A deploy's config may name a method of the config's class
 //     (`mcpTarget`, iterate/mind-config) that answers the class for a client; what the class says
-//     is added to the platform's defaults, and when it fails the defaults answer alone.
+//     is added to the platform's defaults. When a part of it fails, the default answers for that
+//     part, and the server tells the client which part failed.
 //   - ANY HOST OF THE MIND, from the config's `fetch`: `this.auth.mcpServer(request, { target })`
 //     (./auth.ts) answers for `/mcp` and names the method that answers the class.
 import { RpcTarget } from "cloudflare:workers";
M core/mind-worker/src/mcp-config.test.ts
@@ -218,11 +218,15 @@
   const [defaultRun] = (defaults.result || {}).tools as { name: string; description: string }[];
   expect(defaultRun).toMatchObject({ name: "run" });
 
-  const custom = classOf({
-    instructions: () => "Read the skills first.",
-    tools: () => [{ name: "run", description: "Run, as this mind says." }, { name: "hello" }],
-    hello: () => "hi",
-  });
+  const calls: unknown[][] = [];
+  const custom = classOf(
+    {
+      instructions: () => "Read the skills first.",
+      tools: () => [{ name: "run", description: "Run, as this mind says." }, { name: "hello" }],
+      hello: () => "hi",
+    },
+    calls,
+  );
   expect((await answerOf(await mind(custom, "initialize", INIT))).result).toMatchObject({
     instructions: "Read the skills first.",
   });
@@ -231,6 +235,19 @@
     expect.objectContaining({ name: "run", description: "Run, as this mind says." }),
   ]);
 
+  // A CALL OF `run` ASKS THE CLASS NOTHING: the tool is the platform's, so a slow class holds no
+  // run. A call of the class's own tool asks for its tools, and then calls the method.
+  calls.length = 0;
+  const ran = await answerOf(
+    await mind(custom, "tools/call", { name: "run", arguments: { script: "async () => 1" } }),
+  );
+  expect(ran.result).toHaveProperty("content");
+  expect(calls).toEqual([]);
+  expect(
+    (await answerOf(await mind(custom, "tools/call", { name: "hello", arguments: {} }))).result,
+  ).toMatchObject({ content: [{ type: "text", text: "hi" }], isError: false });
+  expect(calls.map(([, method]) => method)).toEqual(["tools", "hello"]);
+
   const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
   const broken = classOf({
     instructions: () => {
@@ -244,17 +261,76 @@
   await vi.advanceTimersByTimeAsync(6000);
   vi.useRealTimers();
   const init = await answerOf(await pending);
-  expect(init.result?.instructions).toMatch(/^One tool, `run/);
+  // the client is told what failed, before the default instructions
+  const [note, defaultInstructions] = String(init.result?.instructions).split("\n\n");
+  expect(note).toMatch(/^THIS MIND'S OWN MCP SETTINGS FAILED/);
+  expect(note).toContain(
+    "What failed: instructions() threw an error; skills() gave no answer in 5000 ms; tools() answered what the platform cannot use.",
+  );
+  expect(defaultInstructions).toMatch(/^One tool, `run/);
   expect(init.result?.capabilities).not.toHaveProperty("resources");
-  expect((await answerOf(await mind(broken, "tools/list"))).result?.tools).toEqual([
-    expect.objectContaining({ name: "run", description: defaultRun.description }),
+  // A LIST OF THE TOOLS THAT THE CLASS FAILED TO ANSWER has `run` alone, and its description
+  // begins with the note: the instructions do not travel with a list
+  const listed = ((await answerOf(await mind(broken, "tools/list"))).result || {}).tools;
+  expect(listed).toEqual([
+    expect.objectContaining({
+      name: "run",
+      description: expect.stringMatching(
+        /^THIS MIND'S OWN MCP SETTINGS FAILED.* What failed: tools\(\) answered what the platform cannot use\. /,
+      ),
+    }),
   ]);
+  expect(listed).toEqual([
+    expect.objectContaining({ description: expect.stringContaining(defaultRun.description) }),
+  ]);
+  // THE ERROR'S OWN TEXT REACHES NO CLIENT: the config's code wrote it, perhaps from another
+  // party's answer, and a client hands what it gets to a model
+  expect(JSON.stringify([init, listed])).not.toContain("the config broke");
   // each failure is one log line: the initialize asked all three, the list its tools again
   expect(warn.mock.calls.map(([line]) => (line as { what: string }).what).sort()).toEqual([
     "iterate-mind.instructions",
     "iterate-mind.skills",
     "iterate-mind.tools",
     "iterate-mind.tools",
+  ]);
+  warn.mockRestore();
+});
+
+test("the mind's own server tells its client which part of the class failed; an app's server does not", async () => {
+  const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+  const half = classOf({
+    instructions: () => "Read the skills first.",
+    skills: () => {
+      throw new Error("no folder\n  /srv/config/skills");
+    },
+  });
+  // ONE PART FAILS: the note names it in the platform's words, and the class's own instructions
+  // stay
+  const own = await serveMcp(
+    post("initialize", INIT, { "x-itx-principal": JSON.stringify(member) }),
+    () => Promise.reject(new Error("no file is read")),
+    half,
+  ).then(answerOf);
+  expect(own.result?.instructions).toMatch(
+    /^THIS MIND'S OWN MCP SETTINGS FAILED.* What failed: skills\(\) threw an error\. .*\n\nRead the skills first\.$/,
+  );
+  expect(JSON.stringify(own)).not.toContain("/srv/config");
+  // a class that has no such method failed nothing: no note
+  const quiet = await serveMcp(
+    post("initialize", INIT, { "x-itx-principal": JSON.stringify(member) }),
+    () => Promise.reject(new Error("no file is read")),
+    classOf({ instructions: () => "Read the skills first." }),
+  ).then(answerOf);
+  expect(quiet.result?.instructions).toBe("Read the skills first.");
+
+  // AN APP'S SERVER answers people who are no members: the words of the config's code stay in
+  // the log
+  const told = await app(half, "initialize", INIT);
+  expect(told.result?.instructions).toBe("Read the skills first.");
+  expect(JSON.stringify(told)).not.toContain("/srv/config");
+  expect(warn.mock.calls.map(([line]) => (line as { what: string }).what)).toEqual([
+    "iterate-mind.skills",
+    "guestbook.skills",
   ]);
   warn.mockRestore();
 });
M core/mind-worker/src/mcp.ts
@@ -24,7 +24,9 @@
 //
 // THE CONFIG CANNOT BREAK A SERVER. Each thing it is asked (`askConfig`) has a time limit and a
 // schema. What fails, is slow or does not fit is logged, and the default stands: the mind's own
-// server then answers as it does with no `mcpTarget`.
+// server then answers that part as it does with no `mcpTarget`, and its instructions tell the
+// client what failed (`configFailedNote`). A call of the platform's own `run` asks the config
+// nothing, so a slow class holds no run.
 
 /** One call of the config's class for this server: `method` with `args`
  *  (iterate/sdk `IterateConfigEntrypoint.mcpCall`). */
@@ -334,6 +336,9 @@
   instructions?: string;
   tools?: z.infer<typeof ConfigTools>;
   skills?: SkillCatalog;
+  /** Each part that failed, as "<method>() <why>" in the platform's words, on the mind's own
+   *  server alone. */
+  failed?: string[];
 };
 
 const CONFIG_ANSWER_TIMEOUT_MS = 5000;
@@ -369,27 +374,32 @@
 const AnyResult = z.looseObject({});
 
 /** ONE QUESTION TO THE CONFIG'S CLASS, which cannot break the server: its answer within the time
- *  limit and in `schema`'s shape, or undefined, with one log line that says what went wrong. */
+ *  limit and in `schema`'s shape, or undefined, with one log line that says what went wrong.
+ *  `failed` gets why in the platform's own words, one of three. The error's text goes to the log
+ *  alone: the config's code wrote it, and may have copied it from somewhere else. */
 async function askConfig<T>(
   ask: () => Promise<unknown>,
   schema: z.ZodType<T>,
   what: string,
+  failed: (why: string) => void,
 ): Promise<T | undefined> {
   let timer: ReturnType<typeof setTimeout> | undefined;
+  let why = "threw an error";
   try {
     const answer = await Promise.race([
       ask(),
       new Promise<never>((_resolve, reject) => {
-        timer = setTimeout(
-          () => reject(new Error(`no answer in ${CONFIG_ANSWER_TIMEOUT_MS} ms`)),
-          CONFIG_ANSWER_TIMEOUT_MS,
-        );
+        timer = setTimeout(() => {
+          why = `gave no answer in ${CONFIG_ANSWER_TIMEOUT_MS} ms`;
+          reject(new Error(`no answer in ${CONFIG_ANSWER_TIMEOUT_MS} ms`));
+        }, CONFIG_ANSWER_TIMEOUT_MS);
       }),
     ]);
     // the class has no such method: the default stands, and nothing is wrong
     if (!answer) return undefined;
     const parsed = schema.safeParse(answer);
     if (parsed.success) return parsed.data;
+    why = "answered what the platform cannot use";
     throw new Error(`not the expected shape: ${parsed.error.issues[0]?.message || "invalid"}`);
   } catch (error) {
     console.warn({
@@ -397,14 +407,31 @@
       what,
       message: (error instanceof Error ? error.message : String(error)).slice(0, 300),
     });
+    failed(why);
     return undefined;
   } finally {
     clearTimeout(timer);
   }
 }
 
+/** WHAT THE MIND'S OWN SERVER TELLS A CLIENT WHEN THE CONFIG'S CLASS FAILED. Without it a broken
+ *  config looks like a mind that has no instructions, tools or skills of its own, and only the
+ *  log says otherwise. It goes first in the instructions, and first in the description of `run`
+ *  when a list of the tools failed: a client may cut either (Claude Code keeps 4,096 characters
+ *  of the instructions).
+ *
+ *  EVERY WORD OF IT IS THE PLATFORM'S. `failed` names one of the three methods and one of three
+ *  reasons (`askConfig`). An error's own text stays in the log: a client hands these words to its
+ *  model, so text that the config's code took from another party would instruct that model, and
+ *  a secret in it would go to the model's provider.
+ *
+ *  An app's server does not say it: the people it answers can do nothing about the mind's config. */
+const configFailedNote = (failed: string[]) =>
+  `THIS MIND'S OWN MCP SETTINGS FAILED, and the platform's defaults answer in their place. What failed: ${failed.join("; ")}. Tell the person you work for: the mind's own instructions, tools or skills can be missing here. \`run\` works. The class that failed is in the mind's config repo (\`mcp.ts\` in the default config), and the mind Worker's log says why (\`mcp.config-target-failed\`).`;
+
 function buildServer(caller: Caller, served: Served, said: Said, client: McpClient): McpServer {
-  const instructions = said.instructions || (served.run ? runInstructions : undefined);
+  const own = said.instructions || (served.run ? runInstructions : undefined);
+  const instructions = said.failed && own ? `${configFailedNote(said.failed)}\n\n${own}` : own;
   const mcpServer = new McpServer(
     { name: served.name, version: "0.1.0" },
     instructions ? { instructions } : {},
@@ -443,7 +470,11 @@
     "run",
     {
       title: "Run a script",
-      description: said.tools?.find((tool) => tool.name === "run")?.description || runDescription,
+      // a list that the class failed to answer has `run` alone: its description says so
+      description: [
+        ...(said.failed ? [configFailedNote(said.failed)] : []),
+        said.tools?.find((tool) => tool.name === "run")?.description || runDescription,
+      ].join("\n\n"),
       inputSchema: fromJsonSchema(
         {
           type: "object",
@@ -553,17 +584,28 @@
   const said: Said = {};
   const { config } = served;
   if (config) {
+    const failed: string[] = [];
     const say = <T>(method: string, schema: z.ZodType<T>) =>
-      askConfig(() => config(client, method, []), schema, `${served.name}.${method}`);
-    const [instructions, tools, files] = await Promise.all([
+      askConfig(
+        () => config(client, method, []),
+        schema,
+        `${served.name}.${method}`,
+        (why) => failed.push(`${method}() ${why}`),
+      );
+    // A call of the platform's own `run` needs nothing of the class: it does not wait for one
+    // that is slow.
+    const tools = asked.tools && !(served.run && asked.callsRunAlone);
+    const [instructions, toolList, files] = await Promise.all([
       asked.instructions ? say("instructions", ConfigInstructions) : undefined,
       // an initialize says whether the server has tools and skills at all
-      asked.tools || asked.instructions ? say("tools", ConfigTools) : undefined,
+      tools || asked.instructions ? say("tools", ConfigTools) : undefined,
       asked.skills || asked.instructions ? say("skills", ConfigSkillFiles) : undefined,
     ]);
     said.instructions = instructions;
-    said.tools = tools;
+    said.tools = toolList;
     if (files) said.skills = await skillCatalog(files);
+    // in one order, whichever part failed first
+    if (served.run && failed.length > 0) said.failed = failed.sort();
   }
   return createMcpHandler(
     () => buildServer(caller, served, said, client),
@@ -616,13 +658,14 @@
 }
 
 const ClientInfo = z.looseObject({ name: z.string().max(256), version: z.string().max(64) });
-/** One JSON-RPC message, as far as this file reads it before the SDK does: its method, and how
- *  the client named itself (`initialize`'s `clientInfo`, or each call's envelope from MCP
- *  2026-07-28 on). */
+/** One JSON-RPC message, as far as this file reads it before the SDK does: its method, the tool
+ *  a `tools/call` names, and how the client named itself (`initialize`'s `clientInfo`, or each
+ *  call's envelope from MCP 2026-07-28 on). */
 const AskedMessage = z.looseObject({
   method: z.string(),
   params: z
     .looseObject({
+      name: z.string().optional().catch(undefined),
       clientInfo: ClientInfo.optional().catch(undefined),
       _meta: z
         .looseObject({
@@ -647,6 +690,7 @@
     return parsed.success ? [parsed.data] : [];
   });
   const methods = messages.map((message) => message.method);
+  const ofTools = messages.filter((message) => message.method.startsWith("tools/"));
   const named = messages
     .map(
       (message) =>
@@ -656,7 +700,11 @@
   return {
     client: named ? { name: named.name, version: named.version } : {},
     instructions: methods.some((method) => method === "initialize" || method === "server/discover"),
-    tools: methods.some((method) => method.startsWith("tools/")),
+    tools: ofTools.length > 0,
+    /** Every message about tools is a call of the tool named `run`. */
+    callsRunAlone:
+      ofTools.length > 0 &&
+      ofTools.every((message) => message.method === "tools/call" && message.params?.name === "run"),
     skills: methods.some(
       (method) => method.startsWith("skills/") || method.startsWith("resources/"),
     ),