Skip to content

[MCP] Update WebMCP registration API - #3844

Merged
fellyph merged 6 commits into
WordPress:trunkfrom
bgrgicak:bgrgicak/async-modelcontext-registertool
Aug 28, 2026
Merged

fellyph merged 6 commits into
WordPress:trunkfrom
bgrgicak:bgrgicak/async-modelcontext-registertool

Conversation

@bgrgicak

@bgrgicak bgrgicak commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Updates WebMCP tool registration to use the current document.modelContext API and handle asynchronous tool registration without breaking the Playground website.

Motivation for the change, related issues

Chrome's WebMCP API has moved away from navigator.modelContext; the Chrome WebMCP Imperative API documentation notes that navigator.modelContext is deprecated in Chrome 150 and recommends document.modelContext instead.

The registerTool() API is also asynchronous in newer Chrome builds, so registration failures need to be caught from the returned Promise. WebMCP is still a progressive enhancement, so failed or unavailable WebMCP registration should not break the website.

Implementation details

  • Switches WebMCP registration to document.modelContext only.
  • Makes registerWebMCPTools() return a Promise and await all registerTool() calls.
  • Updates website and Personal WP initialization to catch async WebMCP registration failures and log them.
  • Updates the WebMCP e2e mock and README references to use document.modelContext.

Testing Instructions

  • Ran git diff --check.
  • I could not run Nx lint/tests in this worktree because node_modules is missing. The commit hook also attempted nx format --fix --parallel --uncommitted and reported that Nx modules could not be found.

Summary by CodeRabbit

  • New Features
    • Updated WebMCP integration to use the current document.modelContext API.
    • WebMCP tools now support asynchronous registration.
    • Multiple tools are registered reliably during setup.
  • Bug Fixes
    • Improved registration failure handling and warning reporting.
    • Prevented incomplete registrations when setup encounters an error.
  • Documentation
    • Updated WebMCP documentation to reflect the current API usage.

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates WebMCP tool registration to use Chrome’s current document.modelContext API and to handle asynchronous registerTool() without allowing failures to break the Playground experience.

Changes:

  • Switched WebMCP registration from navigator.modelContext to document.modelContext.
  • Made registerWebMCPTools() async and awaited tool registration.
  • Updated website/personal-wp initialization, e2e mock, and README to align with the new API.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/playground/website/src/lib/state/redux/init-mcp-bridge.ts Awaits WebMCP registration and logs failures without crashing the site.
packages/playground/personal-wp/src/lib/state/redux/init-mcp-bridge.ts Same async-safe WebMCP registration pattern for personal-wp.
packages/playground/mcp/tests/e2e/webmcp.spec.ts Updates e2e mock to provide document.modelContext and async registerTool().
packages/playground/mcp/src/webmcp.ts Migrates registration to document.modelContext and supports async registration.
packages/playground/mcp/README.md Documentation updated to reference document.modelContext.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/playground/website/src/lib/state/redux/init-mcp-bridge.ts Outdated
Comment thread packages/playground/personal-wp/src/lib/state/redux/init-mcp-bridge.ts Outdated
Comment thread packages/playground/mcp/src/webmcp.ts Outdated
Comment thread packages/playground/mcp/src/webmcp.ts Outdated
Comment thread packages/playground/mcp/src/webmcp.ts
@bgrgicak
bgrgicak marked this pull request as draft June 30, 2026 07:12
@bgrgicak bgrgicak self-assigned this Jul 24, 2026
@bgrgicak
bgrgicak marked this pull request as ready for review July 24, 2026 17:49
@akirk
akirk force-pushed the bgrgicak/async-modelcontext-registertool branch from 7e71cee to 47ab963 Compare August 26, 2026 09:26
@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 36a1c972-8f59-4215-928f-ca3a90ad0aff

📥 Commits

Reviewing files that changed from the base of the PR and between 24b524e and c9c7c54.

📒 Files selected for processing (1)
  • packages/playground/mcp/src/webmcp.ts
💤 Files with no reviewable changes (1)
  • packages/playground/mcp/src/webmcp.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

WebMCP now uses document.modelContext. Tool registration supports asynchronous completion, cancellation, aggregated failures, and promise rejection handling in Redux bridges.

Changes

WebMCP registration

Layer / File(s) Summary
Update the WebMCP API contract
packages/playground/mcp/src/webmcp.ts, packages/playground/mcp/README.md, packages/playground/mcp/tests/e2e/webmcp.spec.ts
The API, documentation, and end-to-end mock use document.modelContext. registerTool may complete asynchronously.
Implement asynchronous tool registration
packages/playground/mcp/src/webmcp.ts
registerWebMCPTools validates the document context, tracks an abort controller, registers tools concurrently, waits for completion, and throws an aggregated error for rejected registrations.
Handle asynchronous bridge failures
packages/playground/personal-wp/src/lib/state/redux/init-mcp-bridge.ts, packages/playground/website/src/lib/state/redux/init-mcp-bridge.ts
The Redux bridges handle rejected registration promises with logger.warn instead of synchronous try/catch blocks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to c9c7c

The change updates WebMCP registration and preserves website behavior when registration is unavailable or fails; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant ReduxMCPBridge
  participant registerWebMCPTools
  participant documentModelContext
  participant WebMCPTools
  ReduxMCPBridge->>registerWebMCPTools: start registration
  registerWebMCPTools->>documentModelContext: read document.modelContext
  registerWebMCPTools->>WebMCPTools: register tools concurrently
  WebMCPTools-->>registerWebMCPTools: resolve or reject registrations
  registerWebMCPTools-->>ReduxMCPBridge: resolve or reject with aggregated error
  ReduxMCPBridge->>ReduxMCPBridge: log rejected registration with logger.warn
Loading

Suggested reviewers: akirk

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: updating the WebMCP registration API, including the move to the current registration approach and asynchronous behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@mho22
mho22 removed their request for review August 26, 2026 09:53
@bgrgicak
bgrgicak requested a review from akirk August 27, 2026 19:25

@fellyph fellyph left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@bgrgicak, It all good. I have tested locally.

I just used codex to suggest a few items.

Comment thread packages/playground/mcp/src/webmcp.ts
Comment thread packages/playground/mcp/src/webmcp.ts
Comment thread packages/playground/mcp/src/webmcp.ts Outdated
Comment thread packages/playground/mcp/src/webmcp.ts
@fellyph
fellyph merged commit f29eca6 into WordPress:trunk Aug 28, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants