Repository navigation
Commit 9676902
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}1 parent 91d0bab commit 9676902
2 files changed
Lines changed: 108 additions & 0 deletions
File tree
- webmcp
- declarative
- imperative
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
74 | 128 | | |
75 | 129 | | |
76 | 130 | | |
0 commit comments