Repository navigation
Add outputSchema to ModelContextTool and RegisteredTool - #254
beaufortfrancois wants to merge 3 commits into
Conversation
Codify WebMCP JSON Schema subset (Draft 2020-12) per 2026-03-05 CG resolution.
Meta-validation in registerTool() (TypeError on invalid schema) and input
validation in executeTool() parallel block before tool execute steps
(DataError with {path,reason,schemaPath} for agent self-correction).
Spec-only per review; WPT split to web-platform-tests/wpt (tentative).
Coordinates with webmachinelearning#254 (outputSchema, same dictionaries).
|
Is this still planned on being added? |
a7e008f to
a988ee0
Compare
I hope so :) 🤞 @domfarolino I've started experimenting with |
a988ee0 to
ec56f58
Compare
markafoltz
left a comment
There was a problem hiding this comment.
A few questions/comments about how the serialization result is passed around (might be missing some key idea)
| @@ -170,12 +170,21 @@ A <dfn>tool definition</dfn> is a [=struct=] with the following [=struct/items=] | |||
There was a problem hiding this comment.
What is the value if the serialization algorithm fails? Is it empty string or null?
There was a problem hiding this comment.
If serialization fails, registerTool() rejects before a tool definition is created, so the value is never set. If no schema is provided, the value is the empty string. The tool definition items now say this normatively.
| DOMString title; | ||
| required DOMString description; | ||
| object inputSchema; | ||
| object outputSchema; |
There was a problem hiding this comment.
Can we make both inputSchema and outputSchema required?
There was a problem hiding this comment.
I'd keep outputSchema optional, as it is in MCP, where tools with unstructured output don't declare one. Making inputSchema required would change existing behavior: ModelContextTool.inputSchema would need to be required too, or default to something like {"type": "object"}. I'd rather handle that in a separate issue than grow this PR. Shall I file one?
There was a problem hiding this comment.
Note that https://chromium-review.googlesource.com/c/chromium/src/+/6850268 was the CL was made inputSchema optional
There was a problem hiding this comment.
Making these values required is desirable for security; they allow agents to enforce that tool inputs and outputs are shaped as structured data and improves spotlighting defenses. It won't be possible to for them to ship as optional, and make required later.
Let's discuss further in a separate issue/PR and land this with the algorithm.
markafoltz
left a comment
There was a problem hiding this comment.
Looks good % a few optional suggested edits
|
|
||
| 1. Return the result of [=serializing a JavaScript value to a JSON string=] given |schema|. | ||
|
|
||
| <div class="note"> |
There was a problem hiding this comment.
This note is not rendering with the Note: prefix, please check this is the right class?
| "<code>inputSchema: { toJSON() {return HTMLDivElement;}}</code>", or | ||
| "<code>outputSchema: { toJSON() {return undefined;}}</code>".</p></li> | ||
|
|
||
| <li><p><i>Re-throws exceptions</i> thrown by "<code>JSON.stringify()</code>", e.g., when |
There was a problem hiding this comment.
Suggestion:
Re-throws exceptions thrown by
JSON.stringify(), e.g. when the object value has a circular reference.
| <div class="note"> | ||
| <p>The serialization algorithm above throws exceptions in the following cases:</p> | ||
| 1. Let |stringified input schema| be the result of [=serializing a tool schema=] given |tool|'s | ||
| {{ModelContextTool/inputSchema}} if it [=map/exists=], and undefined otherwise. If this threw an |
There was a problem hiding this comment.
Suggestion:
If [=serializing a tool schema=] threw an exception,
| </ol> | ||
| </div> | ||
| 1. Let |stringified output schema| be the result of [=serializing a tool schema=] given |tool|'s | ||
| {{ModelContextTool/outputSchema}} if it [=map/exists=], and undefined otherwise. If this threw an |
There was a problem hiding this comment.
If [=serializing a tool schema=] threw an exception,
| @@ -363,6 +363,7 @@ for (const tool of tools) { | |||
| console.log(`Tool: ${tool.name} (from ${tool.origin})`); | |||
| console.log(`Description: ${tool.description}`); | |||
| console.log(`Parameters schema:`, tool.inputSchema); | |||
There was a problem hiding this comment.
Perhaps Input schema: ?
This PR adds an optional
outputSchemamember to theModelContextToolandRegisteredTooldictionaries to enable browser agents and in-page agents to help LLMs reliably reason about the return values of tools.While
responseConstraintwas previously discussed, that name is too specific to the Built-in AI / Prompt API. TheoutputSchemaname aligns directly with the MCP Tools specificationoutputSchemaused to define expected structured outputs with JSON Schema.FIX #9
Preview | Diff