Skip to content

feat(ui): WebMCP site search component - #3632

Merged
ascorbic merged 1 commit into
emdash-cms:mainfrom
swissky:feat/webmcp-site-search
Sep 29, 2026
Merged

ascorbic merged 1 commit into
emdash-cms:mainfrom
swissky:feat/webmcp-site-search

Conversation

@swissky

@swissky swissky commented Sep 29, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Adds an opt-in WebMcpSearch component, 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 deprecated navigator.modelContext), the component registers a search_site tool with readOnlyHint and untrustedContentHint:

  • It calls the existing public GET /_emdash/api/search, so it returns only published content from collections with search enabled.
  • Results are title, absolute URL (built with the same buildLiveSearchResultUrl and routeMap as LiveSearch), collection, and a plain-text excerpt (the <mark> highlights and HTML escaping are removed).
  • Props match LiveSearch: collections, locale (defaults to Astro.currentLocale, null for all), limit (default 10, clamped to the API's 1–100), routeMap.
  • Network errors, non-OK responses, and an empty query come back as tool errors rather than throwing. A rejected registration (for example a duplicate name) is logged, not left unhandled.
  • The registration is tied to an AbortController and 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

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...
  • I have included screenshots below if this PR changes the UI

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

  • This PR includes AI-generated code — model/tool: Cursor + Claude Opus 5.5

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, document over navigator detection, 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 as search_site, execute({ query: "static" }) returned [{ title: "The Case for Static", url: "http://localhost:4410/posts/the-case-for-static", … }] using the configured routeMap, and removing the element aborted the registration.

@changeset-bot

changeset-bot Bot commented Sep 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cb8e4d4

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

This PR includes changesets to release 12 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
create-emdash Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds 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

@emdashbot emdashbot 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.

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.

@emdashbot emdashbot Bot added the review/approved Approved; no new commits since label Sep 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@3632

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@3632

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@3632

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@3632

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@3632

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@3632

emdash

npm i https://pkg.pr.new/emdash@3632

create-emdash

npm i https://pkg.pr.new/create-emdash@3632

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@3632

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@3632

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@3632

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@3632

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@3632

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@3632

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@3632

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@3632

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@3632

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@3632

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@3632

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@3632

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@3632

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@3632

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@3632

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@3632

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@3632

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@3632

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@3632

commit: cb8e4d4

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, nice. I was wanting to add this

@ascorbic
ascorbic merged commit 728790b into emdash-cms:main Sep 29, 2026
46 checks passed
@emdashbot emdashbot Bot mentioned this pull request Sep 29, 2026
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.

2 participants