Repository navigation
fix(webmcp): handle the breaking change to tool registration identity - #3542
Merged
seanmcguire12 merged 3 commits intoNov 24, 2026
Merged
Conversation
…#3540) ## 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](webmachinelearning/webmcp#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](https://webmcp-groceries.wesbos.workers.dev/), 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. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Keeps saved WebMCP tool handles pointing 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. - Adds optional `toolId` to tool descriptors, identities, and the protocol. - Invokes tools by `toolId` when available; old handles now fail cleanly if the registration was removed. - Emits a removal event when a registration is superseded by a same-named replacement. - Legacy clients can opt out of `toolId` in discovery and event payloads. - Bumps `devtools-protocol` to pick up the new WebMCP definitions. <sup>Written for commit 2f51d59. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/browserbase/stagehand/pull/3540?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
🦋 Changeset detectedLatest commit: 6998fda The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 23 files
Architecture diagram
sequenceDiagram
participant SDK as Client SDK (TS/Python)
participant RPC as RPC Client
participant Worker as Stagehand Worker
participant Runtime as Understudy Runtime
participant Page as Browser Page Session
participant Chrome as Chrome (WebMCP)
participant Site as Website
Note over SDK,Chrome: Tool Discovery Flow with Registration Identity
SDK->>RPC: Request tools (includeToolIds=true)
RPC->>Worker: page.webmcp_tools
Worker->>Runtime: pageWebMCPTools(params)
Runtime->>Page: listWebMCPTools(options)
alt Chrome supports toolId
Page->>Chrome: Enable WebMCP
Chrome-->>Page: Tools with toolId
Page->>Page: Track by frameId + name, store toolId
else Older Chrome (no toolId)
Page->>Chrome: Enable WebMCP
Chrome-->>Page: Tools without toolId
Page->>Page: Track by frameId + name only
end
Page-->>Runtime: Tool descriptors
Runtime-->>Worker: Tools (with toolId if included)
Worker-->>RPC: Tool descriptors
RPC-->>SDK: WebMCPTool objects + toolId
Note over SDK,Chrome: Tool Subscription Flow (events)
opt SDK subscribes to toolsAdded/toolsRemoved
SDK->>RPC: page.on(event, includeToolIds=true)
RPC->>Worker: subscribe
Worker->>Runtime: subscribeWebMCPToolsChanged
Runtime->>Page: Add event listener
end
Note over Page,Chrome: Tool Replacement / Removal
alt Tool removed by site
Site->>Chrome: Remove registration
Chrome-->>Page: ToolsRemoved event (with toolId)
Page->>Page: Match by toolId, publish removal if identity
else Tool replaced with same name
Site->>Chrome: Register replacement (new toolId)
Chrome-->>Page: ToolsAdded event (new toolId)
Page->>Page: Detect old toolId differs
Page->>Page: Emit toolsremoved (old identity)
Page->>Page: Emit toolsadded (new tool)
end
Page-->>Runtime: Emit event notification
Runtime-->>Worker: Forward event (with/without toolId)
Worker-->>RPC: Notification
RPC-->>SDK: Async callback invocation
Note over SDK,Chrome: Tool Invocation Flow
SDK->>RPC: invoke(input, toolId if available)
RPC->>Worker: page.webmcp_invoke_tool
Worker->>Runtime: invokeWebMCPTool(frameId, name, toolId)
Runtime->>Page: invokeWebMCPTool(toolId or name)
alt Chrome supports toolId
Page->>Chrome: WebMCP.invokeTool with toolId
else Older Chrome
Page->>Chrome: WebMCP.invokeTool with toolName
end
Chrome-->>Page: Invocation response / error
Page-->>Runtime: Result or "tool not found"
Runtime-->>Worker: Invocation result
Worker-->>RPC: WebMCPInvocation
RPC-->>SDK: Invocation object to await result
alt Tool already removed/replaced
Chrome-->>Page: Error "tool not found"
Page-->>Runtime: Throw error
Runtime-->>Worker: Error response
Worker-->>RPC: Error
RPC-->>SDK: Rejects with "tool not found"
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
miguelg719
approved these changes
Nov 24, 2026
seanmcguire12
deleted the
external/vishalanton16-webmcp-tool-interface
branch
November 24, 2026 20:18
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_storeshandle, 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
toolIdwhen available; a saved handle now fails cleanly with "tool not found" if the page removed the registration.toolIdfrom payloads unless requested.devtools-protocolto pick up the new WebMCP definitions.Written for commit 6998fda. Summary will update on new commits.