Build a WebMCP tool for a web page
Expose a book search to a browser agent and see how page tools fit alongside MCP servers and MCP Apps.
- Choose between a WebMCP page tool, an MCP server, and an MCP App
- Inspect a tool definition and test matching, invalid, and empty searches
- Explain how a page can expose a tool while preserving its manual form
Imagine the MCP server’s book catalog also has a website. A visitor wants an assistant to find books by an author and leave the results on the page. WebMCP lets the page expose a named tool with structured inputs. A compatible browser agent can call that tool, and the page runs its own search logic.
You can start here with basic HTML forms and JavaScript events. The interactive lab below is a simulation. WebMCP itself is a Community Group draft, and native support depends on the browser and its configuration.
WebMCP exposes tools in a compatible browser while the page is open. MCP servers expose capabilities to MCP clients over transports such as stdio or Streamable HTTP, independently of that page. MCP Apps let compatible hosts render an interface supplied by a server inside the agent’s conversation.
A page and an MCP server can use the same search logic. WebMCP registers the tool through a browser API. An MCP client exchanges JSON-RPC messages with the server. Chrome’s comparison · MCP Apps overview
Try it
Up to 15 XPChoose the integration
Match each goal to the interface that fits.
“An assistant shows an interactive reading list inside its conversation.”
“A browser assistant searches the open catalog and updates the results beside you.”
“An MCP client searches the catalog when nobody has the website open.”
Try it
Up to 15 XPTry three book searches
Inspect the definition of search_books. Edit the JSON or pick an example, then run the call. Try a matching query, a blank or invalid query, and a valid query with no matches. Compare the visible results with what the simulated agent receives.
Inspect tool definition search_books
{
"name": "search_books",
"description": "Find books in the sample catalog by title or author.",
"inputSchema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"minLength": 1,
"maxLength": 120
}
},
"required": [
"query"
],
"additionalProperties": false
}
}0 of 3 outcomes explored
Visible page results
Run a search to see results.
Structured tool result
Run a search to see results.
Try a native WebMCP tool
Open the standalone book search demo. Its search form works manually. In a browser with WebMCP enabled, open DevTools → Application → WebMCP, select search_books, and run it with {"query":"Austen"}. Check that both the tool result and the page show the same books. Follow the Chrome setup guide and DevTools guide if the panel is unavailable.
The demo shares the search handler between manual search and tool calls. When WebMCP is available, it registers that handler with the imperative JavaScript API.
1if (typeof document.modelContext?.registerTool === 'function') {
2 await document.modelContext.registerTool({
3 name: 'search_books',
4 description: 'Find books by title or author.',
5 inputSchema: bookSearchSchema,
6 execute: async (args) => runSearch(args),
7 });
8}The declarative API marks up a standard form. The browser derives tool inputs from its fields. In this example the agent can fill the search term and the user chooses when to submit. Connect the form’s submit event to your existing search handler. The example is an alternative to the demo’s JavaScript registration. Declarative API guide
1<form toolname="search_books" tooldescription="Find books by title or author.">
2 <label for="query">Title or author</label>
3 <input id="query" name="query" type="search" maxlength="120" required>
4 <button type="submit">Search</button>
5</form>Key takeaways
A WebMCP tool is registered by a page in a compatible browser.
An invalid search and a successful search with zero results need different feedback.
A manual form and a browser tool can share one validated search handler.
Lesson quiz
4 questions · pass with 3 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…