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" }) +})