Skip to main content
In this tutorial, we will create a plain HTML page that registers one WebMCP tool and then verify that the tool works by calling it from the browser console. By the end, you will have a working page with a tool that browser-side WebMCP consumers can discover and call. Desktop agents need a bridge such as the local relay.

Prerequisites

  • A text editor
  • A modern web browser (Chrome, Edge, Firefox, or Safari)
  • A local static server, such as Python’s built-in HTTP server
No build step or framework is required. Serve the page from localhost because WebMCP rejects tool execution from opaque file: origins.

What we will build

A single HTML page that:
  1. Loads the tool-only @mcp-b/webmcp-polyfill runtime via a script tag
  2. Registers a tool called get-page-title
  3. Displays confirmation in the page when the tool is ready
1

Create the HTML file

Create a new file called index.html and paste in this starting point:
index.html
The <script> tag in the <head> loads @mcp-b/webmcp-polyfill, which installs its WebMCP-compatible tool surface on document.modelContext. No import statements or bundler needed.
2

Register a tool

Replace the empty <script> block at the bottom of the page with:
index.html
This registers a single tool on document.modelContext. The tool returns the current page title. The execute function is what runs when a consumer calls the tool.
3

Serve the page on localhost

From the directory containing index.html, start a static server:
Terminal
Open http://localhost:8000 in your browser. You should see:
Expected page
If the status still says “Loading…”, open the browser console (F12) and check for errors.
4

Verify the tool from the console

Open the browser console (F12, then click the Console tab). Type the following:
Browser console
You should see an array containing your tool:
Browser console
Now call the tool:
Browser console
The output should be an object containing your tool’s response:
Tool result
You have registered a WebMCP tool, discovered it through getTools(), and executed it through the polyfill’s serialized-JSON compatibility method.
5

Try changing the tool

Back in your editor, change the tool so it returns a fixed message instead of document.title:
Tool implementation
Refresh the browser and run the executeTool call again from the console. Notice the text field in the response now says "Tool is working" instead of the page title.

The complete page

Here is the full index.html for reference:
index.html

What you learned

  • @mcp-b/webmcp-polyfill installs its WebMCP-compatible tool surface when loaded via a script tag
  • registerTool() returns a promise that resolves after registering a tool with a name, description, input schema, and execute function
  • document.modelContext.getTools() discovers registered tools; this polyfill executes them through its feature-detected, serialized-JSON executeTool() signature
  • A WebMCP callback can return any serializable value; this example returns an MCP-shaped content array

Next steps