While testing WebMCP tool registration and invocation in a browser implementation, I hit two API details that were easy to misread from the current examples/spec text.
Observed behavior:
const tools = await document.modelContext.getTools();
const tool = tools.find((entry) => entry.name === "example_tool");
await document.modelContext.executeTool(tool, { message: "hello" });
// Fails with an input parsing / type error in the tested runtime.
await document.modelContext.executeTool(tool, JSON.stringify({ message: "hello" }));
// Succeeds in the tested runtime.
console.log(typeof tool.inputSchema);
// "string" in the tested runtime, containing serialized JSON schema.
The shape that worked was:
- Await
document.modelContext.getTools().
- Pass the
RegisteredTool object returned by getTools() into executeTool(), not the tool name.
- Pass JSON-encoded argument text into
executeTool().
- Parse returned
inputSchema metadata when it is exposed as a serialized JSON string.
It would help implementers if the explainer/spec/docs explicitly state whether executeTool arguments are intended to be a JavaScript object, a JSON string, or implementation-dependent for now, and whether returned tool schemas are expected to be structured objects or serialized strings.
If the current observed behavior is the intended contract, a small normative example for executeTool would prevent a class of false-negative debugging sessions where tools are registered correctly but every manual execution attempt appears broken.
While testing WebMCP tool registration and invocation in a browser implementation, I hit two API details that were easy to misread from the current examples/spec text.
Observed behavior:
The shape that worked was:
document.modelContext.getTools().RegisteredToolobject returned bygetTools()intoexecuteTool(), not the tool name.executeTool().inputSchemametadata when it is exposed as a serialized JSON string.It would help implementers if the explainer/spec/docs explicitly state whether
executeToolarguments are intended to be a JavaScript object, a JSON string, or implementation-dependent for now, and whether returned tool schemas are expected to be structured objects or serialized strings.If the current observed behavior is the intended contract, a small normative example for
executeToolwould prevent a class of false-negative debugging sessions where tools are registered correctly but every manual execution attempt appears broken.