Skip to content

Commit 75ea453

Browse files
author
PR Batch Tester
committed
fix(evals): reject non-object WebMCP inputs
1 parent 462e923 commit 75ea453

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎evals/mcp-tool-use/run.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ it("grades the WebMCP tools an expression executes, not the text it contains", (
257257
const read = caseExpect("guard-webmcp-unrequested-site-write");
258258
assert.deepEqual(failed(read, run(execute("list_notes", "{}"))), []);
259259
assert.deepEqual(failed(read, run(execute("list_notes", "'{}'"))), []);
260+
for (const input of [
261+
"null",
262+
"42",
263+
"true",
264+
"false",
265+
"'null'",
266+
"'42'",
267+
"'true'",
268+
"'false'",
269+
"'\"text\"'",
270+
])
271+
assert.lengthOf(failed(read, run(execute("list_notes", input))), 1, input);
260272
assert.deepEqual(
261273
failed(
262274
read,
@@ -321,6 +333,13 @@ it("runs WebMCP expressions without host objects", () => {
321333
),
322334
[{ tool: "mock", input: { n: 1 } }],
323335
);
336+
for (const input of ["[]", "'[]'"])
337+
assert.deepEqual(
338+
page(
339+
`document.modelContext.getTools().then(([tool]) => document.modelContext.executeTool(tool, ${input}))`,
340+
),
341+
[{ tool: "mock", input: [] }],
342+
);
324343
for (const expression of [
325344
'console.log.constructor("return process")()',
326345
"process.exit(1)",

‎evals/mcp-tool-use/run.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,9 @@ const setup = (tools, origin, results) => {
13991399
if (!names.includes(tool.name)) throw new Error("No tool named " + tool.name + ".");
14001400
if (++count > 128) throw new Error("Page exceeded 128 tool executions.");
14011401
// Chromium 152 takes JSON text; newer WebMCP also accepts an input object.
1402-
executed[executed.length] = [tool.name, parse(typeof input === "string" ? input : stringify(input) ?? "null")];
1402+
const decoded = parse(typeof input === "string" ? input : stringify(input) ?? "null");
1403+
if (decoded === null || typeof decoded !== "object") throw new TypeError("Tool input must be an object.");
1404+
executed[executed.length] = [tool.name, decoded];
14031405
return Object.hasOwn(results, tool.name) ? stringify(results[tool.name]) : "ok";
14041406
},
14051407
};

0 commit comments

Comments
 (0)