fix(webmcp): handle the breaking change to tool registration identity

Merged
SE
8d ago
+296-94

thanks @antonvishal for the contribution here!

Why

A website can replace a tool and give the new tool the same name. If Stagehand calls a tool it found earlier using only that name, it can accidentally run the replacement. Chrome now gives each registration its own ID. WebMCP PR #348

What

Stagehand uses that ID in TypeScript and Python to call the exact tool it found. If the website has removed it, the call fails. Older Chrome versions still look up tools by name.

How

Verified on Chrome 158 and Chrome Dev 160 with both SDKs. On the WebMCP groceries demo, save the get_stores handle, navigate away, then return. On Chrome Dev 160, the saved handle should fail and a freshly discovered handle should return the stores.


Summary by cubic

Keeps saved WebMCP tool handles pointed at their original registration so a page that reuses a tool name can't redirect a previously discovered handle to a replacement tool. Chrome now assigns every registration a toolId; Stagehand passes it through in TypeScript and Python when Chrome supports it, and falls back to name-based lookup on older versions.

Behavior changes

  • Invokes tools by toolId when available; a saved handle now fails cleanly with "tool not found" if the page removed the registration.
  • Emits a removal event when a registration is superseded by a same-named replacement, then publishes the replacement.
  • Keeps legacy clients working by omitting toolId from payloads unless requested.
  • Bumps the protocol to 3.2.0 and devtools-protocol to pick up the new WebMCP definitions.