Skip to content

Pass WebMCP executeTool input as an object - #20

Closed
gil-- wants to merge 1 commit into
igrigorik:mainfrom
gil--:fix/executetool-object-input
Closed

gil-- wants to merge 1 commit into
igrigorik:mainfrom
gil--:fix/executetool-object-input

Conversation

@gil--

@gil-- gil-- commented Oct 16, 2026

Copy link
Copy Markdown

Problem

Every page tool call fails with WebMCP tool execution failed on Chrome 155. The WebMCP spec now declares the input as an object:

Promise<DOMString> executeTool(RegisteredTool tool, optional object inputObject, optional ModelContextExecuteToolOptions options = {});

The page bridge still passes JSON.stringify(args). Chrome 155's native ModelContext rejects that string before the tool runs:

TypeError: Failed to execute 'executeTool' on 'ModelContext': invalid input object: value is not an object

The lifecycle replaces the page's error text with fixed text, so the agent sees only the generic message, about 2 ms after the call.

Fix

  • page-bridge.js passes the arguments object.
  • Older DOMString-era ModelContext builds turn an object into "[object Object]" and reject with UnknownError before the callback runs. On that rejection, if no toolactivated event fired for the tool, the bridge retries once with the JSON string. A tool whose callback already ran is never retried.
  • webmcp-polyfill.js accepts the object form (cloned through JSON, undefined becomes {}) and still accepts a JSON string from older callers.

Testing

  • pnpm run check: typecheck, lint, 67 files / 973 tests pass. New tests cover the object input in the polyfill, the legacy string retry, and no retry after the callback activated.
  • Headless Chrome 155.0.8059.84 (native document.modelContext, no flags) on a live Shopify storefront, calling search_catalog with { catalog: { query: "sticker" } } through the page bridge:
    • v0.10.1: {"error":{"code":-32000,"message":"Tool execution failed"}}
    • this branch: the tool result (5 products)

I did not run the WPT browser suite (test:browser:webmcp-wpt).

🤖 Generated with Claude Code

The WebMCP spec now declares executeTool(tool, optional object inputObject),
and Chromium 155 rejects the JSON string the page bridge was passing
("invalid input object: value is not an object"). Every page tool call
failed before reaching the tool, surfacing as "WebMCP tool execution failed".

The bridge now passes the arguments object. If an older DOMString-era
ModelContext rejects it with UnknownError before the callback activates,
it retries once with the JSON string, so no tool runs twice. The polyfill
accepts both forms.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gil--
gil-- force-pushed the fix/executetool-object-input branch from c52458e to 9ede67b Compare October 16, 2026 17:22
@gil--
gil-- marked this pull request as ready for review October 16, 2026 17:22
@igrigorik

Copy link
Copy Markdown
Owner

Dupe of #19, closing.

@igrigorik igrigorik closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants