https://dondibogusky.com/notes/webmcp-site-search/Back to notes
~1 min read

Making Site Search Available to WebMCP

WebMCP turns the site's static Pagefind index into a discoverable search tool that agents can call without changing the site's static-first architecture.

WebMCP is a good fit for this site because the best tool for exposing it was already here: the static Pagefind index generated from the production build.

The work focused less on adding a new search system and more on making the existing one legible to agents. Every page registers a read-only site-search tool through document.modelContext, the homepage and search forms carry declarative tool attributes, and three discovery manifests under /.well-known/ are generated from the same definition so they cannot drift.

Search Stays Static

The tool loads the same Pagefind runtime that powers the visible search page. For a query, it returns titles, canonical URLs, plain-text excerpts, and the total match count as one structured object instead of redirecting an agent to a page flow meant for a person.

This keeps the architecture honest. Search is still built from the final HTML, deployed as static assets, and available without a hosted search service.

Two Tools, Two Jobs

The imperative tool and the declarative form deliberately have different names because they do different things. site-search returns data to the agent and never changes the page. show-search-results is the search form itself: an agent fills it in, the browser submits it, and the person sees the results page. On the search page the form also answers the agent through respondWith(), using the same runtime, so both surfaces return identical results in identical order.

A Better Agent Boundary

Input is validated strictly in code with messages an agent can act on, while the published schema stays loose. The tool registers only once the document is active, so prerendered pages do not advertise tools for a page nobody is looking at yet. Browsers that shipped the earlier navigator.modelContext preview still work through a short-lived fallback.

The surrounding cleanup matters too: Pagefind ignores hidden microformat metadata that should not pollute excerpts, and the content security policy allows the small inline registration script without opening the site up broadly.