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
localhost because
WebMCP rejects tool execution from opaque file: origins.
What we will build
A single HTML page that:- Loads the tool-only
@mcp-b/webmcp-polyfillruntime via a script tag - Registers a tool called
get-page-title - Displays confirmation in the page when the tool is ready
1
Create the HTML file
Create a new file called The
index.html and paste in this starting point:index.html
<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 This registers a single tool on
<script> block at the bottom of the page with:index.html
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 Open If the status still says “Loading…”, open the browser console (F12) and check for errors.
index.html, start a static server:Terminal
http://localhost:8000 in your browser. You should see:Expected page
4
Verify the tool from the console
Open the browser console (F12, then click the Console tab). Type the following:You should see an array containing your tool:Now call the tool:The output should be an object containing your tool’s response:You have registered a WebMCP tool, discovered it through
Browser console
Browser console
Browser console
Tool result
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 Refresh the browser and run the
document.title:Tool implementation
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 fullindex.html for reference:
index.html
What you learned
@mcp-b/webmcp-polyfillinstalls its WebMCP-compatible tool surface when loaded via a script tagregisterTool()returns a promise that resolves after registering a tool with a name, description, input schema, and execute functiondocument.modelContext.getTools()discovers registered tools; this polyfill executes them through its feature-detected, serialized-JSONexecuteTool()signature- A WebMCP callback can return any serializable value; this example returns an MCP-shaped
contentarray
Next steps
- Build Your First React Tool to register tools from React components
- Choose a Runtime to compare the tool-only and full MCP-B runtimes
- WebMCP resources and status for current native browser guidance
- Connect a Desktop Agent to let Claude or Cursor call your tools
