Skip to content

Agents Manager: expose registry abilities through WebMCP with a meta-based gate - #114085

Draft
gziolo wants to merge 17 commits into
trunkfrom
update/agents-manager-webmcp-registry-exposure
Draft

gziolo wants to merge 17 commits into
trunkfrom
update/agents-manager-webmcp-registry-exposure

Conversation

@gziolo

@gziolo gziolo commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Part of BSKY-2070

Follow-up to #113839.

Proposed Changes

  • Expose core/abilities registry abilities alongside REST and provider-chain abilities on supported editor pages with isDevMode: true and a WebMCP-capable browser. Opening chat is not required for independently registered abilities, including Agents Manager’s editor tools.
  • Keep provider useAbilitiesSetup hooks owned solely by chat, with live chat actions. WebMCP queries providers and subscribes to the registry without mounting a second setup hook, avoiding conflicts with sidebar processing state. Third-party abilities registered only by chat setup become available after chat opens.
  • Merge sources first-wins by original ability name: REST, provider chain, then registry. Collect all winning definitions and their owners into one live snapshot. Apply exposure after precedence so an opted-out winner hides its same-named fallbacks.
  • Use the same exposure and normalized-name collision policy for registration and dispatch. Before execution, reject a missing, opted-out, colliding, or changed definition and reconcile registrations. Execute through the owner from the validated snapshot without another cross-source lookup. The selected provider chain and registry still dispatch internally by ability name under their existing contracts. A replacement owner with an identical descriptor can keep its registration; callbacks from replaced or disposed registrations are rejected.
  • Apply meta.webmcp.public for explicit channel opt-in/out, then meta.public for read-only opt-in, then the transitional allowlists. Registry execution retains permission callbacks and schema validation. Existing canvas guards cover known abilities; other plugins remain responsible for permissions and target scoping.
  • Replace polling with registry subscriptions and synchronization when the provider chain changes. Isolate source, descriptor, and registration failures so other tools remain available. Preserve complete browser annotations when retrying registration on a subsequent reconcile.
  • Route REST execution through GET for reads, DELETE for destructive and idempotent writes, and POST for other writes. Keep ability-specific projections in contracts.ts, exposure policy in exposure.ts, and source composition in compose-tool-providers.ts.
  • Update packages/agents-manager/src/webmcp/README.md and AGENTS.md. Consolidate overlapping tests while retaining coverage for precedence, ownership, collisions, registration recovery, and cancellation.

Why are these changes being made?

The prototype exposed a fixed set of abilities. Registry discovery and metadata flags let plugins participate without extending client-side allowlists. Exposure, browser hints, and execution must refer to the same current definition and source, including when a source recovers or an ability changes after registration.

The REST source remains a local stand-in for @wordpress/core-abilities. The WebMCP README describes the metadata, loading, and query-argument requirements that would let us remove it.

Future considerations

Timed discovery retries are deliberately omitted for this dev-mode experiment. Successful REST discovery is cached for the mount; later tool-execution failures do not invalidate that cache or remove tools. Failed discovery is uncached and can be attempted again after a registry/provider change or another tool dispatch. Without further activity, recovery may require a remount or reload. Other sources remain available, and a failed higher-priority source can allow a same-named fallback to win.

If automatic recovery becomes a production requirement, consider bounded discovery retries with backoff. Successful preloading of the exact discovery request could avoid the initial network request, but preload coverage has not been verified here. Tool executions, especially writes, are never retried automatically.

Deploy dependencies

None added by this PR. The experiment uses the existing Agents Manager inline development-mode flag and ability sources; REST tools require the existing site's Abilities API. Removing the local REST source would require the upstream changes described in the WebMCP README.

Testing Instructions

Automated validation

Passed on the current branch:

  • yarn test-packages 'agents-manager|jetpack-ai-sidebar' --runInBand — 202 suites, 3,643 tests.
  • yarn typecheck-packages
  • NODE_OPTIONS=--max-old-space-size=8192 yarn typecheck-client
  • ESLint on all changed TypeScript/TSX files.

The focused WebMCP and hook suites pass: 9 suites, 79 tests. Coverage includes source precedence and opt-outs, dispatch from a single validated snapshot, collisions appearing after registration, private colliding abilities, recovery through fresh registrations, GET/POST/DELETE routing, partial discovery failures, malformed descriptors, cancellation, and disposal races.

Live browser checks and a fresh production bundle-size comparison after rebasing remain outstanding; previous bundle measurements are not representative of the current branch.

Calypso

Run yarn start using the existing configured port. Regression checks: open and reopen Agents Manager on a hosting screen; confirm normal chat ability execution. Confirm non-editor screens do not register WebMCP tools or fetch the am-webmcp chunk.

Dashboard

Run yarn start-dashboard. Regression checks: open Agents Manager and confirm normal chat operation. Confirm the non-editor surface does not expose WebMCP tools.

Simple and Atomic editors

Sandbox widgets.wp.com, then run yarn dev --sync from apps/agents-manager. Open a post, page, custom-post-type block editor, or site editor with isDevMode: true in a WebMCP-capable browser.

Must test:

  1. With chat closed, follow browser discovery and the block-tree/edit, pattern insertion, and media upload flows in packages/agents-manager/src/webmcp/README.md. Confirm available tools target the current editor. Use disposable content and leave editor changes unpublished.
  2. Register an opted-in client ability through the real registry. Confirm the browser discovers it, executes its callback, and removes it after unregistration without reloading.
  3. Temporarily fail REST discovery, restore it, and trigger a registry change. Confirm server tools return and other sources remain usable during the failure.
  4. Navigate between editors and confirm registrations follow the current scope. Reload with development mode disabled and confirm tools are absent.

Regression checks: open and close chat while WebMCP is active; verify provider abilities and chat callbacks still work and registrations survive the chat lifecycle. During an active sidebar block request, trigger an Agents Manager rerender and confirm the shimmer and pending target remain active until the request completes. Check lazy-chunk requests and the browser console.

WooCommerce AI and Reader Chat

Using the same sandbox bundle setup, open the WooCommerce AI admin and Reader Chat on a public blog. Regression checks: confirm existing chat functionality and no WebMCP registrations on non-editor pages. Include a self-hosted Jetpack/WooCommerce test environment where available.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • For UI changes, have you tested the affected components in dark mode?
  • Have you tested accessibility for your changes? Ensure the feature remains usable with various user agents (e.g., browsers), interfaces (e.g., keyboard navigation), and assistive technologies (e.g., screen readers) (PCYsg-S3g-p2).
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Webpack Runtime (~49 bytes added 📈 [gzipped])

Details
Name Parsed Gzip
runtime +164 B +0.1% +49 B +0.1%

Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded.

App Entrypoints (~22 bytes added 📈 [gzipped])

Details
Name Parsed Gzip
entry-stepper +38 B +0.0% +11 B +0.0%
entry-main +38 B +0.0% +11 B +0.0%

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~2073 bytes added 📈 [gzipped])

Details
Name Parsed Gzip
am-webmcp +141.59 kB +48.4% +41.51 kB +39.3%
am-editor-abilities +3.70 kB +0.1% +1.04 kB +0.1%
plugin-recommendations +3.68 kB +2.6% +989 B +2.4%
theme +38 B +0.0% +12 B +0.0%
am-selected-block +25 B +0.0% +50 B +0.0%
am-page-design-renderer +25 B +0.0% +50 B +0.0%
am-font-picker +25 B +0.0% +50 B +0.0%
am-color-picker +25 B +0.0% +50 B +0.0%
am-button-picker +25 B +0.0% +50 B +0.0%
patterns +25 B +0.0% +50 B +0.0%

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~130 bytes added 📈 [gzipped])

Details
Name Parsed Gzip
async-load-automattic-agents-manager +370 B +0.0% +80 B +0.0%
async-load-automattic-global-styles-src-components-global... +25 B +0.0% +50 B +0.0%

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

@github-actions

This comment was marked as outdated.

@gziolo gziolo self-assigned this Sep 8, 2026
@gziolo
gziolo requested a review from artpi September 9, 2026 10:13
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Sep 9, 2026
@gziolo
gziolo requested a review from glendaviesnz September 9, 2026 10:13
@gziolo

gziolo commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@artpi and @glendaviesnz, I'm still learning the codebase and iterating on the WebMCP integration. However, I would appreciate any pointers if you notice anything out of the ordinary. The primary goal here is to reuse the client-side abilities registry from WordPress core as the source for WebMCP tools. In addition, I would like to establish conditions for how these abilities get approved as candidates for WebMCP tools. I'm happy to extract parts of this exploration if you believe some aspects could land in production already.

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.

🟡 Changes recommended

Provider dispatch can bypass the validated definition, and malformed schemas can halt reconciliation of otherwise valid tools.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Extends Agents Manager’s experimental WebMCP adapter to expose eligible REST, provider-chain, and WordPress registry abilities.

Changes:

  • Adds metadata-based exposure, source precedence, collision handling, and REST method routing.
  • Replaces polling with registry subscriptions and live reconciliation.
  • Expands documentation and regression coverage.
File summaries
File Description
packages/agents-manager/WEBMCP.md Documents sources, policy, lifecycle, and testing.
packages/agents-manager/AGENTS.md Clarifies WebMCP versus chat routing.
src/webmcp/types.ts Expands WebMCP contracts and annotations.
src/webmcp/server-ability-provider.ts Implements REST discovery and execution routing.
src/webmcp/registry-tool-provider.ts Adds registry-backed execution.
src/webmcp/provider-abilities-setup.tsx Extracts external ability setup.
src/webmcp/mount.ts Composes sources and store subscription.
src/webmcp/exposure.ts Implements metadata exposure and collision policy.
src/webmcp/contracts.ts Centralizes ability-specific projections.
src/webmcp/compose-tool-providers.ts Adds first-wins source composition.
src/webmcp/adapter.ts Adds reconciliation and stale-definition checks.
src/webmcp/ability-names.ts Centralizes policy names.
src/webmcp/__tests__/server-ability-provider.test.ts Tests REST routing and retries.
src/webmcp/__tests__/registry-tool-provider.test.ts Tests registry execution.
src/webmcp/__tests__/mount.test.ts Tests lifecycle and precedence.
src/webmcp/__tests__/exposure.test.ts Tests exposure rules and collisions.
src/webmcp/__tests__/contracts.test.ts Tests schema and description projection.
src/webmcp/__tests__/compose-tool-providers.test.ts Tests provider composition.
src/webmcp/__tests__/adapter.test.ts Expands adapter regression coverage.
src/utils/load-external-providers.ts Makes merged provider contracts defined-only.
src/utils/legacy-style-variation-css.ts Uses shared record validation.
src/utils/is-record.ts Adds shared object narrowing.
src/utils/canvas-guard.ts Requires a defined provider.
src/utils/ability-completion-broadcast.ts Requires a defined provider.
src/utils/__tests__/canvas-guard.test.ts Updates guard tests for defined providers.
src/utils/__tests__/ability-completion-broadcast.test.ts Updates broadcast tests.
src/hooks/use-webmcp-tools.ts Replaces polling with mounted synchronization.
src/hooks/__tests__/use-webmcp-tools.test.ts Tests registry and provider synchronization.
src/components/agents-manager.tsx Uses extracted WebMCP setup component.
src/components/__tests__/agent-setup.test.tsx Isolates setup tests from WebMCP runtime.
Review details
  • Files reviewed: 30/30 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

gziolo and others added 11 commits October 28, 2026 12:33
…based gate

Read client abilities from the core/abilities store and register them as
WebMCP tools. Exposure follows meta.webmcp.public first, then meta.public
for read-only abilities, then the existing allowlists. Replace the
two-second polling with a store subscription, skip colliding tool names,
add untrustedContentHint, and keep registering other tools when one fails.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UUhsdoUsXmAhdW4sFxUdLL
withCanvasGuard() and withAbilityCompletionBroadcast() now take a
provider and return a wrapped provider. The merged provider always
exists, so the undefined pass-through and the overload it forced on
the registry path are gone.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UUhsdoUsXmAhdW4sFxUdLL
…ntracts

Merge the REST, provider-chain, and registry sources with one first-wins
helper instead of two wrappers that each re-implemented the routing.
Move every ability-specific adjustment into a contract table so the
adapter no longer checks ability names, keep collision selection next to
the exposure policy, share one isRecord helper, and move the WebMCP setup
component out of the root component.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UUhsdoUsXmAhdW4sFxUdLL
The WebMCP draft defines readOnlyHint, untrustedContentHint, and
consequentialHint only. Stop emitting the MCP-style destructiveHint and
idempotentHint, and derive consequentialHint from the contract table,
meta.webmcp.consequential, or the ability's destructive annotation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UUhsdoUsXmAhdW4sFxUdLL
Simplify the WebMCP adapter after review feedback.

