Skip to content

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

Merged
seanmcguire12 merged 3 commits into
mainfrom
external/vishalanton16-webmcp-tool-interface
Nov 24, 2026
Merged

seanmcguire12 merged 3 commits into
mainfrom
external/vishalanton16-webmcp-tool-interface

Conversation

@seanmcguire12

@seanmcguire12 seanmcguire12 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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.

Written for commit 6998fda. Summary will update on new commits.

View guided diff Turn on auto-fix

…#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. -->
@seanmcguire12
seanmcguire12 requested a review from a team as a code owner November 24, 2026 19:48
@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6998fda

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand-protocol Minor
browse Patch
@browserbasehq/stagehand-examples Patch
@browserbasehq/stagehand-integrations-claude-cua-sdk Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/eve Patch
@browserbasehq/stagehand-integrations-gemini-cua-sdk Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-claude-code Patch
@browserbasehq/stagehand-integrations-codex Patch
@browserbasehq/stagehand-integrations-cursor Patch
@browserbasehq/stagehand-integrations-deepagents-sdk Patch
@browserbasehq/stagehand-integrations-fx Patch
@browserbasehq/stagehand-integrations-mastra Patch
@browserbasehq/stagehand-integrations-pi-sdk Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch
@browserbasehq/stagehand-integrations-eve-harness Patch

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

@socket-security

socket-security Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​devtools-protocol@​0.0.1657692 ⏵ 0.0.1740066100 +110084 +598 +1100

View full report

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/sdk-python/tests/test_page.py Resolved
@seanmcguire12
seanmcguire12 merged commit 8194de9 into main Nov 24, 2026
196 of 199 checks passed
@seanmcguire12
seanmcguire12 deleted the external/vishalanton16-webmcp-tool-interface branch November 24, 2026 20:18
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.

3 participants