Repository navigation
feat(ui): WebMCP site search component - #3632
Conversation
🦋 Changeset detectedLatest commit: cb8e4d4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 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 |
There was a problem hiding this comment.
This PR adds an opt-in WebMcpSearch component that exposes the existing public search API as a read-only WebMCP search_site tool for in-browser AI agents. The approach is sound and stays consistent with LiveSearch: it reuses buildLiveSearchResultUrl, the same routeMap, collections/locale/limit props defaulting to Astro.currentLocale, and the public GET /_emdash/api/search endpoint. It introduces no new server-side queries on page renders, forces anonymous searches to published content via the existing route, clamps limit to the API's 1–100 range, and cleans up the tool registration on element disconnect via AbortController.
I reviewed the changed Astro component, the tool-registration module, the unit tests, the search API route/schema, the changeset, and the docs addition. The implementation correctly escapes the query via URLSearchParams, decodes the sanitized snippet back to plain text, and returns API/network failures as tool errors rather than throwing. The tests cover request scope, limit clamping, URL generation, excerpt decoding, empty-query/HTTP/network errors, document/navigator detection, abort cleanup, and both sync and async registration failures. The changeset and docs accurately describe the user-facing capability.
No blocking issues, regressions, or AGENTS.md violations found.
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
ascorbic
left a comment
There was a problem hiding this comment.
Ah, nice. I was wanting to add this
What does this PR do?
Adds an opt-in
WebMcpSearchcomponent,emdash/ui/webmcp-search, that lets AI agents running in a visitor's browser search the site through WebMCP instead of scraping pages. Related to the agent-readiness thread in Discussion #1008.In browsers that expose
document.modelContext(falling back to the deprecatednavigator.modelContext), the component registers asearch_sitetool withreadOnlyHintanduntrustedContentHint:GET /_emdash/api/search, so it returns only published content from collections with search enabled.buildLiveSearchResultUrlandrouteMapasLiveSearch), collection, and a plain-text excerpt (the<mark>highlights and HTML escaping are removed).LiveSearch:collections,locale(defaults toAstro.currentLocale,nullfor all),limit(default 10, clamped to the API's 1–100),routeMap.AbortControllerand removed when the element disconnects, so view transitions don't leave stale tools behind.It adds nothing to page renders: the component emits a hidden custom element and a script, and the search API runs only when an agent calls the tool. In browsers without WebMCP it does nothing.
Docs: a new section in the AI tools guide, distinguishing it from the site's admin MCP server.
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.No admin UI or strings; the component renders nothing visible. No Discussion: opened directly as a maintainer-side improvement, related to Discussion #1008.
AI-generated code disclosure
Screenshots / test output
Not applicable (no visible UI).
packages/core/tests/unit/components/webmcp-search.test.ts(8 tests) covers the request scope and limit clamping, absolute URLs and excerpt decoding, tool errors for empty queries, HTTP failures and network failures,documentovernavigatordetection, unregistering on abort, and sync and async registration failures.Verified in a browser on the simple demo with a stand-in
document.modelContext: the tool registered assearch_site,execute({ query: "static" })returned[{ title: "The Case for Static", url: "http://localhost:4410/posts/the-case-for-static", … }]using the configuredrouteMap, and removing the element aborted the registration.