WebMCP Generator
Register your store's search, add-to-cart and contact forms as tools AI agents can call directly.
Your details
Your script (paste before </body>)
<script>
(function () {
if (!('modelContext' in document)) return; // WebMCP isn't supported in this browser yet; this script is a safe no-op until it is.
var controller = new AbortController();
if (document.querySelector("form[action*='/search'], form[role='search']")) {
document.modelContext.registerTool({
name: "search_products",
description: "Search this store's products by keyword and go to the results page",
inputSchema: { type: "object", properties: { query: { type: "string", description: "What to search for" } }, required: ["query"] },
async execute({ query }) {
var form = document.querySelector("form[action*='/search'], form[role='search']");
var input = form.querySelector("input[type=search], input[name='q'], input[type=text]");
if (!input) return { content: [{ type: "text", text: "No search field found on this page." }] };
input.value = query;
form.requestSubmit ? form.requestSubmit() : form.submit();
return { content: [{ type: "text", text: "Searching the store for \"" + query + "\"." }] };
},
}, { signal: controller.signal });
}
if (document.querySelector("form[action*='/cart/add'], form.cart, form[action*='add-to-cart']")) {
document.modelContext.registerTool({
name: "add_to_cart",
description: "Add the product on this page to the shopping cart",
inputSchema: { type: "object", properties: { quantity: { type: "number", description: "How many to add", default: 1 } } },
async execute(args) {
var form = document.querySelector("form[action*='/cart/add'], form.cart, form[action*='add-to-cart']");
var qtyField = form.querySelector("input[name='quantity']");
if (qtyField && args && args.quantity) qtyField.value = String(args.quantity);
form.requestSubmit ? form.requestSubmit() : form.submit();
return { content: [{ type: "text", text: "Submitted the add-to-cart form. Check the cart to confirm it was added." }] };
},
}, { signal: controller.signal });
}
})();
</script>WebMCP (document.modelContext) is an emerging browser proposal from Microsoft and Google, not yet supported in mainstream browsers. This script safely does nothing until support ships; test it in a browser build that implements the proposal.
Shopify: paste this before </body> in theme.liquid. WooCommerce/WordPress: add it to your footer, or through a snippet plugin like WPCode.
Live preview
What WebMCP does
WebMCP is a proposed browser API, led by Microsoft and Google through the W3C Web Machine Learning Community Group, that lets a web page register tools an AI agent browsing on the visitor's behalf can call directly, instead of guessing at buttons and forms. A page calls document.modelContext.registerTool() with a tool name, a description, an input schema and a function that runs the action.
This generator writes that script for your store, wiring up tools for the forms already on your page: search, add to cart, and a contact form, matched by CSS selector so it works without changing your theme's own markup.
- It's not yet supported in mainstream browsers. The script checks
'modelContext' in documentfirst and does nothing if that API isn't there, so it's safe to add now and it will start working as support ships. - Test it in a browser build that supports the proposal (see the WebMCP repository) before relying on it, and re-check the API shape periodically since it's still changing.
Adding it to your store
- 01
Shopify
Paste the script into
theme.liquidjust before</body>, or add it as a Custom Liquid section on the pages that need it. - 02
WooCommerce / WordPress
Add it to your theme's footer, or paste it into a header/footer field if your theme or a snippet plugin like WPCode provides one.
- 03
Check the selectors
The default selectors match Shopify's and common WooCommerce form markup. If a tool doesn't find its form, open your page's HTML and adjust the selector field to match your theme's actual form.
Questions people ask
Will this let an AI agent buy something without the shopper confirming?
It submits the same form your visitor would, so it follows whatever confirmation steps your store already has. It doesn't bypass payment or your cart.
Does the add-to-cart tool confirm the item was actually added?
It submits your cart form, which is reliable, but different themes respond differently (a redirect, a drawer, an AJAX update), so this generic script can't read every theme's confirmation. It reports that it submitted the form; the agent can check the cart page to be sure.
Is this the same as the Universal Commerce Protocol (UCP)?
No. WebMCP is a browser API for pages a visitor (and their agent) is already looking at. UCP is a server-side manifest agents can call directly, without a browser. They're built by different groups for different situations; a store can use either or both.
Do I need developer help to install this?
Pasting a script tag into your theme is usually enough, but if your theme's footer is locked down or you're unsure, get a developer to add it for you.
Related tools
Last reviewed 30 September 2026.
Sources: WebMCP proposal, Web Machine Learning Community Group
