From 8169ccb5439a0292637c38734d69279be6cb5c7f Mon Sep 17 00:00:00 2001 From: Gabriel De Andrade Date: Tue, 24 Nov 2026 11:34:43 -0400 Subject: [PATCH 1/6] feat(server): rare MCP tools load as packs and stop counting against the tool budget Co-Authored-By: Claude Fable 5.2 --- .github/workflows/agent-context-budget.yml | 2 + apps/server/package.json | 1 + apps/server/scripts/mcp-relist-probe.ts | 114 +++++++++++ apps/server/src/mcp/McpHttpServer.test.ts | 19 +- apps/server/src/mcp/McpHttpServer.ts | 9 +- apps/server/src/mcp/McpToolExposure.ts | 63 +++++- apps/server/src/mcp/toolkits/theme/tools.ts | 8 +- .../src/mcp/toolkits/toolSearch/handlers.ts | 9 +- .../src/mcp/toolkits/toolSearch/tools.ts | 7 +- .../src/provider/AgentContextBudget.test.ts | 35 ++-- .../src/provider/agentContextBudget.json | 3 +- docs/internals/03_providers.md | 25 +++ evals/mcp-tool-use/README.md | 9 + evals/mcp-tool-use/cases/tool-search.ndjson | 4 + evals/mcp-tool-use/run.test.ts | 69 +++++++ evals/mcp-tool-use/run.ts | 187 +++++++++++++++--- 16 files changed, 505 insertions(+), 59 deletions(-) create mode 100644 apps/server/scripts/mcp-relist-probe.ts create mode 100644 evals/mcp-tool-use/cases/tool-search.ndjson diff --git a/.github/workflows/agent-context-budget.yml b/.github/workflows/agent-context-budget.yml index a4fe7cb3e88e0..7682bb98e4d92 100644 --- a/.github/workflows/agent-context-budget.yml +++ b/.github/workflows/agent-context-budget.yml @@ -3,6 +3,7 @@ name: Agent Context Budget # Fails when a PR raises a value in agentContextBudget.json above main's. AgentContextBudget.test.ts # keeps that file equal to the measured context, so the context cannot grow by editing the file. # To accept growth on purpose, a maintainer adds the agent-context-increase label. +# mcpPackToolListJsonBytes is recorded, not gated: pack tools load on demand (McpToolExposure.ts). on: pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] @@ -40,6 +41,7 @@ jobs: git show "HEAD^1:$BUDGET" > "$RUNNER_TEMP/main.json" grown=$(jq -r --slurpfile main "$RUNNER_TEMP/main.json" ' to_entries[] + | select(.key != "mcpPackToolListJsonBytes") | select($main[0][.key] != null and .value > $main[0][.key]) | "\(.key): \($main[0][.key]) -> \(.value) (+\(.value - $main[0][.key]))" ' "$BUDGET") diff --git a/apps/server/package.json b/apps/server/package.json index 780cc64f0b2e5..6bc98e86c06ca 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -31,6 +31,7 @@ "record:fx-replay": "node scripts/record-fx-acp-replay-fixture.ts", "record:kiro-replay": "node scripts/record-kiro-acp-replay-fixture.ts", "record:muse-replay": "node scripts/record-muse-msp-replay-fixture.ts", + "probe:mcp-relist": "node scripts/mcp-relist-probe.ts", "generate": "graphqlgen", "generate:expo-schema": "node scripts/fetch-expo-schema.ts" }, diff --git a/apps/server/scripts/mcp-relist-probe.ts b/apps/server/scripts/mcp-relist-probe.ts new file mode 100644 index 0000000000000..9476c7383484d --- /dev/null +++ b/apps/server/scripts/mcp-relist-probe.ts @@ -0,0 +1,114 @@ +// Serves T3's real MCP transport with a hidden tool, to see whether a harness lists tools again +// after `tool_search`, before T3 defers tools for it (docs/internals/03_providers.md). +// @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer.layer takes Node's createServer. +import * as NodeHttp from "node:http"; + +import { NodeHttpServer, NodeRuntime } from "@effect/platform-node"; +import * as NodeServices from "@effect/platform-node/NodeServices"; +import { + EnvironmentId, + OrchestratorMcpFailure, + ProviderInstanceId, + ThreadId, +} from "@t3tools/contracts"; +import * as Console from "effect/Console"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import * as Logger from "effect/Logger"; +import * as References from "effect/References"; +import * as Schema from "effect/Schema"; +import { Tool, Toolkit } from "effect/ai"; +import { Command, Flag } from "effect/cli"; +import { HttpRouter } from "effect/http"; + +import * as McpHttpServer from "../src/mcp/McpHttpServer.ts"; +import type * as McpInvocationContext from "../src/mcp/McpInvocationContext.ts"; +import * as McpSessionRegistry from "../src/mcp/McpSessionRegistry.ts"; +import * as McpToolAccess from "../src/mcp/McpToolAccess.ts"; +import * as McpToolAccessTestkit from "../src/mcp/McpToolAccess.testkit.ts"; +import * as ServerSettings from "../src/serverSettings.ts"; + +const token = "probe"; +const code = "plum-4471"; + +const scope: McpInvocationContext.McpThreadInvocationScope = { + environmentId: EnvironmentId.make("probe"), + requestNamespace: token, + thread: { + threadId: ThreadId.make("probe-thread"), + providerSessionId: token, + providerInstanceId: ProviderInstanceId.make("probe"), + }, + client: undefined, + capabilities: new Set(["orchestration"]), + issuedAt: 1, +}; + +const ProbeToolkit = Toolkit.make( + Tool.make("delegate_task", { + description: "Not part of this probe. Do not call.", + success: Schema.Struct({}), + failure: OrchestratorMcpFailure, + failureMode: "return", + }), + Tool.make("probe_secret", { + description: "Returns the probe's secret code.", + success: Schema.Struct({ code: Schema.String }), + failure: OrchestratorMcpFailure, + failureMode: "return", + }) + // Read-only, so a harness in a no-approval mode still runs it. + .annotate(Tool.Readonly, true) + .annotate(Tool.Destructive, false), +); + +const served = McpHttpServer.layerMcpTransport( + Layer.mergeAll( + McpHttpServer.toolkitRegistration( + ProbeToolkit, + McpToolAccess.toLayer(ProbeToolkit, { + delegate_task: McpToolAccess.reads(() => Effect.succeed({})), + probe_secret: McpToolAccess.reads(() => + Effect.log("probe: the model called the hidden tool").pipe(Effect.as({ code })), + ), + }), + ), + McpHttpServer.layerToolSearch, + ), +).pipe( + Layer.provide(ServerSettings.layerTest()), + Layer.provide(McpToolAccessTestkit.liveThreadsLayer), + Layer.provide( + Layer.mock(McpSessionRegistry.McpSessionRegistry)({ + resolve: (candidate) => Effect.succeed(candidate === token ? scope : undefined), + }), + ), +); + +const command = Command.make( + "mcp-relist-probe", + { port: Flag.Int("port").pipe(Flag.withDefault(8787)) }, + ({ port }) => + Console.log(`MCP endpoint: http://127.0.0.1:${port}/mcp +Headers: "Authorization: Bearer ${token}" and "t3-tool-exposure: deferred" +Prompt: Find the tool that returns the probe's secret code, call it, and reply with the code. +Pass: a "mcp.tool-search.relisted" line, then "the model called the hidden tool" in one turn. +Restart this server for each run: a search stays loaded for the life of the process. +`).pipe( + Effect.andThen( + HttpRouter.serve(served, { disableListenLog: true }).pipe( + Layer.provide(NodeHttpServer.layer(NodeHttp.createServer, { port, host: "127.0.0.1" })), + Layer.provide(Logger.layer([Logger.consolePretty()])), + Layer.provide(Layer.succeed(References.MinimumLogLevel, "Debug")), + Layer.launch, + ), + ), + ), +); + +if (import.meta.main) { + Command.run(command, { version: "0.0.0" }).pipe( + Effect.provide(NodeServices.layer), + NodeRuntime.runMain, + ); +} diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts index 3b2cb665b3548..2af86f327be1e 100644 --- a/apps/server/src/mcp/McpHttpServer.test.ts +++ b/apps/server/src/mcp/McpHttpServer.test.ts @@ -56,6 +56,7 @@ import * as ServerSettings from "../serverSettings.ts"; import { advertisedJsonSchema } from "./advertisedJsonSchema.ts"; import * as McpHttpServer from "./McpHttpServer.ts"; import * as McpToolAccess from "./McpToolAccess.ts"; +import * as McpToolExposure from "./McpToolExposure.ts"; import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts"; import * as McpInvocationContext from "./McpInvocationContext.ts"; import * as McpSessionRegistry from "./McpSessionRegistry.ts"; @@ -2149,6 +2150,7 @@ it.effect("lists optional tools to a deferring client only after tool_search loa tool("delegate_task", "Delegates a task."), tool("preview_open", "Opens a browser preview."), tool("schedule_task", "Schedules a task."), + tool("t3_theme_set", "Restyles T3 Code.").annotate(McpToolExposure.Pack, "customization"), ); const reads = McpToolAccess.reads(() => Effect.succeed({})); const serverLayer = McpHttpServer.layerMcpTransport( @@ -2159,6 +2161,7 @@ it.effect("lists optional tools to a deferring client only after tool_search loa delegate_task: reads, preview_open: reads, schedule_task: reads, + t3_theme_set: reads, }), ), McpHttpServer.layerToolSearch, @@ -2232,7 +2235,8 @@ it.effect("lists optional tools to a deferring client only after tool_search loa const deferring = yield* session("deferringToken", true); const other = yield* session("otherToken", false); expect(yield* deferring.listed).toEqual(["delegate_task", "tool_search"]); - expect(yield* other.listed).toEqual(["delegate_task", "preview_open", "schedule_task"]); + const everything = ["delegate_task", "preview_open", "schedule_task", "t3_theme_set"]; + expect(yield* other.listed).toEqual(everything); // Unlisted tools stay callable. expect((yield* deferring.call("schedule_task", {})).structuredContent).toEqual({}); @@ -2240,7 +2244,18 @@ it.effect("lists optional tools to a deferring client only after tool_search loa (yield* deferring.call("tool_search", { query: "browser" })).structuredContent, ).toEqual({ tools: [{ name: "preview_open", description: "Opens a browser preview." }] }); expect(yield* deferring.listed).toEqual(["delegate_task", "preview_open", "tool_search"]); - expect(yield* other.listed).toEqual(["delegate_task", "preview_open", "schedule_task"]); + expect(yield* other.listed).toEqual(everything); + + // A pack's name loads its tools, whatever their text says. + expect( + (yield* deferring.call("tool_search", { query: "customization" })).structuredContent, + ).toEqual({ tools: [{ name: "t3_theme_set", description: "Restyles T3 Code." }] }); + expect(yield* deferring.listed).toEqual([ + "delegate_task", + "preview_open", + "t3_theme_set", + "tool_search", + ]); }), ).pipe(Effect.provide(NodeHttpServer.layerTest)), ); diff --git a/apps/server/src/mcp/McpHttpServer.ts b/apps/server/src/mcp/McpHttpServer.ts index 2b1deed86f037..59388e831a8d6 100644 --- a/apps/server/src/mcp/McpHttpServer.ts +++ b/apps/server/src/mcp/McpHttpServer.ts @@ -1540,7 +1540,11 @@ const layerToolExposure = Layer.effect( enabledWhen === undefined || enabledWhen({ protocolVersion: "", capabilities: {} }) ); }) - .map(({ tool }) => ({ name: tool.name, description: tool.description ?? "" })), + .map(({ tool, annotations }) => ({ + name: tool.name, + description: tool.description ?? "", + pack: Context.getOrUndefined(annotations, McpToolExposure.Pack), + })), () => server.notifications["notifications/tools/list_changed"]({}), ); }), @@ -1562,6 +1566,9 @@ const layerDeferredListing = McpServer.visibility( if (headers[MCP_TOOL_EXPOSURE_HEADER] !== "deferred" || providerSessionId === undefined) { return target !== McpToolExposure.TOOL_SEARCH; } + if (exposure.relisted(providerSessionId)) { + yield* Effect.logDebug("mcp.tool-search.relisted", { providerSessionId }); + } return exposure.isListed(providerSessionId, target); }); }), diff --git a/apps/server/src/mcp/McpToolExposure.ts b/apps/server/src/mcp/McpToolExposure.ts index cb1ff850717d1..390ac0139741a 100644 --- a/apps/server/src/mcp/McpToolExposure.ts +++ b/apps/server/src/mcp/McpToolExposure.ts @@ -15,9 +15,28 @@ const MAX_RESULTS = 10; // Sessions that ended are never reported here, so keep only the newest. const MAX_SESSIONS = 256; +/** + * Tools for a job few threads do. `tool_search` with the pack's name loads all of + * them, and they stay outside the gated tool budget (AgentContextBudget.test.ts). + */ +export const PACKS = { + customization: "restyle T3 Code itself", +} as const; + +export type PackName = keyof typeof PACKS; + +/** Tool annotation that puts a tool in a pack. */ +export class Pack extends Context.Service()("t3/mcp/McpToolExposure/Pack") {} + export interface ListedTool { readonly name: string; readonly description: string; + readonly pack?: PackName | undefined; +} + +export interface ToolSearchCaller { + readonly providerSessionId: string; + readonly providerInstanceId: string; } export class McpToolExposure extends Context.Service< @@ -25,10 +44,12 @@ export class McpToolExposure extends Context.Service< { /** Finds tools for the query and lists them to the session from now on. */ readonly search: ( - providerSessionId: string, + caller: ToolSearchCaller, query: string, ) => Effect.Effect>; readonly isListed: (providerSessionId: string, tool: string) => boolean; + /** True once, when the session lists tools for the first time after a search loaded some. */ + readonly relisted: (providerSessionId: string) => boolean; } >()("t3/mcp/McpToolExposure") {} @@ -57,31 +78,55 @@ export const make = ( for (const oldest of loaded.keys()) { if (loaded.size <= MAX_SESSIONS) break; loaded.delete(oldest); + awaitingRelist.delete(oldest); + relisters.delete(oldest); } }; + // Sessions whose last search loaded tools and that have not listed tools since. + const awaitingRelist = new Set(); + // A harness that lists lazily can search twice before it lists, so only warn about + // sessions that have never listed after a search. + const relisters = new Set(); return McpToolExposure.of({ - search: Effect.fn("McpToolExposure.search")(function* (providerSessionId, query) { + search: Effect.fn("McpToolExposure.search")(function* (caller, query) { + const { providerSessionId } = caller; const terms = query .toLowerCase() .split(/[^a-z0-9_]+/u) .filter(Boolean); - const found = tools() - .filter((tool) => tool.name !== TOOL_SEARCH) - .map((tool) => ({ tool, score: score(tool, terms) })) - .filter((match) => match.score > 0) - .sort((a, b) => b.score - a.score) - .slice(0, MAX_RESULTS) - .map((match) => match.tool); + const candidates = tools().filter((tool) => tool.name !== TOOL_SEARCH); + const inNamedPack = (tool: ListedTool) => + tool.pack !== undefined && terms.includes(tool.pack); + const found = [ + ...candidates.filter(inNamedPack), + ...candidates + .filter((tool) => !inNamedPack(tool)) + .map((tool) => ({ tool, score: score(tool, terms) })) + .filter((match) => match.score > 0) + .sort((a, b) => b.score - a.score) + .slice(0, MAX_RESULTS) + .map((match) => match.tool), + ]; + if (awaitingRelist.has(providerSessionId) && !relisters.has(providerSessionId)) { + // The harness ignored list_changed, so its model cannot see what the search loads. + yield* Effect.logWarning("mcp.tool-search.not-relisted", caller); + } if (found.length > 0) { load( providerSessionId, found.map((tool) => tool.name), ); + awaitingRelist.add(providerSessionId); yield* announceListChanged(); } return found; }), isListed: (providerSessionId, tool) => DIRECT_TOOLS.has(tool) || loaded.get(providerSessionId)?.has(tool) === true, + relisted: (providerSessionId) => { + if (!awaitingRelist.delete(providerSessionId)) return false; + relisters.add(providerSessionId); + return true; + }, }); }; diff --git a/apps/server/src/mcp/toolkits/theme/tools.ts b/apps/server/src/mcp/toolkits/theme/tools.ts index 716c540b2c41e..7f82544531131 100644 --- a/apps/server/src/mcp/toolkits/theme/tools.ts +++ b/apps/server/src/mcp/toolkits/theme/tools.ts @@ -8,6 +8,7 @@ import * as Schema from "effect/Schema"; import { Tool, Toolkit } from "effect/ai"; import * as EnvironmentTheme from "../../../environmentTheme.ts"; import * as McpInvocationContext from "../../McpInvocationContext.ts"; +import * as McpToolExposure from "../../McpToolExposure.ts"; import * as ThreadCommandExecutor from "../../../orchestration-v2/ThreadCommandExecutor.ts"; import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts"; @@ -50,7 +51,8 @@ const ThemeReadTool = Tool.make("t3_theme_read", { }), }) .annotate(Tool.Readonly, true) - .annotate(Tool.Destructive, false); + .annotate(Tool.Destructive, false) + .annotate(McpToolExposure.Pack, "customization"); const ThemeSetTool = Tool.make("t3_theme_set", { ...shared, @@ -66,6 +68,8 @@ const ThemeSetTool = Tool.make("t3_theme_set", { appearance: Schema.optionalKey(Appearance), published: Schema.Boolean, }), -}).annotate(Tool.Destructive, true); +}) + .annotate(Tool.Destructive, true) + .annotate(McpToolExposure.Pack, "customization"); export const ThemeToolkit = Toolkit.make(ThemeReadTool, ThemeSetTool); diff --git a/apps/server/src/mcp/toolkits/toolSearch/handlers.ts b/apps/server/src/mcp/toolkits/toolSearch/handlers.ts index 649069fbc1adb..5a04b13f6be14 100644 --- a/apps/server/src/mcp/toolkits/toolSearch/handlers.ts +++ b/apps/server/src/mcp/toolkits/toolSearch/handlers.ts @@ -12,7 +12,14 @@ export const layer = McpToolAccess.toLayer(ToolSearchToolkit, { Effect.flatMap((scope) => McpInvocationContext.requireThreadScope(scope, "tool_search")), ); const exposure = yield* McpToolExposure.McpToolExposure; - return { tools: yield* exposure.search(thread.providerSessionId, query) }; + const found = yield* exposure.search( + { + providerSessionId: thread.providerSessionId, + providerInstanceId: thread.providerInstanceId, + }, + query, + ); + return { tools: found.map(({ name, description }) => ({ name, description })) }; }), ), }); diff --git a/apps/server/src/mcp/toolkits/toolSearch/tools.ts b/apps/server/src/mcp/toolkits/toolSearch/tools.ts index 74741ccca557d..8e05d794867fe 100644 --- a/apps/server/src/mcp/toolkits/toolSearch/tools.ts +++ b/apps/server/src/mcp/toolkits/toolSearch/tools.ts @@ -5,9 +5,12 @@ import { McpSchema, Tool, Toolkit } from "effect/ai"; import * as McpInvocationContext from "../../McpInvocationContext.ts"; import * as McpToolExposure from "../../McpToolExposure.ts"; +const packList = Object.entries(McpToolExposure.PACKS) + .map(([name, purpose]) => `\`${name}\` (${purpose})`) + .join(", "); + const ToolSearchTool = Tool.make(McpToolExposure.TOOL_SEARCH, { - description: - "Load T3 Code tools you do not have yet, then call them by name. Search by name or purpose: threads (t3_thread_*), projects (t3_project_*), worktrees, preview_* browser, device_*, html_preview/html_render, schedule_task, pull requests and guides, attachments, request_secret, environment links. Exact names work too.", + description: `Load T3 Code tools you do not have yet, then call them by name. Search by name or purpose: threads (t3_thread_*), projects (t3_project_*), worktrees, preview_* browser, device_*, html_preview/html_render, schedule_task, pull requests and guides, attachments, request_secret, environment links. Exact names work too. A pack name loads its whole set: ${packList}.`, parameters: Schema.Struct({ query: Schema.String.check(Schema.isMaxLength(500)) }), success: Schema.Struct({ tools: Schema.Array(Schema.Struct({ name: Schema.String, description: Schema.String })), diff --git a/apps/server/src/provider/AgentContextBudget.test.ts b/apps/server/src/provider/AgentContextBudget.test.ts index ad8593c387528..882d305d6b403 100644 --- a/apps/server/src/provider/AgentContextBudget.test.ts +++ b/apps/server/src/provider/AgentContextBudget.test.ts @@ -4,6 +4,7 @@ import { expect, it } from "@effect/vitest"; import { ProviderInstanceId } from "@t3tools/contracts"; import { McpProviderSessions } from "@t3tools/provider-core/server/McpProviderSessions"; import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; +import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import { McpServer } from "effect/ai"; @@ -17,6 +18,7 @@ import { GitManager } from "../git/GitManager.ts"; import { GitWorkflowService } from "../git/GitWorkflowService.ts"; import { TaskFolders } from "../workspace/TaskFolders.ts"; import * as McpHttpServer from "../mcp/McpHttpServer.ts"; +import * as McpToolExposure from "../mcp/McpToolExposure.ts"; import { PreviewAutomationBroker } from "../mcp/PreviewAutomationBroker.ts"; import { CLAUDE_PROVIDER, @@ -147,24 +149,35 @@ it.effect("only request_secret and send_to_user ask Claude Code to load them up }).pipe(Effect.provide(layerAdvertisedTools)), ); -// CI rejects a PR that raises any value above main's agentContextBudget.json, so growth +// CI rejects a PR that raises a gated value above main's agentContextBudget.json, so growth // needs the agent-context-increase label. Lower the values when the text shrinks. +// mcpPackToolListJsonBytes is recorded but not gated: harnesses that defer tools never list +// a pack up front, and the eager ones are the fallback (docs/internals/03_providers.md). it.effect("agent context matches the committed budget", () => Effect.gen(function* () { const mcp = yield* McpServer.McpServer; + // The model sees these fields. outputSchema and annotations are protocol metadata. + const toolListBytes = (inPack: boolean) => + utf8Bytes( + JSON.stringify( + mcp.tools + .filter( + ({ annotations }) => + (Context.getOrUndefined(annotations, McpToolExposure.Pack) !== undefined) === + inPack, + ) + .map(({ tool }) => ({ + name: tool.name, + description: tool.description, + inputSchema: tool.inputSchema, + })), + ), + ); const measured = { claudeSystemAppendBytes: utf8Bytes(claudeSystemAppend()), codexAdditionalContextBytes: utf8Bytes(codexAdditionalContext()), - // The model sees these fields. outputSchema and annotations are protocol metadata. - mcpToolListJsonBytes: utf8Bytes( - JSON.stringify( - mcp.tools.map(({ tool }) => ({ - name: tool.name, - description: tool.description, - inputSchema: tool.inputSchema, - })), - ), - ), + mcpToolListJsonBytes: toolListBytes(false), + mcpPackToolListJsonBytes: toolListBytes(true), }; expect( diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 4089b32f80569..2726d8f559818 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,6 @@ { "claudeSystemAppendBytes": 6245, "codexAdditionalContextBytes": 7639, - "mcpToolListJsonBytes": 61844 + "mcpToolListJsonBytes": 60616, + "mcpPackToolListJsonBytes": 1229 } diff --git a/docs/internals/03_providers.md b/docs/internals/03_providers.md index 4b4d781a12d58..7d9f4e4b5e110 100644 --- a/docs/internals/03_providers.md +++ b/docs/internals/03_providers.md @@ -57,6 +57,31 @@ clients read declared capabilities, never provider names. bypass a provider's sandbox or approval rules. - **T3 MCP tools.** Inject the thread's authenticated MCP server so agents can reach T3 tools, and keep turns working if that server is unreachable. +- **Listing tools on demand needs a harness that lists again.** T3 can list only a few tools and + reveal the rest through `tool_search` (`deferMcpTools`). That works only when the harness calls + `tools/list` again after `notifications/tools/list_changed`, which arrives in the SSE body of the + `tool_search` response, and gives its model the new tools in the same turn. Many harnesses do not: + Cursor reads tools once per run, and Codex ignores the notification unless a feature flag is on. + The full list is therefore the default. Turn deferral on for a harness only after it passes + [`mcp-relist-probe.ts`](../../apps/server/scripts/mcp-relist-probe.ts); a harness that fails is + left with four tools. + + What each harness did when last checked (2026-11-23). Re-run the probe rather than trust a row. + + | Harness | Lists again after `list_changed` | Today | Known from | + | ------------ | ------------------------------------------------------------------------------------ | ------------------------- | ------------------ | + | Claude Code | Yes, same turn | Its own ToolSearch | Probe | + | Codex | Only with `features.mcp_tool_list_changed` | Its own tool search | Probe | + | Copilot CLI | Yes, same turn | T3's `tool_search` | Probe (#34245) | + | Pi | No: T3's extension lists once | Pi's own `tool_search` | Source | + | OpenCode | Yes, same turn; the next step can race it | Full list | Source, not probed | + | Antigravity | Yes; same turn unknown | Full list | Binary symbols | + | Kiro | Unknown; its open-source ancestor did | Full list | Strings | + | Grok | Unknown | Full list | Strings | + | fx | Not from a POST response; yes over stdio | Full list | Source | + | Cursor | No: tools are read once per run | Full list | Bundle | + | Muse Code | Unknown | Full list | Strings | + | ACP Registry | Gemini CLI, Goose, Kilo, fast-agent, Kimchi do; Qwen Code, Kimi, Mistral Vibe do not | Full list, except Copilot | Source | ## Model manifest diff --git a/evals/mcp-tool-use/README.md b/evals/mcp-tool-use/README.md index 4d0a5b011b73d..9c7693e72cf58 100644 --- a/evals/mcp-tool-use/README.md +++ b/evals/mcp-tool-use/README.md @@ -27,11 +27,20 @@ Cases are JSON lines in `cases/`, one file per area. The case schema in `run.ts` - `kind`: `bad` reproduces a mistake, `guard` protects correct behavior, `control` is ordinary work. - `experience`: the real mistake, in a sentence. `source`: where it happened. - `setup`: the fake thread, its `world` (repo, branch, files, PRs, pages), `priorTurns`, and `mocks` for tool results. With `world.backgroundTasks`, `t3_background_wait` answers from T3's own handler and ThreadManagementService, so its result and errors are the checkout's; a prior wait with `"result": "default"` gets that result too. +- `setup.toolExposure: "t3_tool_search"` uses the Claude template with ACP prompt instructions and T3's server-side deferred MCP listing. These cases run on Claude models. - `setup.priorTurns[].toolCalls[].resultFile`: load a repository-relative file as the tool result instead of copying its contents into the case. An empty `prompt` resumes a top-level thread after its last prior tool result without adding a user message. Side-chat and subagent setups require a nonempty prompt. - `expect`: the checks, such as `calls`, `callsMustNot`, `maxCalls`, `order`, `shellMust`, `textMust`, `finalTextMust` (the last text, once the turn ended), and `linked`. A call's `args` match partially: `~text` is a case-insensitive substring, `re:` a case-sensitive regex, `"<=N"` / `">=N"` bound a number, `null` matches a missing key, and keys may be dotted paths. For `calls` and `callsMustNot`, `argsAnyOf` accepts any one of its partial argument objects, in addition to `args`. Only `calls` supports `success: true`, which requires a recorded successful result. `distinctCalls` supports only `tool` and `args`. Device cases also use `device` to check every child brief, forbid raw UI commands, bound failed device actions per user turn, and require artifact paths in completed final answers. Secrets cases use `secret` (see [Secrets cases](#secrets-cases)). Check that the case builds with `--dry-run --case `. Then run it on the text before your fix, where it must fail, and on the text after, where it must pass. +## Server-side tool search cases + +`cases/tool-search.ndjson` checks discovery of customization and preview tools, with ordinary file edits and project theme edits as controls. The first request includes T3's direct tools, including `tool_search`. Claude's native `ToolSearch` serves only the template's native deferred tools. The runner uses T3's search implementation and exposes the newly listed schemas on the next model request. + +Claude stands in for models used by ACP harnesses. The runner assumes the harness re-lists tools within the same turn after a search, so these cases measure the model's routing decisions. Harness support for re-listing requires separate verification. A search that finds tools answers with tool references instead of its JSON result: the API rejects text beside references, and a plain change to the tool list unbinds earlier thinking blocks. + +On Sonnet 5.5 at 3 samples, `t3-tool-search-theme-pack` passed 0/3 with the `tool_search` description that named no packs and 3/3 with the pack list (2026-11-23). `t3-tool-search-preview-open` passed 3/3 on both, and the two controls passed 3/3 with the pack list. + ## Device manager cases `cases/device-manager.ndjson` ports nine mechanisms from the [device-routing investigation described in #25661](https://github.com/pingdotgg/t3code/pull/25661) and adds seven cases from t3dotgg’s 2026-10-26 fleet device investigation. All prompts, files, hosts and prior turns are authored Acme data; the fleet cases cite finding ids without carrying source transcripts or identifiers. diff --git a/evals/mcp-tool-use/cases/tool-search.ndjson b/evals/mcp-tool-use/cases/tool-search.ndjson new file mode 100644 index 0000000000000..3b0c4a6f6d8e0 --- /dev/null +++ b/evals/mcp-tool-use/cases/tool-search.ndjson @@ -0,0 +1,4 @@ +{"id": "t3-tool-search-theme-pack", "area": "tool-search", "kind": "bad", "pattern": "restyle T3 Code itself", "experience": "In a session that lists T3 tools on demand, tool_search's description named no theme tools, so an agent asked to restyle T3 Code never searched for them. It should load the customization pack, read the theme guide, then publish the theme.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}, "setup": {"role": "top", "mocks": {"t3_theme_read": {"current": "", "builtIn": ["t3-chat", "grove", "ocean", "ember", "iris"], "published": [], "guide": "Themes restyle T3 Code on web and desktop. `canvas` and `accent` (hex) derive a full palette. `css` applies after the app's styles."}, "t3_theme_set": {"themeId": "night-terminal", "published": true}}, "toolExposure": "t3_tool_search"}, "prompt": "Make T3 Code itself look like a late-night terminal: near-black background with a green accent.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "t3_theme_read", "success": true}, {"tool": "t3_theme_set", "args": {"theme.appearance": "dark"}, "success": true}], "order": ["tool_search", "t3_theme_read", "t3_theme_set"]}, "maxSteps": 8} +{"id": "t3-tool-search-preview-open", "kind": "guard", "pattern": "discover an optional browser tool", "experience": "A request to open the running app in the shared preview still works when the harness defers T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "report": "Maintainer field review, 2026-11: Claude threads whose project CLAUDE.md named a browser CLI that was not installed fell back to ad hoc Playwright for requested browser work"}, "setup": {"role": "top", "world": {"repo": "acme/app", "processes": "The Acme web dev server is running and http://localhost:3000/ answers 200."}, "mocks": {"preview_status": {"available": false, "visible": false, "tabId": null, "url": null, "title": null, "loading": false, "profiles": [{"id": "default", "name": "Default"}, {"id": "incognito", "name": "Incognito", "incognito": true}], "defaultProfileId": "default"}, "preview_open": {"available": true, "visible": true, "tabId": "tab_1", "url": "http://localhost:3000/", "title": "Acme", "loading": false, "control": {"owner": "agent", "ownedByCaller": true, "generation": 1}}}, "toolExposure": "t3_tool_search"}, "prompt": "Open http://localhost:3000/ in the T3 Code preview browser and leave it open.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "preview_open", "success": true}], "order": ["tool_search", "preview_open"]}, "maxSteps": 8, "area": "tool-search", "privacy": "commit-safe"} +{"id": "t3-tool-search-control-file-edit", "kind": "control", "pattern": "a routine project file edit", "experience": "Ordinary coding work uses the harness's editing tools without discovering T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "note": "Control for the server-side tool search introduced for Copilot."}, "setup": {"role": "top", "world": {"repo": "acme/app", "files": {"src/retry.ts": "export const retryLimit = 2;\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change retryLimit from 2 to 3 in src/retry.ts.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/retry.ts", "new_string": "~3"}, {"file_path": "~src/retry.ts", "content": "~retryLimit = 3"}, {"command": "~retryLimit = 3"}]}], "notCalls": ["tool_search"]}, "maxSteps": 6, "area": "tool-search", "privacy": "commit-safe"} +{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} diff --git a/evals/mcp-tool-use/run.test.ts b/evals/mcp-tool-use/run.test.ts index 2bbb8b426e3bb..102b7367c5c73 100644 --- a/evals/mcp-tool-use/run.test.ts +++ b/evals/mcp-tool-use/run.test.ts @@ -24,6 +24,7 @@ import { gradeSample, modelRequests, makeSample, + relistT3Tools, ranCalls, McpToolUseCase, savesPastedSecrets, @@ -733,6 +734,74 @@ it("rebuilds the template from this checkout and sends a child T3's task prompt" assert.notEqual(prompt?.text, childCase.prompt); }); +it.effect("re-lists T3 search results for the next model request", () => + Effect.gen(function* () { + const config = { + apiKey: "", + model: "claude-sonnet-5-5", + effort: "high", + maxSteps: 6, + shellModel: "claude-haiku-5-5", + } as const; + const base = buildBase(template, { + model: config.model, + keepUserInstructions: false, + t3Deferred: true, + }); + const testCase: McpToolUseCase = { + ...childCase, + setup: { role: "top", toolExposure: "t3_tool_search" }, + }; + const sample = makeSample(testCase, base); + assert.deepEqual( + sample.tools + .filter((tool) => tool.name.startsWith("mcp__t3-code__")) + .map((tool) => normalizeToolName(tool.name)), + ["orchestrator_capabilities", "delegate_task", "task_status", "tool_search"], + ); + assert.notInclude(base.system.map((block) => block.text).join("\n"), "mcp__t3-code__"); + assert.include( + String(buildMessages(sample)[0]?.content.at(-1)?.text), + "", + ); + const call = (name: string, input: unknown) => + answerToolCall(sample, config, { type: "tool_use", id: "test", name, input }); + const native = yield* call("mcp__host__clown_ToolSearch", { + query: "select:mcp__t3-code__t3_theme_read", + }); + assert.equal(native.content, "No matching deferred tools found"); + + const themeSearch = yield* call("mcp__t3-code__tool_search", { query: "customization" }); + assert.isFalse(themeSearch.is_error === true); + assert.deepEqual(themeSearch.content, [ + { type: "tool_reference", tool_name: "mcp__t3-code__t3_theme_read" }, + { type: "tool_reference", tool_name: "mcp__t3-code__t3_theme_set" }, + ]); + const prematureCall = yield* call("mcp__t3-code__t3_theme_read", {}); + assert.isTrue(prematureCall.is_error); + assert.include(String(prematureCall.content), "Load it with mcp__t3-code__tool_search first"); + + relistT3Tools(sample); + const themeTool = sample.tools.find((tool) => tool.name === "mcp__t3-code__t3_theme_read"); + assert.isDefined(themeTool?.input_schema); + assert.isTrue(themeTool?.defer_loading); + const previewSearch = yield* call("mcp__t3-code__tool_search", { query: "preview_open" }); + assert.deepInclude(previewSearch.content, { + type: "tool_reference", + tool_name: "mcp__t3-code__preview_open", + }); + relistT3Tools(sample); + assert.include( + sample.tools.map((tool) => tool.name), + "mcp__t3-code__preview_open", + ); + assert.notInclude( + makeSample(testCase, base).tools.map((tool) => tool.name), + "mcp__t3-code__preview_open", + ); + }).pipe(Effect.provide(FetchHttpClient.layer)), +); + it("lists link tools only while a case turns the beta on, and sends chips as T3 projects them", () => { const off = buildBase(template, { model: "claude-sonnet-5-5", keepUserInstructions: false }); const on = buildBase(template, { diff --git a/evals/mcp-tool-use/run.ts b/evals/mcp-tool-use/run.ts index f54f6e520c43d..e8f184410de62 100644 --- a/evals/mcp-tool-use/run.ts +++ b/evals/mcp-tool-use/run.ts @@ -40,6 +40,7 @@ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http"; import { taskPrompt } from "../../apps/server/src/mcp/delegatedTaskModes.ts"; import * as McpInvocationContext from "../../apps/server/src/mcp/McpInvocationContext.ts"; +import * as McpToolExposure from "../../apps/server/src/mcp/McpToolExposure.ts"; import { advertisedJsonSchema } from "../../apps/server/src/mcp/advertisedJsonSchema.ts"; import * as Contracts from "@t3tools/contracts"; import { @@ -49,6 +50,7 @@ import { ThreadId, } from "@t3tools/contracts"; import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences"; +import { t3AcpPromptWithInstructions } from "@t3tools/provider-core/server/orchestrationInstructions"; import { THEME_GUIDE } from "@t3tools/shared/themeCss"; import { formatThreadLink } from "@t3tools/shared/threadLinks"; import { buildCodexAdditionalContext } from "../../apps/server/src/provider/CodexDeveloperInstructions.ts"; @@ -80,6 +82,7 @@ import { } from "../../apps/server/src/mcp/toolkits/pullRequests/tools.ts"; import { ThemeToolkit } from "../../apps/server/src/mcp/toolkits/theme/tools.ts"; import { ThreadToolkit } from "../../apps/server/src/mcp/toolkits/thread/tools.ts"; +import { ToolSearchToolkit } from "../../apps/server/src/mcp/toolkits/toolSearch/tools.ts"; import { WorktreeToolkit } from "../../apps/server/src/mcp/toolkits/worktree/tools.ts"; import { CLAUDE_PROVIDER, @@ -350,6 +353,8 @@ export const McpToolUseCase = Schema.Struct({ role: Schema.Literals(["top", "delegated-child", "native-subagent"]), /** Runs only on this harness, for cases whose right answer depends on it. */ harness: Schema.optional(Schema.Literals(["claude", "codex"])), + /** Claude template with ACP instructions and T3's own deferred listing and tool_search. */ + toolExposure: Schema.optional(Schema.Literal("t3_tool_search")), /** The Linked environments beta is on, so T3 lists its link tools. */ linkedEnvironments: Schema.optional(Schema.Boolean), /** false: the project is on no forge T3 reads, so T3 hides its forge tools. */ @@ -513,6 +518,24 @@ const t3SourceTools: ReadonlyArray = [ HtmlToolkit, MessageToolkit, ].flatMap((toolkit): ReadonlyArray => Object.values(toolkit.tools)); +const t3SearchCatalog = t3SourceTools.map((tool) => ({ + name: tool.name, + description: Tool.getDescription(tool) ?? "", + pack: Context.getOrUndefined(tool.annotations, McpToolExposure.Pack), +})); +const searchCaller = { + providerSessionId: "mcp-tool-use-eval", + providerInstanceId: "mcp-tool-use-eval", +}; +/** Searches only the tools the case lists, so every result has a schema to load. */ +const makeT3Exposure = (eligible: ReadonlyArray) => { + const names = new Set(eligible.map((tool) => normalizeToolName(tool.name))); + const catalog = t3SearchCatalog.filter((tool) => names.has(tool.name)); + return McpToolExposure.make( + () => catalog, + () => Effect.void, + ); +}; // McpHttpServer decodes arguments with each tool's JSON codec, which drops undeclared keys. const t3InputDecoders = new Map( t3SourceTools.map((tool) => [ @@ -522,11 +545,15 @@ const t3InputDecoders = new Map( ), ]), ); -const t3Tools: ReadonlyArray = t3SourceTools.map((tool) => ({ +const advertisedTool = (tool: Tool.Any): ApiTool => ({ name: `${T3_PREFIX}${tool.name}`, description: Tool.getDescription(tool) ?? "", input_schema: advertisedJsonSchema(tool), -})); +}); +const t3Tools = t3SourceTools.map(advertisedTool); +const t3SearchSourceTool = ToolSearchToolkit.tools.tool_search; +const decodeT3Search = Schema.decodeUnknownOption(t3SearchSourceTool.parametersSchema); +const decodePriorT3Search = Schema.decodeUnknownSync(t3SearchSourceTool.parametersSchema); // T3 gates these on the `preview` capability, which agent browser access decides. const PREVIEW_TOOLS = new Set( [PreviewToolkit, PreviewControlsToolkit].flatMap((toolkit) => @@ -720,6 +747,7 @@ export const buildBase = ( readonly subagent?: boolean; readonly links?: boolean; readonly forge?: boolean; + readonly t3Deferred?: boolean; /** A native subagent starts from its task: T3 appends nothing to its system prompt. */ readonly nativeSubagent?: boolean; /** false: the thread has no agent device access, so T3's text leaves devices out. */ @@ -731,7 +759,13 @@ export const buildBase = ( readonly arm?: Arm; }, ) => { - const t3 = visibleT3Tools(options); + const visible = visibleT3Tools(options); + const t3 = options.t3Deferred ? [...visible, advertisedTool(t3SearchSourceTool)] : visible; + const exposure = options.t3Deferred ? makeT3Exposure(t3) : undefined; + if (exposure && (options.agentFeedback ?? "off") !== "off") { + // This mode sends ACP instructions, which carry no feedback guidance. + throw new Error("toolExposure t3_tool_search does not model agentFeedback."); + } const firstAssistant = template.messages.findIndex((message) => message.role === "assistant"); const head = template.messages.slice(0, firstAssistant === -1 ? undefined : firstAssistant); const systemTexts = [ @@ -745,19 +779,21 @@ export const buildBase = ( throw new Error(`The template needs one ${RUNTIME_MARKER} block and a deferred tool list.`); } const nativeDeferred = deferredList.split("\n").filter((name) => name && !isT3Name(name)); + const t3NativeDeferred = exposure ? [] : t3; const names = [ ...nativeDeferred, - ...t3.filter((tool) => !alwaysLoaded.has(tool.name)).map((tool) => tool.name), + ...t3NativeDeferred.filter((tool) => !alwaysLoaded.has(tool.name)).map((tool) => tool.name), ] .toSorted() .join("\n"); const { model } = options; - const append = options.nativeSubagent - ? "" - : forArm( - t3SystemAppend(model, options.deviceAccess, options.browserAccess, options.agentFeedback), - options.arm, - ); + const append = + options.nativeSubagent || exposure + ? "" + : forArm( + t3SystemAppend(model, options.deviceAccess, options.browserAccess, options.agentFeedback), + options.arm, + ); const modelLine = `You are powered by the model named ${MODELS[model]}. The exact model ID is ${model}.`; const joined = systemTexts.join("\n"); // The capture's home directory names its user. Cases use `/home/user` paths instead. @@ -799,11 +835,18 @@ export const buildBase = ( }, nativeTools: [ ...template.tools.filter((tool) => !isT3Name(tool.name)), - ...t3.filter((tool) => alwaysLoaded.has(tool.name)), + ...t3.filter((tool) => + exposure + ? exposure.isListed(searchCaller.providerSessionId, normalizeToolName(tool.name)) + : alwaysLoaded.has(tool.name), + ), ], /** Tools ToolSearch loads: T3 tools from source, and native tools the template only names. */ t3, - deferred: [...t3, ...nativeDeferred.map((name) => ({ name, ...nativeSchema(name) }))], + deferred: [ + ...t3NativeDeferred, + ...nativeDeferred.map((name) => ({ name, ...nativeSchema(name) })), + ], }; }; @@ -999,6 +1042,7 @@ type Sample = { readonly testCase: McpToolUseCase; readonly base: Base; readonly tools: Array; + readonly t3Exposure?: ReturnType; readonly repo: string; readonly shell: Array; readonly shellUsage: Usage; @@ -1064,6 +1108,9 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => { testCase, base, tools: [...base.nativeTools], + ...(testCase.setup.toolExposure === "t3_tool_search" + ? { t3Exposure: makeT3Exposure(base.t3) } + : {}), repo: testCase.setup.world?.repo ?? "acme/app", shell, shellUsage: emptyUsage(), @@ -1174,8 +1221,41 @@ const gitStatus = ({ setup }: McpToolUseCase) => { }; const findTool = (base: Base, bare: string) => - [...base.nativeTools, ...base.deferred].find((tool) => normalizeToolName(tool.name) === bare) ?? - (base.codex ? { name: bare } : undefined); + [...base.nativeTools, ...base.deferred, ...base.t3].find( + (tool) => normalizeToolName(tool.name) === bare, + ) ?? (base.codex ? { name: bare } : undefined); + +const t3Search = (exposure: ReturnType, id: string, query: string) => + exposure.search(searchCaller, query).pipe( + // The API allows no text beside tool references, and they carry the same names and + // descriptions, so a search that found tools answers with references alone. + Effect.map((found) => + found.length === 0 + ? toolResult(id, { tools: [] }) + : { + type: "tool_result", + tool_use_id: id, + content: found.map((tool) => ({ + type: "tool_reference", + tool_name: `${T3_PREFIX}${tool.name}`, + })), + }, + ), + ); + +export const relistT3Tools = ({ t3Exposure, base, tools }: Sample) => { + if (!t3Exposure?.relisted(searchCaller.providerSessionId)) return; + for (const tool of base.t3) { + if ( + t3Exposure.isListed(searchCaller.providerSessionId, normalizeToolName(tool.name)) && + !hasTool(tools, tool.name) + ) { + // A plain push would change the tool list and unbind earlier thinking blocks, so the + // re-list is sent the way Claude Code loads tools: deferred schemas the result references. + tools.push({ ...tool, defer_loading: true }); + } + } +}; /** Adds deferred schemas to `tools` and returns the ToolSearch result Claude Code sends. */ const loadTools = (tools: Array, id: string, found: ReadonlyArray): Block => { @@ -1188,7 +1268,7 @@ const loadTools = (tools: Array, id: string, found: ReadonlyArray { - const { testCase, base, tools } = sample; + const { testCase, base, tools, t3Exposure } = sample; const messages: Array = []; const push = (role: ApiMessage["role"], ...blocks: ReadonlyArray) => { const last = messages.at(-1); @@ -1196,6 +1276,20 @@ export const buildMessages = (sample: Sample) => { else messages[messages.length - 1] = { role, content: [...last.content, ...blocks] }; }; const { role, context, delegateRole, priorTurns = [] } = testCase.setup; + let acpInstructionsPending = t3Exposure !== undefined; + const userPrompt = (prompt: string) => { + if (!acpInstructionsPending) return prompt; + const withInstructions = t3AcpPromptWithInstructions({ + prompt, + state: { + interactionMode: "default", + hasT3Mcp: true, + hasDeviceTools: testCase.setup.world?.deviceAgentAccess !== false, + }, + }); + acpInstructionsPending = withInstructions === prompt; + return withInstructions; + }; const sideChat = testCase.setup.sideChat; if (testCase.prompt === "" && (role !== "top" || sideChat !== undefined)) { throw new Error( @@ -1234,28 +1328,46 @@ export const buildMessages = (sample: Sample) => { } return { ...call, id: `toolu_prior_${nextId++}`, name: tool.name, tool, prior: call }; }); - // Prior T3 calls load their schemas first, as in a real deferred session. const unloaded = [...new Set(calls.map((call) => call.tool))].filter( (tool) => !hasTool(tools, tool.name), ); - if (unloaded.length > 0 && !base.codex) { + const nativeDeferred = unloaded.filter((tool) => !t3Exposure || !isT3Name(tool.name)); + if (nativeDeferred.length > 0 && !base.codex) { const id = `toolu_prior_${nextId++}`; - const query = `select:${unloaded.map((tool) => tool.name).join(",")}`; - const input = { query, max_results: unloaded.length }; + const query = `select:${nativeDeferred.map((tool) => tool.name).join(",")}`; + const input = { query, max_results: nativeDeferred.length }; push("assistant", { type: "tool_use", id, name: toolSearch, input }); - push("user", loadTools(tools, id, unloaded), text(TOOL_LOADED)); + push("user", loadTools(tools, id, nativeDeferred), text(TOOL_LOADED)); } // One call per step, as most real turns run them. - for (const { id, name, input, result, tool, prior } of calls) { + for (const { id, name, input, result, prior } of calls) { + const bare = normalizeToolName(name); + if (t3Exposure && isT3Name(name) && !hasTool(tools, name)) { + const searchId = `toolu_prior_${nextId++}`; + push("assistant", { + type: "tool_use", + id: searchId, + name: `${T3_PREFIX}${McpToolExposure.TOOL_SEARCH}`, + input: { query: bare }, + }); + push("user", Effect.runSync(t3Search(t3Exposure, searchId, bare))); + relistT3Tools(sample); + } push("assistant", { type: "tool_use", id, name, input }); + if (t3Exposure && bare === McpToolExposure.TOOL_SEARCH) { + const decoded = decodePriorT3Search(input); + push("user", Effect.runSync(t3Search(t3Exposure, id, decoded.query))); + relistT3Tools(sample); + continue; + } const replayed = - normalizeToolName(tool.name) === "orchestrator_capabilities" + bare === "orchestrator_capabilities" ? capabilities(sample, result) : (sample.priorResults.get(prior) ?? result); const answer = toolResult(id, replayed); push("user", sample.priorErrors.has(prior) ? { ...answer, is_error: true } : answer); } - if (turn.text) push(turn.role, text(turn.text)); + if (turn.text) push(turn.role, text(turn.role === "user" ? userPrompt(turn.text) : turn.text)); } const userText = testCase.promptContext === undefined @@ -1265,7 +1377,7 @@ export const buildMessages = (sample: Sample) => { sideChatContext === undefined ? userText : withInlineContext(sideChatContext, userText); const childPrompt = () => taskPrompt({ task: prompt, role: delegateRole }); if (testCase.prompt !== "") - push("user", text(role === "delegated-child" ? childPrompt() : prompt)); + push("user", text(userPrompt(role === "delegated-child" ? childPrompt() : prompt))); // Claude Code gives a subagent its SubagentStart hooks' context as a reminder after the task. if (native && base.subagentContext) { push("user", reminder(`SubagentStart hook additional context: ${base.subagentContext}`)); @@ -2236,7 +2348,7 @@ export const answerToolCall = Effect.fn("evaluateMcpToolUse.answerToolCall")(fun config: Config, call: typeof ToolUse.Type, ) { - const { testCase, base, tools } = sample; + const { testCase, base, tools, t3Exposure } = sample; let name = normalizeToolName(call.name); let input = isRecord(call.input) ? call.input : {}; if (call.name === "web__run") { @@ -2251,9 +2363,18 @@ export const answerToolCall = Effect.fn("evaluateMcpToolUse.answerToolCall")(fun } const failed = (error: string): Block => ({ ...toolResult(call.id, error), is_error: true }); if (!base.codex && !hasTool(tools, call.name)) { - const error = `InputValidationError: ${call.name} is deferred. Load it with ToolSearch first.`; + const search = + t3Exposure && isT3Name(call.name) + ? `${T3_PREFIX}${McpToolExposure.TOOL_SEARCH}` + : "ToolSearch"; + const error = `InputValidationError: ${call.name} is deferred. Load it with ${search} first.`; return failed(`${error}`); } + if (t3Exposure && name === McpToolExposure.TOOL_SEARCH) { + const decoded = Option.getOrUndefined(decodeT3Search(input)); + if (decoded === undefined) return failed("Invalid tool_search input."); + return yield* t3Search(t3Exposure, call.id, decoded.query); + } if (name === "ToolSearch") { const max = typeof input.max_results === "number" ? input.max_results : 5; const found = searchTools(base, valueText(input.query), max); @@ -3004,6 +3125,7 @@ const runSample = Effect.fn("evaluateMcpToolUse.runSample")(function* ( }); }), ); + relistT3Tools(sample); // Claude Code adds this text after a ToolSearch that loaded tools. const loaded = results.some((result) => Array.isArray(result.content)); messages.push({ role: "user", content: [...results, ...(loaded ? [text(TOOL_LOADED)] : [])] }); @@ -3243,7 +3365,8 @@ const main = Effect.gen(function* () { const selectedCases = cases.filter( ({ id, setup }) => (wanted === undefined || wanted.includes(id)) && - (setup.harness === undefined || setup.harness === harness), + (setup.harness === undefined || setup.harness === harness) && + (!codex || setup.toolExposure !== "t3_tool_search"), ); if (selectedCases.length === 0) return yield* Effect.die(new Error("No case matches --case.")); // The raw arm has no PR or issue tools, so a case whose prior turns call one cannot be replayed. @@ -3302,6 +3425,7 @@ const main = Effect.gen(function* () { links: boolean, forge: boolean, agentFeedback: Contracts.AgentFeedbackMode = "off", + t3Deferred = false, ): Effect.Effect => codex ? decodeCodexCapture(template).pipe( @@ -3327,6 +3451,7 @@ const main = Effect.gen(function* () { keepUserInstructions, subagent: role === "delegated-child", nativeSubagent: role === "native-subagent", + t3Deferred, links, forge, deviceAccess, @@ -3343,19 +3468,20 @@ const main = Effect.gen(function* () { ); // Codex has no native subagents; its cases with that role run as top-level threads. const baseKey = ({ setup }: McpToolUseCase) => - `${codex && setup.role === "native-subagent" ? "top" : setup.role}:${setup.world?.deviceAgentAccess !== false}:${setup.world?.browserAgentAccess !== false}:${setup.linkedEnvironments === true}:${setup.forge !== false}:${setup.world?.agentFeedback ?? "off"}`; + `${codex && setup.role === "native-subagent" ? "top" : setup.role}:${setup.world?.deviceAgentAccess !== false}:${setup.world?.browserAgentAccess !== false}:${setup.linkedEnvironments === true}:${setup.forge !== false}:${setup.world?.agentFeedback ?? "off"}:${setup.toolExposure === "t3_tool_search"}`; const base = yield* buildFor("top", true, true, false, true); - const bases = new Map([["top:true:true:false:true:off", base]]); + const bases = new Map([["top:true:true:false:true:off:false", base]]); for (const testCase of selected) { const key = baseKey(testCase); if (bases.has(key)) continue; - const [role = "top", device, browser, links, forge, feedback] = key.split(":") as [ + const [role = "top", device, browser, links, forge, feedback, t3Deferred] = key.split(":") as [ McpToolUseCase["setup"]["role"], string, string, string, string, string, + string, ]; bases.set( key, @@ -3366,6 +3492,7 @@ const main = Effect.gen(function* () { links === "true", forge === "true", feedback as Contracts.AgentFeedbackMode, + t3Deferred === "true", ), ); } From 5db9587205680063e733ba7290de2bd57272add4 Mon Sep 17 00:00:00 2001 From: Gabriel De Andrade Date: Tue, 24 Nov 2026 11:42:20 -0400 Subject: [PATCH 2/6] test(evals): tool-search controls require a successful edit Co-Authored-By: Claude Fable 5.2 --- evals/mcp-tool-use/cases/tool-search.ndjson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evals/mcp-tool-use/cases/tool-search.ndjson b/evals/mcp-tool-use/cases/tool-search.ndjson index 3b0c4a6f6d8e0..cf7649465ca5c 100644 --- a/evals/mcp-tool-use/cases/tool-search.ndjson +++ b/evals/mcp-tool-use/cases/tool-search.ndjson @@ -1,4 +1,4 @@ {"id": "t3-tool-search-theme-pack", "area": "tool-search", "kind": "bad", "pattern": "restyle T3 Code itself", "experience": "In a session that lists T3 tools on demand, tool_search's description named no theme tools, so an agent asked to restyle T3 Code never searched for them. It should load the customization pack, read the theme guide, then publish the theme.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}, "setup": {"role": "top", "mocks": {"t3_theme_read": {"current": "", "builtIn": ["t3-chat", "grove", "ocean", "ember", "iris"], "published": [], "guide": "Themes restyle T3 Code on web and desktop. `canvas` and `accent` (hex) derive a full palette. `css` applies after the app's styles."}, "t3_theme_set": {"themeId": "night-terminal", "published": true}}, "toolExposure": "t3_tool_search"}, "prompt": "Make T3 Code itself look like a late-night terminal: near-black background with a green accent.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "t3_theme_read", "success": true}, {"tool": "t3_theme_set", "args": {"theme.appearance": "dark"}, "success": true}], "order": ["tool_search", "t3_theme_read", "t3_theme_set"]}, "maxSteps": 8} {"id": "t3-tool-search-preview-open", "kind": "guard", "pattern": "discover an optional browser tool", "experience": "A request to open the running app in the shared preview still works when the harness defers T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "report": "Maintainer field review, 2026-11: Claude threads whose project CLAUDE.md named a browser CLI that was not installed fell back to ad hoc Playwright for requested browser work"}, "setup": {"role": "top", "world": {"repo": "acme/app", "processes": "The Acme web dev server is running and http://localhost:3000/ answers 200."}, "mocks": {"preview_status": {"available": false, "visible": false, "tabId": null, "url": null, "title": null, "loading": false, "profiles": [{"id": "default", "name": "Default"}, {"id": "incognito", "name": "Incognito", "incognito": true}], "defaultProfileId": "default"}, "preview_open": {"available": true, "visible": true, "tabId": "tab_1", "url": "http://localhost:3000/", "title": "Acme", "loading": false, "control": {"owner": "agent", "ownedByCaller": true, "generation": 1}}}, "toolExposure": "t3_tool_search"}, "prompt": "Open http://localhost:3000/ in the T3 Code preview browser and leave it open.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "preview_open", "success": true}], "order": ["tool_search", "preview_open"]}, "maxSteps": 8, "area": "tool-search", "privacy": "commit-safe"} -{"id": "t3-tool-search-control-file-edit", "kind": "control", "pattern": "a routine project file edit", "experience": "Ordinary coding work uses the harness's editing tools without discovering T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "note": "Control for the server-side tool search introduced for Copilot."}, "setup": {"role": "top", "world": {"repo": "acme/app", "files": {"src/retry.ts": "export const retryLimit = 2;\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change retryLimit from 2 to 3 in src/retry.ts.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/retry.ts", "new_string": "~3"}, {"file_path": "~src/retry.ts", "content": "~retryLimit = 3"}, {"command": "~retryLimit = 3"}]}], "notCalls": ["tool_search"]}, "maxSteps": 6, "area": "tool-search", "privacy": "commit-safe"} -{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} +{"id": "t3-tool-search-control-file-edit", "kind": "control", "pattern": "a routine project file edit", "experience": "Ordinary coding work uses the harness's editing tools without discovering T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "note": "Control for the server-side tool search introduced for Copilot."}, "setup": {"role": "top", "world": {"repo": "acme/app", "files": {"src/retry.ts": "export const retryLimit = 2;\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change retryLimit from 2 to 3 in src/retry.ts.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/retry.ts", "new_string": "~3"}, {"file_path": "~src/retry.ts", "content": "~retryLimit = 3"}, {"command": "~retryLimit = 3"}], "success": true}], "notCalls": ["tool_search"]}, "maxSteps": 6, "area": "tool-search", "privacy": "commit-safe"} +{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~theme.css"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} From 1b6fac22ae3dedf71c729a46620e51a5d377030d Mon Sep 17 00:00:00 2001 From: Gabriel De Andrade Date: Tue, 24 Nov 2026 11:45:00 -0400 Subject: [PATCH 3/6] test(evals): the project-theme control requires a write Co-Authored-By: Claude Fable 5.2 --- evals/mcp-tool-use/cases/tool-search.ndjson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evals/mcp-tool-use/cases/tool-search.ndjson b/evals/mcp-tool-use/cases/tool-search.ndjson index cf7649465ca5c..c9399d0439d63 100644 --- a/evals/mcp-tool-use/cases/tool-search.ndjson +++ b/evals/mcp-tool-use/cases/tool-search.ndjson @@ -1,4 +1,4 @@ {"id": "t3-tool-search-theme-pack", "area": "tool-search", "kind": "bad", "pattern": "restyle T3 Code itself", "experience": "In a session that lists T3 tools on demand, tool_search's description named no theme tools, so an agent asked to restyle T3 Code never searched for them. It should load the customization pack, read the theme guide, then publish the theme.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}, "setup": {"role": "top", "mocks": {"t3_theme_read": {"current": "", "builtIn": ["t3-chat", "grove", "ocean", "ember", "iris"], "published": [], "guide": "Themes restyle T3 Code on web and desktop. `canvas` and `accent` (hex) derive a full palette. `css` applies after the app's styles."}, "t3_theme_set": {"themeId": "night-terminal", "published": true}}, "toolExposure": "t3_tool_search"}, "prompt": "Make T3 Code itself look like a late-night terminal: near-black background with a green accent.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "t3_theme_read", "success": true}, {"tool": "t3_theme_set", "args": {"theme.appearance": "dark"}, "success": true}], "order": ["tool_search", "t3_theme_read", "t3_theme_set"]}, "maxSteps": 8} {"id": "t3-tool-search-preview-open", "kind": "guard", "pattern": "discover an optional browser tool", "experience": "A request to open the running app in the shared preview still works when the harness defers T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "report": "Maintainer field review, 2026-11: Claude threads whose project CLAUDE.md named a browser CLI that was not installed fell back to ad hoc Playwright for requested browser work"}, "setup": {"role": "top", "world": {"repo": "acme/app", "processes": "The Acme web dev server is running and http://localhost:3000/ answers 200."}, "mocks": {"preview_status": {"available": false, "visible": false, "tabId": null, "url": null, "title": null, "loading": false, "profiles": [{"id": "default", "name": "Default"}, {"id": "incognito", "name": "Incognito", "incognito": true}], "defaultProfileId": "default"}, "preview_open": {"available": true, "visible": true, "tabId": "tab_1", "url": "http://localhost:3000/", "title": "Acme", "loading": false, "control": {"owner": "agent", "ownedByCaller": true, "generation": 1}}}, "toolExposure": "t3_tool_search"}, "prompt": "Open http://localhost:3000/ in the T3 Code preview browser and leave it open.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "preview_open", "success": true}], "order": ["tool_search", "preview_open"]}, "maxSteps": 8, "area": "tool-search", "privacy": "commit-safe"} {"id": "t3-tool-search-control-file-edit", "kind": "control", "pattern": "a routine project file edit", "experience": "Ordinary coding work uses the harness's editing tools without discovering T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "note": "Control for the server-side tool search introduced for Copilot."}, "setup": {"role": "top", "world": {"repo": "acme/app", "files": {"src/retry.ts": "export const retryLimit = 2;\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change retryLimit from 2 to 3 in src/retry.ts.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/retry.ts", "new_string": "~3"}, {"file_path": "~src/retry.ts", "content": "~retryLimit = 3"}, {"command": "~retryLimit = 3"}], "success": true}], "notCalls": ["tool_search"]}, "maxSteps": 6, "area": "tool-search", "privacy": "commit-safe"} -{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~theme.css"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} +{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~sed -i"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} From a3e352b0e1849af391d8542c854860edbf1776e4 Mon Sep 17 00:00:00 2001 From: Gabriel De Andrade Date: Tue, 24 Nov 2026 11:46:15 -0400 Subject: [PATCH 4/6] test(evals): the project-theme control matches the rule it replaces Co-Authored-By: Claude Fable 5.2 --- evals/mcp-tool-use/cases/tool-search.ndjson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evals/mcp-tool-use/cases/tool-search.ndjson b/evals/mcp-tool-use/cases/tool-search.ndjson index c9399d0439d63..44791d848712e 100644 --- a/evals/mcp-tool-use/cases/tool-search.ndjson +++ b/evals/mcp-tool-use/cases/tool-search.ndjson @@ -1,4 +1,4 @@ {"id": "t3-tool-search-theme-pack", "area": "tool-search", "kind": "bad", "pattern": "restyle T3 Code itself", "experience": "In a session that lists T3 tools on demand, tool_search's description named no theme tools, so an agent asked to restyle T3 Code never searched for them. It should load the customization pack, read the theme guide, then publish the theme.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}, "setup": {"role": "top", "mocks": {"t3_theme_read": {"current": "", "builtIn": ["t3-chat", "grove", "ocean", "ember", "iris"], "published": [], "guide": "Themes restyle T3 Code on web and desktop. `canvas` and `accent` (hex) derive a full palette. `css` applies after the app's styles."}, "t3_theme_set": {"themeId": "night-terminal", "published": true}}, "toolExposure": "t3_tool_search"}, "prompt": "Make T3 Code itself look like a late-night terminal: near-black background with a green accent.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "t3_theme_read", "success": true}, {"tool": "t3_theme_set", "args": {"theme.appearance": "dark"}, "success": true}], "order": ["tool_search", "t3_theme_read", "t3_theme_set"]}, "maxSteps": 8} {"id": "t3-tool-search-preview-open", "kind": "guard", "pattern": "discover an optional browser tool", "experience": "A request to open the running app in the shared preview still works when the harness defers T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "report": "Maintainer field review, 2026-11: Claude threads whose project CLAUDE.md named a browser CLI that was not installed fell back to ad hoc Playwright for requested browser work"}, "setup": {"role": "top", "world": {"repo": "acme/app", "processes": "The Acme web dev server is running and http://localhost:3000/ answers 200."}, "mocks": {"preview_status": {"available": false, "visible": false, "tabId": null, "url": null, "title": null, "loading": false, "profiles": [{"id": "default", "name": "Default"}, {"id": "incognito", "name": "Incognito", "incognito": true}], "defaultProfileId": "default"}, "preview_open": {"available": true, "visible": true, "tabId": "tab_1", "url": "http://localhost:3000/", "title": "Acme", "loading": false, "control": {"owner": "agent", "ownedByCaller": true, "generation": 1}}}, "toolExposure": "t3_tool_search"}, "prompt": "Open http://localhost:3000/ in the T3 Code preview browser and leave it open.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "preview_open", "success": true}], "order": ["tool_search", "preview_open"]}, "maxSteps": 8, "area": "tool-search", "privacy": "commit-safe"} {"id": "t3-tool-search-control-file-edit", "kind": "control", "pattern": "a routine project file edit", "experience": "Ordinary coding work uses the harness's editing tools without discovering T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "note": "Control for the server-side tool search introduced for Copilot."}, "setup": {"role": "top", "world": {"repo": "acme/app", "files": {"src/retry.ts": "export const retryLimit = 2;\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change retryLimit from 2 to 3 in src/retry.ts.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/retry.ts", "new_string": "~3"}, {"file_path": "~src/retry.ts", "content": "~retryLimit = 3"}, {"command": "~retryLimit = 3"}], "success": true}], "notCalls": ["tool_search"]}, "maxSteps": 6, "area": "tool-search", "privacy": "commit-safe"} -{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~sed -i"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} +{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~--accent: #60a5fa"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} From a634142c319b866165deb37e2f1952a33e6cf421 Mon Sep 17 00:00:00 2001 From: Gabriel De Andrade Date: Tue, 24 Nov 2026 11:47:08 -0400 Subject: [PATCH 5/6] test(evals): the project-theme control matches the substitution Co-Authored-By: Claude Fable 5.2 --- evals/mcp-tool-use/cases/tool-search.ndjson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evals/mcp-tool-use/cases/tool-search.ndjson b/evals/mcp-tool-use/cases/tool-search.ndjson index 44791d848712e..81bafcd8a236d 100644 --- a/evals/mcp-tool-use/cases/tool-search.ndjson +++ b/evals/mcp-tool-use/cases/tool-search.ndjson @@ -1,4 +1,4 @@ {"id": "t3-tool-search-theme-pack", "area": "tool-search", "kind": "bad", "pattern": "restyle T3 Code itself", "experience": "In a session that lists T3 tools on demand, tool_search's description named no theme tools, so an agent asked to restyle T3 Code never searched for them. It should load the customization pack, read the theme guide, then publish the theme.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}, "setup": {"role": "top", "mocks": {"t3_theme_read": {"current": "", "builtIn": ["t3-chat", "grove", "ocean", "ember", "iris"], "published": [], "guide": "Themes restyle T3 Code on web and desktop. `canvas` and `accent` (hex) derive a full palette. `css` applies after the app's styles."}, "t3_theme_set": {"themeId": "night-terminal", "published": true}}, "toolExposure": "t3_tool_search"}, "prompt": "Make T3 Code itself look like a late-night terminal: near-black background with a green accent.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "t3_theme_read", "success": true}, {"tool": "t3_theme_set", "args": {"theme.appearance": "dark"}, "success": true}], "order": ["tool_search", "t3_theme_read", "t3_theme_set"]}, "maxSteps": 8} {"id": "t3-tool-search-preview-open", "kind": "guard", "pattern": "discover an optional browser tool", "experience": "A request to open the running app in the shared preview still works when the harness defers T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "report": "Maintainer field review, 2026-11: Claude threads whose project CLAUDE.md named a browser CLI that was not installed fell back to ad hoc Playwright for requested browser work"}, "setup": {"role": "top", "world": {"repo": "acme/app", "processes": "The Acme web dev server is running and http://localhost:3000/ answers 200."}, "mocks": {"preview_status": {"available": false, "visible": false, "tabId": null, "url": null, "title": null, "loading": false, "profiles": [{"id": "default", "name": "Default"}, {"id": "incognito", "name": "Incognito", "incognito": true}], "defaultProfileId": "default"}, "preview_open": {"available": true, "visible": true, "tabId": "tab_1", "url": "http://localhost:3000/", "title": "Acme", "loading": false, "control": {"owner": "agent", "ownedByCaller": true, "generation": 1}}}, "toolExposure": "t3_tool_search"}, "prompt": "Open http://localhost:3000/ in the T3 Code preview browser and leave it open.", "expect": {"calls": [{"tool": "tool_search", "success": true}, {"tool": "preview_open", "success": true}], "order": ["tool_search", "preview_open"]}, "maxSteps": 8, "area": "tool-search", "privacy": "commit-safe"} {"id": "t3-tool-search-control-file-edit", "kind": "control", "pattern": "a routine project file edit", "experience": "Ordinary coding work uses the harness's editing tools without discovering T3 tools.", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/34245", "note": "Control for the server-side tool search introduced for Copilot."}, "setup": {"role": "top", "world": {"repo": "acme/app", "files": {"src/retry.ts": "export const retryLimit = 2;\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change retryLimit from 2 to 3 in src/retry.ts.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/retry.ts", "new_string": "~3"}, {"file_path": "~src/retry.ts", "content": "~retryLimit = 3"}, {"command": "~retryLimit = 3"}], "success": true}], "notCalls": ["tool_search"]}, "maxSteps": 6, "area": "tool-search", "privacy": "commit-safe"} -{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~--accent: #60a5fa"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} +{"id": "t3-tool-search-control-project-theme", "area": "tool-search", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}, "toolExposure": "t3_tool_search"}, "prompt": "Change the dark theme accent to green.", "expect": {"calls": [{"tool": "Edit|Write|Bash", "argsAnyOf": [{"file_path": "~src/theme.css"}, {"command": "~#60a5fa; }/.dark { --accent: #"}], "success": true}], "notCalls": ["tool_search", "t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone.", "deferredListingPullRequest": "https://github.com/pingdotgg/t3code/pull/34245"}} From 4035d072f39c27cab123546c3c2be3be414ed420 Mon Sep 17 00:00:00 2001 From: Gabriel De Andrade Date: Tue, 24 Nov 2026 11:53:18 -0400 Subject: [PATCH 6/6] docs: harness observations move to an operations runbook Co-Authored-By: Claude Fable 5.2 --- apps/server/scripts/mcp-relist-probe.ts | 2 +- .../src/provider/AgentContextBudget.test.ts | 2 +- docs/README.md | 1 + docs/internals/03_providers.md | 22 ++----------- docs/operations/06_mcp-tool-deferral.md | 33 +++++++++++++++++++ 5 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 docs/operations/06_mcp-tool-deferral.md diff --git a/apps/server/scripts/mcp-relist-probe.ts b/apps/server/scripts/mcp-relist-probe.ts index 9476c7383484d..60b15500b1fd7 100644 --- a/apps/server/scripts/mcp-relist-probe.ts +++ b/apps/server/scripts/mcp-relist-probe.ts @@ -1,5 +1,5 @@ // Serves T3's real MCP transport with a hidden tool, to see whether a harness lists tools again -// after `tool_search`, before T3 defers tools for it (docs/internals/03_providers.md). +// after `tool_search`, before T3 defers tools for it (docs/operations/06_mcp-tool-deferral.md). // @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer.layer takes Node's createServer. import * as NodeHttp from "node:http"; diff --git a/apps/server/src/provider/AgentContextBudget.test.ts b/apps/server/src/provider/AgentContextBudget.test.ts index 882d305d6b403..493cf5e61947e 100644 --- a/apps/server/src/provider/AgentContextBudget.test.ts +++ b/apps/server/src/provider/AgentContextBudget.test.ts @@ -152,7 +152,7 @@ it.effect("only request_secret and send_to_user ask Claude Code to load them up // CI rejects a PR that raises a gated value above main's agentContextBudget.json, so growth // needs the agent-context-increase label. Lower the values when the text shrinks. // mcpPackToolListJsonBytes is recorded but not gated: harnesses that defer tools never list -// a pack up front, and the eager ones are the fallback (docs/internals/03_providers.md). +// a pack up front, and the eager ones are the fallback (docs/operations/06_mcp-tool-deferral.md). it.effect("agent context matches the committed budget", () => Effect.gen(function* () { const mcp = yield* McpServer.McpServer; diff --git a/docs/README.md b/docs/README.md index 00e60de0e7063..2a6c8ced5398b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -72,3 +72,4 @@ anything. - [03 · Release](./operations/03_release.md) - [04 · Observability](./operations/04_observability.md) - [05 · Relay observability](./operations/05_relay-observability.md) +- [06 · MCP tool deferral](./operations/06_mcp-tool-deferral.md) diff --git a/docs/internals/03_providers.md b/docs/internals/03_providers.md index 7d9f4e4b5e110..fe3c123643ee8 100644 --- a/docs/internals/03_providers.md +++ b/docs/internals/03_providers.md @@ -63,25 +63,9 @@ clients read declared capabilities, never provider names. `tool_search` response, and gives its model the new tools in the same turn. Many harnesses do not: Cursor reads tools once per run, and Codex ignores the notification unless a feature flag is on. The full list is therefore the default. Turn deferral on for a harness only after it passes - [`mcp-relist-probe.ts`](../../apps/server/scripts/mcp-relist-probe.ts); a harness that fails is - left with four tools. - - What each harness did when last checked (2026-11-23). Re-run the probe rather than trust a row. - - | Harness | Lists again after `list_changed` | Today | Known from | - | ------------ | ------------------------------------------------------------------------------------ | ------------------------- | ------------------ | - | Claude Code | Yes, same turn | Its own ToolSearch | Probe | - | Codex | Only with `features.mcp_tool_list_changed` | Its own tool search | Probe | - | Copilot CLI | Yes, same turn | T3's `tool_search` | Probe (#34245) | - | Pi | No: T3's extension lists once | Pi's own `tool_search` | Source | - | OpenCode | Yes, same turn; the next step can race it | Full list | Source, not probed | - | Antigravity | Yes; same turn unknown | Full list | Binary symbols | - | Kiro | Unknown; its open-source ancestor did | Full list | Strings | - | Grok | Unknown | Full list | Strings | - | fx | Not from a POST response; yes over stdio | Full list | Source | - | Cursor | No: tools are read once per run | Full list | Bundle | - | Muse Code | Unknown | Full list | Strings | - | ACP Registry | Gemini CLI, Goose, Kilo, fast-agent, Kimchi do; Qwen Code, Kimi, Mistral Vibe do not | Full list, except Copilot | Source | + [`mcp-relist-probe.ts`](../../apps/server/scripts/mcp-relist-probe.ts): with deferral on, a + harness that does not list again leaves its model with four tools. The runbook and the last + observations are in [MCP tool deferral](../operations/06_mcp-tool-deferral.md). ## Model manifest diff --git a/docs/operations/06_mcp-tool-deferral.md b/docs/operations/06_mcp-tool-deferral.md new file mode 100644 index 0000000000000..debb892f51875 --- /dev/null +++ b/docs/operations/06_mcp-tool-deferral.md @@ -0,0 +1,33 @@ +# MCP tool deferral + +T3 can list only a few MCP tools to a harness and reveal the rest through `tool_search`. Why that needs a harness that lists tools again is in [Providers](../internals/03_providers.md). This page is how to check a harness, and what the last checks found. + +## Probe a harness + +1. From `apps/server`, run `node scripts/mcp-relist-probe.ts` (`--port` changes the port). It serves the real MCP transport with one hidden tool and prints the endpoint, the two headers, and a prompt. +2. Attach that endpoint to the harness as an HTTP MCP server with both headers, and send the prompt on the harness's cheapest model. +3. The harness passes when the log shows `mcp.tool-search.relisted` and then `the model called the hidden tool` in the same turn. +4. Restart the probe before the next run: a search stays loaded for the life of the process. + +A harness that passes can take `deferMcpTools`. One that does not stays on the full list. + +The live server writes the same `mcp.tool-search.relisted` line at debug level. It warns with `mcp.tool-search.not-relisted` when a session searches again without ever having listed after a search, which is how a harness that stopped listing shows up in the field. + +## Last observations + +Checked 2026-11-23. Harnesses change, so re-run the probe rather than trust a row. "Probe" rows were run; the others were read from shipped code. + +| Harness | Lists again after `list_changed` | Today | Known from | +| ------------ | ------------------------------------------------------------------------------------ | ------------------------- | ------------------ | +| Claude Code | Yes, same turn | Its own ToolSearch | Probe | +| Codex | Only with `features.mcp_tool_list_changed` | Its own tool search | Probe | +| Copilot CLI | Yes, same turn | T3's `tool_search` | Probe (#34245) | +| Pi | No: T3's extension lists once | Pi's own `tool_search` | Source | +| OpenCode | Yes, same turn; the next step can race it | Full list | Source, not probed | +| Antigravity | Yes; same turn unknown | Full list | Binary symbols | +| Kiro | Unknown; its open-source ancestor did | Full list | Strings | +| Grok | Unknown | Full list | Strings | +| fx | Not from a POST response; yes over stdio | Full list | Source | +| Cursor | No: tools are read once per run | Full list | Bundle | +| Muse Code | Unknown | Full list | Strings | +| ACP Registry | Gemini CLI, Goose, Kilo, fast-agent, Kimchi do; Qwen Code, Kimi, Mistral Vibe do not | Full list, except Copilot | Source |