Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
OpenRouter and other API-key models work again on Windows: the built-in tools fit the 128-tool limit (#3811)
Milind Soni905a3d2518d7
diff --git a/electron/lent-screen-tools.d.mts b/electron/lent-screen-tools.d.mtsnew file mode 100644index 0000000000..4479dbe6b3--- /dev/null+++ b/electron/lent-screen-tools.d.mts@@ -0,0 +1,4 @@+export const LENT_SCREEN_ARGUMENTS: Readonly<Record<string, Record<string, unknown>>>;+export const LENT_SCREEN_TOOLS: ReadonlySet<string>;+export function lentScreenArguments(name: unknown, input: unknown): { arguments: Record<string, unknown> } | { error: string };+export function lentScreenToolListing(tools: unknown): Array<Record<string, unknown>>;diff --git a/server/computer-tool-list.test.ts b/server/computer-tool-list.test.tsnew file mode 100644index 0000000000..e9f535e3a0--- /dev/null+++ b/server/computer-tool-list.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from "vitest";+import { LENT_SCREEN_TOOLS } from "../electron/lent-screen-tools.mjs";+import { listsComputerTool } from "./computer-tool-list.ts";+import { CUA_DRIVER_WINDOWS_TOOLS } from "./testing/cua-driver-tools.ts";++const SCREEN_WORK = [+ "list_apps", "list_windows", "get_window_state", "get_accessibility_tree", "get_desktop_state", "get_screen_size",+ "get_cursor_position", "launch_app", "kill_app", "bring_to_front", "set_window_frame", "click", "double_click", "right_click",+ "drag", "type_text", "press_key", "hotkey", "set_value", "scroll", "move_cursor", "zoom", "clipboard_read", "clipboard_write",+ "start_session", "end_session", "verify_state", "invoke_menu",+];+const DRIVER_BROWSER = ["page", "get_browser_state", "browser_prepare", "browser_navigate", "browser_click", "browser_type",+ "browser_dialog", "browser_set_input_files", "browser_download", "browser_pointer"];++describe("a turn's computer", () => {+ it("lists the screen work of Windows' 57 driver tools beside the built-in browser, and none of the driver's upkeep", () => {+ expect(CUA_DRIVER_WINDOWS_TOOLS).toHaveLength(57);+ expect(CUA_DRIVER_WINDOWS_TOOLS.filter((name) => listsComputerTool(name, true))).toEqual(SCREEN_WORK);+ });++ it("keeps the driver's own browser only when no built-in browser is mounted", () => {+ expect(CUA_DRIVER_WINDOWS_TOOLS.filter((name) => listsComputerTool(name, false)).sort()).toEqual([...SCREEN_WORK, ...DRIVER_BROWSER].sort());+ });++ it("keeps every screen tool a lent screen lends, but not the cursor looks or the session read-backs it carries", () => {+ const lent = [...LENT_SCREEN_TOOLS].filter((name) => !DRIVER_BROWSER.includes(name));+ expect(lent.filter((name) => !listsComputerTool(name, true)).sort()).toEqual([+ "escalate_session", "get_agent_cursor_state", "get_session_state", "set_agent_cursor_enabled", "set_agent_cursor_motion", "set_agent_cursor_style",+ ]);+ });+});diff --git a/server/computer-tool-list.ts b/server/computer-tool-list.tsnew file mode 100644index 0000000000..afad226c1d--- /dev/null+++ b/server/computer-tool-list.ts@@ -0,0 +1,21 @@+// Cua Driver 0.28.2 lists 57 tools on Windows and 56 on macOS: its screen tools, its own browser over CDP, and its upkeep.++/** The driver's config, recordings, updates and diagnostics, the look of its agent cursor, and the session read-backs it+ * keeps for older callers. */+const DRIVER_UPKEEP: ReadonlySet<string> = new Set([+ "get_config", "set_config",+ "get_recording_state", "start_recording", "stop_recording", "replay_trajectory",+ "check_for_update", "install_ffmpeg", "check_permissions", "health_report", "debug_window_info",+ "get_agent_cursor_state", "set_agent_cursor_enabled", "set_agent_cursor_motion", "set_agent_cursor_style", "set_agent_cursor_theme",+ "get_session", "list_sessions", "get_session_state", "escalate_session",+]);++function drivesItsOwnBrowser(name: string): boolean {+ return name.startsWith("browser_") || name === "get_browser_state" || name === "page";+}++/** Whether a turn's computer lists this tool to the model: never the driver's upkeep, and beside the built-in browser+ * not the driver's own browser either. */+export function listsComputerTool(name: string, besideBuiltInBrowser: boolean): boolean {+ return !DRIVER_UPKEEP.has(name) && !(besideBuiltInBrowser && drivesItsOwnBrowser(name));+}diff --git a/server/drivers/chat-mcp-tools.test.ts b/server/drivers/chat-mcp-tools.test.tsindex eb8650b459..59ad0098a2 100644--- a/server/drivers/chat-mcp-tools.test.ts+++ b/server/drivers/chat-mcp-tools.test.ts@@ -4,8 +4,9 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, describe, expect, it, vi } from "vitest";import { augmentedPath } from "../env-path.ts";-import { ChatToolSessionError, mountChatTools, type ChatToolSession } from "./chat-mcp-tools.ts";+import { ChatToolSessionError, mountChatTools, trimmedToolsNotice, type ChatToolSession } from "./chat-mcp-tools.ts";import type { ToolScope } from "../../shared/tool-scope.ts";+import { catalogServer, CUA_DRIVER_WINDOWS_TOOLS, syntheticToolNames } from "../testing/cua-driver-tools.ts";import { startFakeHttpMcp } from "../testing/fake-http-mcp-server.ts";import { whopLikeCatalog } from "../testing/whop-like-catalog.ts";import { wideSchema } from "../testing/oversized-tool-schema.ts";@@ -591,6 +592,90 @@ describe("Chat MCP tool directory", () => {});});+describe("Chat MCP tool limit", () => {+ const CORE_COMPUTER = ["click", "double_click", "right_click", "drag", "scroll", "type_text", "press_key", "hotkey", "set_value",+ "launch_app", "list_apps", "list_windows", "get_window_state", "get_desktop_state", "get_screen_size", "zoom", "invoke_menu"];+ function catalog(names: readonly string[]) {+ const { dir, server } = catalogServer(names);+ dirs.push(dir);+ return server;+ }+ async function mount(integrations: NonNullable<Parameters<typeof mountChatTools>[0]>) {+ const controller = new AbortController();+ controllers.push(controller);+ const session = await mountChatTools(integrations, controller.signal, true);+ sessions.push(session);+ return { session, names: session.definitions.map((tool) => tool.function.name) };+ }+ const windowsTurn = (agents: number, more: Partial<NonNullable<Parameters<typeof mountChatTools>[0]>> = {}) => ({+ localComputer: { ...catalog(CUA_DRIVER_WINDOWS_TOOLS), scope: "local-computer" as const },+ browser: catalog(syntheticToolNames("agent_browser", 32)),+ agents: catalog(syntheticToolNames("agent", agents)),+ composio: catalog(syntheticToolNames("router", 7)),+ data: catalog(syntheticToolNames("table", 5)),+ ...more,+ });++ it.each([42, 47])("fits a Windows turn with %i agents tools: every agents tool, the screen tools, and one browser", async (agents) => {+ const { session, names } = await mount(windowsTurn(agents));+ expect(session.skipped).toEqual([]);+ expect(session.trimmed).toEqual([]);+ expect(names.length + 1).toBeLessThanOrEqual(128);+ expect(names).toEqual(expect.arrayContaining(syntheticToolNames("agents_agent", agents)));+ expect(names).toEqual(expect.arrayContaining(CORE_COMPUTER.map((tool) => `computer_${tool}`)));+ expect(names.filter((name) => /^computer_(?:browser_|get_browser_state$|page$)/.test(name))).toEqual([]);+ expect(names.filter((name) => /^computer_(?:start_recording|set_config|get_config|check_for_update|install_ffmpeg|set_agent_cursor_motion)$/.test(name))).toEqual([]);+ expect(names.filter((name) => name.startsWith("browser_"))).toHaveLength(32);+ });++ it("lists the computer's own browser tools when the turn has no built-in browser", async () => {+ const { names } = await mount({ localComputer: { ...catalog(CUA_DRIVER_WINDOWS_TOOLS), scope: "local-computer" } });+ expect(names).toEqual(expect.arrayContaining(["computer_browser_navigate", "computer_get_browser_state", "computer_click"]));+ expect(names).not.toContain("computer_install_ffmpeg");+ });++ it("caps built-ins that still overflow instead of failing the turn, keeping the agents server whole and saying what was left out", async () => {+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});+ try {+ const { session, names } = await mount(windowsTurn(51, {+ composio: catalog(syntheticToolNames("router", 14)),+ highlevel: catalog(syntheticToolNames("crm", 20)),+ device: catalog(syntheticToolNames("phone", 23)),+ }));+ expect(names).toHaveLength(127);+ expect(names).toEqual(expect.arrayContaining(syntheticToolNames("agents_agent", 51)));+ expect(names).toEqual(expect.arrayContaining(CORE_COMPUTER.map((tool) => `computer_${tool}`)));+ expect(names.filter((name) => name.startsWith("data_"))).toEqual(["data_table_1", "data_table_2"]);+ expect(session.skipped).toEqual([]);+ expect(session.trimmed).toEqual([{ server: "data", listed: 2, of: 5 }, { server: "highlevel", listed: 0, of: 20 }, { server: "device", listed: 0, of: 23 }]);+ expect(trimmedToolsNotice(session.trimmed)).toBe(`"data" listed 2 of 5 tools, "highlevel" listed 0 of 20 tools, "device" listed 0 of 23 tools to fit the model's 128-tool limit; the rest are left out of this turn.`);+ expect(trimmedToolsNotice([])).toBeUndefined();+ } finally { warn.mockRestore(); }+ });++ it("gives the agents server its whole list before a computer mounted ahead of it", async () => {+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});+ try {+ const { session, names } = await mount({ localComputer: catalog(syntheticToolNames("vm", 100)), agents: catalog(syntheticToolNames("agent", 51)) });+ expect(names).toEqual([...syntheticToolNames("computer_vm", 76), ...syntheticToolNames("agents_agent", 51)]);+ expect(session.trimmed).toEqual([{ server: "computer", listed: 76, of: 100 }]);+ } finally { warn.mockRestore(); }+ });++ it("still skips a configured server that does not fit beside the built-ins, leaving room for ask_user", async () => {+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});+ try {+ const fits = await mount(windowsTurn(42, { custom: { notes: catalog(syntheticToolNames("note", 13)) } }));+ expect(fits.names).toHaveLength(127);+ expect(fits.session.skipped).toEqual([]);+ const over = await mount(windowsTurn(42, { custom: { notes: catalog(syntheticToolNames("note", 14)) } }));+ expect(over.names).toHaveLength(114);+ expect(over.session.skipped).toEqual([{ server: "notes", reason: "MCP tool count exceeds the 128-tool limit" }]);+ expect(over.session.trimmed).toEqual([]);+ } finally { warn.mockRestore(); }+ });+});+describe("Chat MCP startup budgets", () => {/** Lets real I/O run, the faked clock standing still, until `condition`. */async function untilReal(condition: () => boolean): Promise<void> {diff --git a/server/drivers/chat-mcp-tools.ts b/server/drivers/chat-mcp-tools.tsindex 55b0a3ef5b..64514b41eb 100644--- a/server/drivers/chat-mcp-tools.ts+++ b/server/drivers/chat-mcp-tools.ts@@ -15,6 +15,8 @@ import { appMountFor, mcpStdioServer } from "../mcp-gate-config.ts";import { REMOTE_MCP_STARTUP_MS, remoteMcpSpec } from "../mcp-http.ts";import { compileToolSchema } from "../mcp-schema-validator.ts";import { fitToolList } from "../mcp-tool-schema.ts";+import { listsComputerTool } from "../computer-tool-list.ts";+import { capToolList, shareToolBudget } from "../tool-count-limit.ts";import type { ToolSchemaProfile } from "../tool-schema-profile.ts";import { allowsTool, canUseMcpServer, parseToolScope, type ToolScope } from "../../shared/tool-scope.ts";import { OWN_APPS_SERVER } from "../../shared/own-apps.ts";@@ -30,9 +32,12 @@ export interface ChatToolCallView { title: string; input: Record<string, unknown/** A dispatched operation may already have taken effect: never retry it through a new round. */export class ChatToolSessionError extends Error {}export interface SkippedChatMcpServer { server: string; reason: string }+/** A built-in server that listed only its first `listed` of `of` tools, so the turn fits the model's tool limit. */+export interface TrimmedChatMcpServer { server: string; listed: number; of: number }export interface ChatToolSession {definitions: ChatToolDefinition[];skipped: SkippedChatMcpServer[];+ trimmed: TrimmedChatMcpServer[];validate(name: string, args: unknown): void;/** Directory reads and OpenMausBot's own agents server need no card; call_tool shows the tool it runs. */view(name: string, args: Record<string, unknown>): ChatToolCallView;@@ -50,6 +55,9 @@ const DEFAULT_CALL_MS = 10 * 60_000;const FRAME_BYTES = 2 * 1024 * 1024;const OUTPUT_BYTES = 50 * 1024;const TOOL_COUNT = 128;+/** ask_user, which the runtime lists after the MCP tools. */+const RUNTIME_TOOLS = 1;+const MCP_TOOL_COUNT = TOOL_COUNT - RUNTIME_TOOLS;const MAX_PAGES = 100;const SCHEMA_BYTES = 64 * 1024;const CATALOG_BYTES = 1024 * 1024;@@ -232,6 +240,12 @@ class ChatMcpClient {}}+export function trimmedToolsNotice(trimmed: readonly TrimmedChatMcpServer[]): string | undefined {+ if (!trimmed.length) return undefined;+ const servers = trimmed.map(({ server, listed, of }) => `"${server}" listed ${listed} of ${of} tools`).join(", ");+ return `${servers} to fit the model's ${TOOL_COUNT}-tool limit; the rest are left out of this turn.`;+}+function boundedText(value: string): string {const bytes = Buffer.from(value);if (bytes.length <= OUTPUT_BYTES) return value;@@ -273,6 +287,8 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]if (integrations?.data && eligible("data")) servers.push(["data", integrations.data]);if (integrations?.highlevel && eligible("highlevel")) servers.push(["highlevel", integrations.highlevel]);if (integrations?.device && eligible("device")) servers.push(["device", integrations.device]);+ const builtIns = servers.length;+ const besideBrowser = servers.some(([, descriptor]) => descriptor === integrations?.browser);for (const [name, server] of Object.entries(integrations?.custom ?? {})) {if (!eligible(name)) continue;const remote = remoteMcpSpec(server) !== undefined;@@ -287,6 +303,7 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]const clients: ChatMcpClient[] = [];const skippable = new Set(Object.keys(integrations?.custom ?? {}));const skipped: SkippedChatMcpServer[] = [];+ const trimmed: TrimmedChatMcpServer[] = [];const started = new Map<string, ChatMcpClient>();let closed = false;let closing: Promise<void> | undefined;@@ -311,8 +328,10 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]const client = new ChatMcpClient(descriptor, computerUse);clients.push(client);started.set(name, client);- const include = (tool: unknown) => scope === undefined || (object(tool) && typeof tool.name === "string"- && ((searchable.has(name) && isDirectoryTool(tool.name)) || allowsTool(scope, { kind: "mcp", server: name, name: tool.name })));+ const computer = descriptor === integrations?.localComputer;+ const keeps = (tool: unknown) => !computer || !object(tool) || typeof tool.name !== "string" || listsComputerTool(tool.name, besideBrowser);+ const include = (tool: unknown) => keeps(tool) && (scope === undefined || (object(tool) && typeof tool.name === "string"+ && ((searchable.has(name) && isDirectoryTool(tool.name)) || allowsTool(scope, { kind: "mcp", server: name, name: tool.name }))));const tools = await client.tools(signal, include, searchable.has(name) ? REMOTE_MCP_STARTUP_MS : STARTUP_MS, observers.get(name));if (!tools.length && scope === undefined && descriptor === integrations?.localComputer) throw new Error("The Local VM listed no tools");// Harness mounts are known by descriptor, never by a name a configured server could claim. A grant@@ -321,6 +340,10 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]return { name, client, launch, builtInBrowser: descriptor === integrations?.browser, agents: descriptor === agentsServer,hostComputer: descriptor === integrations?.localComputer && integrations?.localComputer?.scope === "local-computer", tools };}));+ // The agents server keeps its whole list first; a configured server fits in what the built-ins leave, or is skipped.+ const shares = shareToolBudget(mounts.flatMap((mount, index) => index < builtIns && mount.status === "fulfilled"+ ? [{ name: String(index), tools: mount.value.tools.length, agents: mount.value.agents }] : [])+ .sort((a, b) => Number(b.agents) - Number(a.agents)), MCP_TOOL_COUNT);for (const [index, mount] of mounts.entries()) {const configured = servers[index]![0];if (signal.aborted || closed) throw aborted();@@ -335,14 +358,19 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]await skip(mount.reason);continue;}- const { name: server, client, launch, builtInBrowser, agents, hostComputer, tools } = mount.value;+ const { name: server, client, launch, builtInBrowser, agents, hostComputer, tools: offered } = mount.value;+ const tools = capToolList(offered, shares.get(String(index)));+ if (tools.length < offered.length) {+ trimmed.push({ server, listed: tools.length, of: offered.length });+ console.warn(`chat-mcp: "${server}" listed ${tools.length} of ${offered.length} tools to fit the model's ${TOOL_COUNT}-tool limit`);+ }const staged: Array<{ tool: RegisteredTool; definition: ChatToolDefinition }> = [];try {const originalNames = new Set<string>();for (const tool of tools) {if (!object(tool) || typeof tool.name !== "string" || !tool.name.trim() || originalNames.has(tool.name)) throw new Error("MCP server advertised an invalid or duplicate tool name");originalNames.add(tool.name);- if (definitions.length + staged.length >= TOOL_COUNT) throw new Error("MCP tool count exceeds the 128-tool limit");+ if (definitions.length + staged.length >= MCP_TOOL_COUNT) throw new Error("MCP tool count exceeds the 128-tool limit");if (!object(tool.inputSchema) || tool.inputSchema.type !== "object") throw new Error("MCP tools require an object input schema");if (Buffer.byteLength(JSON.stringify(tool.inputSchema)) > SCHEMA_BYTES) throw new Error("MCP tool schema exceeds the 64KB limit");const schema = compileToolSchema(tool.inputSchema);@@ -411,7 +439,7 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]return { title: chatToolName(tool.server, runs), input: object(args.arguments) ? args.arguments : {}, ask: true, ...(grant ? { grant } : {}) };};return {- definitions, skipped, validate, view, close,+ definitions, skipped, trimmed, validate, view, close,async execute(name, args, callSignal) {validate(name, args);if (callSignal.aborted) { await close(); throw aborted(); }diff --git a/server/drivers/openai-chat-tools.test.ts b/server/drivers/openai-chat-tools.test.tsindex 4cc3a59b77..acf7455dea 100644--- a/server/drivers/openai-chat-tools.test.ts+++ b/server/drivers/openai-chat-tools.test.ts@@ -12,6 +12,7 @@ import { BUILT_IN_DATA_SYSTEM_PROMPT } from "../data/instructions.ts";import type { ProviderInstance, SendTurnInput } from "../contracts.ts";import { removeTempDir } from "../testing/cleanup.ts";import { recordEvents } from "../testing/events.ts";+import { catalogServer, CUA_DRIVER_WINDOWS_TOOLS, syntheticToolNames } from "../testing/cua-driver-tools.ts";import { startFakeHttpMcp } from "../testing/fake-http-mcp-server.ts";import { whopLikeCatalog } from "../testing/whop-like-catalog.ts";import { GrokDriver } from "./grok.ts";@@ -1329,6 +1330,51 @@ describe("a configured MCP server that cannot mount", () => {});});+describe("a turn with the person's Windows computer, the built-in browser and the agents server", () => {+ function catalog(names: readonly string[]) {+ const { dir, server } = catalogServer(names);+ cleanups.push(() => removeTempDir(dir));+ return server;+ }+ const integrations = (agents: number, more: SendTurnInput["integrations"] = {}): SendTurnInput["integrations"] => ({+ localComputer: { ...catalog(CUA_DRIVER_WINDOWS_TOOLS), scope: "local-computer" },+ browser: catalog(syntheticToolNames("agent_browser", 32)),+ agents: catalog(syntheticToolNames("agent", agents)),+ composio: catalog(syntheticToolNames("router", 7)),+ data: catalog(syntheticToolNames("table", 5)),+ ...more,+ });++ it("sends at most 128 tools, ask_user and every agents tool among them", async () => {+ const f = await fixture((_body, response) => answer(response));+ await f.start({ integrations: integrations(42) });+ expect(await f.completed()).toMatchObject({ ok: true });+ const names = f.requests[0].tools!.map((tool) => tool.function.name);+ expect(names).toHaveLength(115);+ expect(names).toContain("ask_user");+ expect(names).toEqual(expect.arrayContaining(syntheticToolNames("agents_agent", 42)));+ expect(names).toEqual(expect.arrayContaining(["computer_click", "computer_type_text", "computer_get_window_state"]));+ expect(names.filter((name) => name.startsWith("computer_browser_"))).toEqual([]);+ expect(f.recorder.events.filter((event) => event.type === "runtime.notice" || event.type === "runtime.error")).toEqual([]);+ });++ it("lists fewer built-in tools when they still overflow, says which, and runs the turn", async () => {+ const f = await fixture((_body, response) => answer(response));+ const warn = console.warn;+ console.warn = () => {};+ try {+ await f.start({ integrations: integrations(51, { composio: catalog(syntheticToolNames("router", 14)), device: catalog(syntheticToolNames("phone", 23)) }) });+ expect(await f.completed()).toMatchObject({ ok: true });+ } finally { console.warn = warn; }+ const names = f.requests[0].tools!.map((tool) => tool.function.name);+ expect(names).toHaveLength(128);+ expect(names.at(-1)).toBe("ask_user");+ expect(f.recorder.events).toContainEqual(expect.objectContaining({ type: "runtime.notice",+ message: `"data" listed 2 of 5 tools, "device" listed 0 of 23 tools to fit the model's 128-tool limit; the rest are left out of this turn.` }));+ expect(f.recorder.events.some((event) => event.type === "runtime.error")).toBe(false);+ });+});+describe("a provider that streams whole tool calls without an index", () => {it("runs both of Gemini's calls from one chunk and answers each by its id", async () => {const f = await fixture((_body, response, round) => {diff --git a/server/drivers/openai-chat.ts b/server/drivers/openai-chat.tsindex 9bfebdfbdc..82b24de043 100644--- a/server/drivers/openai-chat.ts+++ b/server/drivers/openai-chat.ts@@ -13,7 +13,7 @@ import { ASK_USER_TOOL, ASK_USER_TOOL_DEFINITION, askQuestionSummary, parseAskQuimport { allowsTool, parseToolScope } from "../../shared/tool-scope.ts";import { redactSecretsInText } from "../redact.ts";import { toolDetailPreview } from "../tool-summary.ts";-import { ChatToolSessionError, mountChatTools, type ChatToolDefinition, type ChatToolSession, type ChatToolResult } from "./chat-mcp-tools.ts";+import { ChatToolSessionError, mountChatTools, trimmedToolsNotice, type ChatToolDefinition, type ChatToolSession, type ChatToolResult } from "./chat-mcp-tools.ts";import { assertImageTransport, chatImageBudget, chatToolImages, chatUserContent, type ChatContentPart } from "./chat-images.ts";import { promptHalves, volatileContextNote, withContextNote } from "./prompt-split.ts";import { createChatToolApproval, refusal } from "./chat-tool-approval.ts";@@ -617,6 +617,8 @@ export function createOpenAIChatRuntime<Config>(options: RuntimeOptions<Config>)for (const { server, reason } of tools.skipped) {emit({ ...base(turn.threadId, turnId), type: "runtime.notice", message: `MCP server "${server}" was skipped for this turn: ${safeText(reason)}` });}+ const trimmedNotice = trimmedToolsNotice(tools.trimmed);+ if (trimmedNotice) emit({ ...base(turn.threadId, turnId), type: "runtime.notice", message: trimmedNotice });const questionAllowed = options.tools !== false && allowsTool(scope, { kind: "native", name: ASK_USER_TOOL });let optionalQuestionOnly = questionAllowed && tools.definitions.length === 0;// An MCP server squatting ask_user cannot shadow it (dispatch intercepts the name); skip its definition.diff --git a/server/testing/cua-driver-tools.ts b/server/testing/cua-driver-tools.tsnew file mode 100644index 0000000000..98fe386047--- /dev/null+++ b/server/testing/cua-driver-tools.ts@@ -0,0 +1,43 @@+// What Cua Driver 0.28.2 lists on Windows (its MCP reference for that version: 57 tools), and stdio MCP servers that list+// synthetic tools by name, for turns shaped like a real one.+import { mkdtempSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";++export const CUA_DRIVER_WINDOWS_TOOLS: readonly string[] = [+ "list_apps", "list_windows", "get_window_state", "get_accessibility_tree", "get_desktop_state", "get_screen_size",+ "get_cursor_position", "get_config", "get_recording_state", "get_agent_cursor_state",+ "launch_app", "kill_app", "bring_to_front", "set_window_frame", "click", "double_click", "right_click", "drag", "type_text",+ "press_key", "hotkey", "set_value", "scroll", "move_cursor", "zoom",+ "page", "clipboard_read", "clipboard_write", "start_recording", "stop_recording", "replay_trajectory",+ "set_config", "start_session", "end_session", "set_agent_cursor_enabled", "set_agent_cursor_motion",+ "check_permissions", "health_report", "check_for_update", "install_ffmpeg",+ "verify_state", "invoke_menu", "debug_window_info", "set_agent_cursor_theme", "get_browser_state", "browser_prepare",+ "browser_navigate", "browser_click", "browser_type", "browser_dialog", "browser_set_input_files", "browser_download",+ "browser_pointer", "escalate_session", "get_session", "list_sessions", "get_session_state",+];++/** `count` tool names that read as one server's own, `prefix_1` onwards. */+export function syntheticToolNames(prefix: string, count: number): string[] {+ return Array.from({ length: count }, (_, index) => `${prefix}_${index + 1}`);+}++const CATALOG_SERVER = `+import { createInterface } from "node:readline";+const names = JSON.parse(process.env.CATALOG_TOOLS);+const reply = (id, result) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, result }) + "\\n");+createInterface({ input: process.stdin }).on("line", (line) => {+ const request = JSON.parse(line);+ if (request.method === "initialize") reply(request.id, { protocolVersion: "2024-11-05", capabilities: { tools: {} } });+ else if (request.method === "tools/list") reply(request.id, { tools: names.map((name) => ({ name, description: "Synthetic " + name, inputSchema: { type: "object" } })) });+ else if (request.id !== undefined) reply(request.id, { content: [{ type: "text", text: "ran " + request.params?.name }] });+});+`;++/** A stdio MCP server, as a turn's integrations take it, that lists exactly `names`. Remove `dir` when done. */+export function catalogServer(names: readonly string[]): { dir: string; server: { command: string; args: string[]; env: Record<string, string> } } {+ const dir = mkdtempSync(join(tmpdir(), "omb-catalog-mcp-"));+ const script = join(dir, "catalog.mjs");+ writeFileSync(script, CATALOG_SERVER);+ return { dir, server: { command: process.execPath, args: [script], env: { CATALOG_TOOLS: JSON.stringify(names) } } };+}