- Resolve the owner of an ability live on every call, as the chat
  provider chain does, instead of keeping a provider per registration.
  A tool call re-reads the current winner for its ability name and is
  rejected when that winner is gone, opted out, or has a different
  descriptor. A source change with an identical descriptor keeps the
  registration, so tools no longer flicker when the provider chain
  arrives after the registry.
- Keep the merge helper WebMCP-only under src/webmcp/ and leave the
  chat provider chain untouched.
- Drop the timed retries from the mount. A source that fails to load is
  reported and skipped, the other sources still register, and the
  uncached REST failure is fetched again on the next reconcile.
- Update WEBMCP.md, AGENTS.md, and the tests to match.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011tWfc3eeKKSXcPGPMxJeHc
…bilities

Document that the local REST provider mirrors the upstream
@wordpress/core-abilities loader, why that loader cannot replace it yet,
and the steps that would let us delete the local copy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011tWfc3eeKKSXcPGPMxJeHc
A registry ability can carry a schema that cannot be serialized, such as
a cyclic object. Building its fingerprint threw outside the per-tool try
block and aborted the whole reconcile, so the valid tools after it were
never registered.

- Build the descriptor and fingerprint through a helper that reports
  that one ability as a failure and skips it, removes its registration
  when the live descriptor stops being serializable, and lets the other
  tools register.
- Treat a descriptor that cannot be serialized as a changed tool at
  dispatch.
- Build the adapter test harness with the real merge helper over a
  single source, so the tests use the same seam as the mount.
- Document the name-based dispatch inside each owner as a known limit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011tWfc3eeKKSXcPGPMxJeHc
…t test

The assertion for wpcom/get-posts with a stored public: false read as if
the flag opted the ability in. Rename the test, add the control case of a
non-allowlisted ability with the same flag and annotations, and explain
why the stored default cannot be an opt-out.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011tWfc3eeKKSXcPGPMxJeHc
@gziolo
gziolo force-pushed the update/agents-manager-webmcp-registry-exposure branch from 1a211cd to bbcfc91 Compare October 28, 2026 11:37
@gziolo
gziolo requested a balanced review from Copilot October 28, 2026 12:32

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.

🟡 Changes recommended

Duplicate setup hooks can clear pending targets during active requests, while dispatch can execute tools that name-collision rules should exclude.

2 open issues
2 resolved since last review

Review effort: Balanced

@gziolo
gziolo force-pushed the update/agents-manager-webmcp-registry-exposure branch from d92f957 to 415ce66 Compare October 28, 2026 13:16
@gziolo
gziolo requested a balanced review from Copilot October 28, 2026 13:19

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.

🔵 Needs a closer look

Duplicate provider setup instances share module-level state, allowing inert actions to stop the shimmer, emit premature completion, and clear the pending block during an active transformation.

2 open issues

Review effort: Balanced

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.

🔵 Needs a closer look

Human assessment is needed because a moderate finding omitted from the published review shows that recovered REST tools can remain undiscoverable.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

gziolo and others added 2 commits October 28, 2026 15:03
A stale tool call starts a reconcile before it rejects. A failure of that
reconcile was dropped without a message. The adapter now takes the mount's
onSyncError, so every sync failure is reported in one place.

Also remove a WebMCP hook mock from the agent setup tests. Nothing asserted
it, and the suite passes without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

gziolo commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

WebMCP landed in the WordPress AI plugin: WordPress/ai#1081

Both approaches register tools with the browser through modelContext.registerTool(). The browser agent supplies the AI model and calls the tools.

  • The AI plugin adds an optional experiment with 14 dedicated editor tools, including block editing, undo, save, and publish. Its bridge collects built-in tools and tools added through a JavaScript registry, applies a filter, and registers up to 30 tools by default. Tool calls read or change the editor's data stores. Plugins can call refresh() to register additional tools.
  • This PR builds browser tools from existing abilities in Agents Manager, the client abilities registry, and the site's Abilities REST API. The bridge applies exposure rules and sends each call to the provider that owns the ability. It also updates or removes registrations when abilities change and checks for stale definitions before execution. Its editor tools leave changes unsaved for review.

The main difference is scope: the AI plugin focuses on the current page and leaves server abilities to MCP. This PR also exposes selected site capabilities, such as fetching patterns and uploading media, through the same browser interface.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants