diff --git a/src/webmcp.test.ts b/src/webmcp.test.ts new file mode 100644 index 000000000..4c953051b --- /dev/null +++ b/src/webmcp.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from "bun:test"; + +import { webMcpExecuteInput } from "./webmcp.js"; + +describe("webMcpExecuteInput", () => { + it("ignores a tool whose inputSchema getter throws", () => { + const broken = { name: "broken" } as { + name: string; + inputSchema?: unknown; + }; + Object.defineProperty(broken, "inputSchema", { + get() { + throw new Error("bad descriptor"); + }, + }); + + expect(webMcpExecuteInput([broken], { n: 1 })).toEqual({ n: 1 }); + }); + + it("still uses JSON input when another tool reports a JSON string schema", () => { + const broken = { name: "broken" } as { + name: string; + inputSchema?: unknown; + }; + Object.defineProperty(broken, "inputSchema", { + get() { + throw new Error("bad descriptor"); + }, + }); + + expect( + webMcpExecuteInput( + [ + broken, + { name: "native", description: "", inputSchema: '{"type":"object"}' }, + ], + { n: 1 }, + ), + ).toBe('{"n":1}'); + }); +}); diff --git a/src/webmcp.ts b/src/webmcp.ts index 68c8bdaf4..07dd97964 100644 --- a/src/webmcp.ts +++ b/src/webmcp.ts @@ -268,7 +268,13 @@ export function webMcpExecuteInput( args: Record, ): object { const copied = plain(args); - return frameTools.some((tool) => typeof tool?.inputSchema === "string") + return frameTools.some((tool) => { + try { + return typeof tool?.inputSchema === "string"; + } catch { + return false; + } + }) ? (JSON.stringify(copied) as unknown as object) : copied; }