From 491cea357d2289c8250d8b1fd281ffcadb746693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=98=BC=F0=9D=99=A3=F0=9D=99=99=F0=9D=99=A7?= =?UTF-8?q?=F0=9D=99=9A=F0=9D=99=AC=20=F0=9D=99=95=F0=9D=99=AE=F0=9D=99=9B?= <4560883+andrew-zyf@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:42:32 +0800 Subject: [PATCH] agy-cli: run_command's toolSummary no longer collides with agy's own (#1174) agy-cli forwards a run_command tool that declares toolSummary when agy adds its own. agy adds a required toolSummary to the MCP tools it loads. When the client's own run_command already lists toolSummary as required, the duplicate makes the schema invalid and the toolbox fails to start. The bridge now drops toolSummary from run_command's required list when it lists the tool. On the way back it fills in "Run command" when agy kept the summary to itself and the client's schema declares the property. A summary the model sent is kept, and a schema without the property is left alone. Run at 52b77b78 on mote: packages/agy-cli `bun test` 25/25. Broken by hand: with main's index.mjs, the new tool-summary test goes red. The author checked a live agy client: run_command is the only tool that requires toolSummary, and an agy-to-magpie-to-agy session ran `pwd`. Not tried here: a live agy session, since the local agy account is disabled. Co-authored-by: andrew-zyf --- packages/agy-cli/agy-cli.test.mjs | 1 + packages/agy-cli/index.mjs | 14 ++++++-- packages/agy-cli/test/tool-summary.mjs | 46 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 packages/agy-cli/test/tool-summary.mjs diff --git a/packages/agy-cli/agy-cli.test.mjs b/packages/agy-cli/agy-cli.test.mjs index fd1a8a1..5a10a2b 100644 --- a/packages/agy-cli/agy-cli.test.mjs +++ b/packages/agy-cli/agy-cli.test.mjs @@ -23,6 +23,7 @@ for (const [name, mocks] of [ ["catalog.mjs", false], ["step-usage.mjs", false], ["tool-schema.mjs", false], + ["tool-summary.mjs", false], ["usage-settlement.mjs", false], ["steer-in-session.mjs", false], ["repeat-batch.mjs", false], diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 1bb65f3..6250ff3 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -2325,9 +2325,14 @@ class Proc { throw new Error("agy bridge: no prompt in flight for MCP call") } const name = message.name - const args = message.arguments ?? {} + let args = message.arguments ?? {} if (!args || typeof args !== "object" || Array.isArray(args)) throw new Error("agy bridge: invalid tool arguments") - if (!this.tools.some((tool) => tool.name === name)) throw new Error(`agy bridge: undeclared tool ${name}`) + const tool = this.tools.find((item) => item.name === name) + if (!tool) throw new Error(`agy bridge: undeclared tool ${name}`) + // agy consumes its internal toolSummary instead of forwarding it to MCP. + if (name === "run_command" && tool.inputSchema?.properties?.toolSummary && !Object.hasOwn(args, "toolSummary")) { + args = { ...args, toolSummary: "Run command" } + } const signature = stableJSON(args) const running = turn.calls.find((call) => call.deferred && !call.lateDelivered && call.name === name && stableJSON(call.arguments) === signature) @@ -4138,6 +4143,11 @@ function normalizeTools(body) { throw new UnsupportedContent(`an invalid schema for tool ${tool.name}`) } const inputSchema = ensureGeminiArrayItems(sanitizeInputSchema(expandToolSchema(rawSchema))) + // agy adds its own required toolSummary to MCP tools. A duplicate makes + // the resulting JSON Schema invalid before the agent can start. + if (tool.name === "run_command" && Array.isArray(inputSchema.required)) { + inputSchema.required = inputSchema.required.filter((key) => key !== "toolSummary") + } tools.push({ name: tool.name, description: typeof tool.description === "string" ? tool.description : "", diff --git a/packages/agy-cli/test/tool-summary.mjs b/packages/agy-cli/test/tool-summary.mjs new file mode 100644 index 0000000..503cd72 --- /dev/null +++ b/packages/agy-cli/test/tool-summary.mjs @@ -0,0 +1,46 @@ +import { test } from "node:test" +import assert from "node:assert/strict" +import { baseBody, createBridgeKit, readSse } from "./testkit.mjs" + +async function callRunCommand(inputSchema, args) { + const kit = await createBridgeKit() + try { + let listed + kit.prompts.push(async (agent) => { + listed = await agent.listTools() + await agent.tool("run_command", args) + }) + const body = baseBody({ tools: [{ name: "run_command", input_schema: inputSchema }] }) + const result = await readSse(await kit.request(body)) + return { schema: listed.result.tools[0].inputSchema, call: result.content.find((item) => item.type === "tool_use") } + } finally { + await kit.dispose() + } +} + +test("run_command avoids agy's toolSummary collision and restores the argument for the client", async () => { + const schema = { + type: "object", + properties: { CommandLine: { type: "string" }, toolSummary: { type: "string" } }, + required: ["CommandLine", "toolSummary"], + additionalProperties: false, + } + const result = await callRunCommand(schema, { CommandLine: "pwd" }) + assert.deepEqual(result.schema.required, ["CommandLine"]) + assert.deepEqual(result.call.input, { CommandLine: "pwd", toolSummary: "Run command" }) + assert.deepEqual(schema.required, ["CommandLine", "toolSummary"]) +}) + +test("run_command keeps supplied summaries and does not add one to unrelated schemas", async () => { + const schema = { + type: "object", + properties: { CommandLine: { type: "string" }, toolSummary: { type: "string" } }, + required: ["CommandLine", "toolSummary"], + } + const supplied = await callRunCommand(schema, { CommandLine: "pwd", toolSummary: "Show location" }) + assert.equal(supplied.call.input.toolSummary, "Show location") + const withoutSummary = await callRunCommand({ + type: "object", properties: { command: { type: "string" } }, required: ["command"], additionalProperties: false, + }, { command: "pwd" }) + assert.deepEqual(withoutSummary.call.input, { command: "pwd" }) +})