Prerequisites
- A text editor
- A modern web browser (Chrome, Edge, Firefox, or Safari)
What we will build
A single HTML page that:- Loads the strict
@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
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 the strict WebMCP surface on navigator.modelContext. No import statements or bundler needed.Register a tool
Replace the empty This registers a single tool on
<script> block at the bottom of the page with:index.html
navigator.modelContext. The tool returns the current page title. The execute function is what runs when an AI agent, or you through the testing API, calls the tool.Open the page in your browser
Open If the status still says “Loading…”, open the browser console (F12) and check for errors.
index.html directly in your browser (double-click the file, or drag it into a browser window). You should see: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 and executed it through the testing API.
The complete page
Here is the fullindex.html for reference:
index.html
What you learned
@mcp-b/webmcp-polyfillinstalls the strict WebMCP surface when loaded via a script tagregisterTool()registers a single tool with a name, description, input schema, and execute functionnavigator.modelContextTestingprovideslistTools()andexecuteTool()for verifying tools from the console- Tools return a
contentarray with{ type: "text", text: "..." }objects
Next steps
- Build Your First React Tool to register tools from React components
- Choose a Runtime to see when to move from the strict core to the full MCP-B runtime
- Try the Native Chrome Preview to use the browser’s built-in WebMCP API
- Connect a Desktop Agent to let Claude or Cursor call your tools
