You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0852361
Browse filesBrowse the repository at this point in the historyBrowse files
WebMCP: Reject tool results that can't be converted to a string
Imperative and declarative WebMCP tools both turn a non-object result
into a string with `ScriptValue::ToString()`, which calls
`ToString(context).ToLocalChecked()`. Converting a Symbol throws, so
the `MaybeLocal` is empty and the renderer hits a fatal V8 error
("Empty MaybeLocal"):
await document.modelContext.registerTool({
name: 'tool',
description: 'desc',
execute: () => Symbol(),
});
const [tool] = await document.modelContext.getTools();
document.modelContext.executeTool(tool); // Crash.
A declarative tool crashes the same way through
`e.respondWith(Promise.resolve(Symbol()))`.
This CL converts these results inside a `v8::TryCatch`, and fails the
execution when conversion throws, the same way both paths already
handle an object that can't be serialized to JSON. `executeTool()`
then rejects with `OperationError`. For imperative tools this matches
the spec: "invoke the execute callback" serializes the result to a
JSON string, which throws for a Symbol, so the execution fails with
"unserializable result". In `ModelContext`, the object and non-object
branches now share one `TryCatch`.
How other non-object results, such as strings and `undefined`, should
serialize is a separate question, which I raised in
webmachinelearning/webmcp#361.
Adds unserializable-result cases (a Symbol, an object with a BigInt
property, a throwing toJSON(), and a throwing getter) to the imperative
executeTool-error-window-onerror test, and a declarative
executeTool-respondWith-unserializable test covering the same cases. The
Symbol cases crash without this CL. Also adds me to AUTHORS.
[email protected], [email protected]
Bug: None
Change-Id: I6266226ae361e12e52df65b218b70f6a3102aba5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8640683
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Aadharsh Pannirselvam <[email protected]>
Commit-Queue: Khushal Sagar <[email protected]>
Reviewed-by: Khushal Sagar <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1740992}
0 commit comments