Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/webmcp.test.ts
Original file line number Diff line number Diff line change
@@ -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}');
});
});
8 changes: 7 additions & 1 deletion src/webmcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ export function webMcpExecuteInput(
args: Record<string, unknown>,
): 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;
}
Expand Down