WebMCP for WordPress: Make Your Site AI-Agent Ready
WordPress runs 43% of the web. If you operate a WordPress site and you've been hearing about WebMCP, you're probably wondering how this applies to you. After all, most WebMCP tutorials assume you're building a React or Next.js app from scratch.
But here's what makes WebMCP interesting for WordPress users specifically: you don't need to be a JavaScript developer to get started. The declarative HTML approach lets you make your forms and content agent-discoverable by adding a few attributes to your existing markup. No build tools or npm packages, and no framework rewrites.
WebMCP is the W3C browser API (navigator.modelContext) that lets AI agents discover and use structured tools on any website. For WordPress, this means an AI assistant visiting your site can find your contact form, search your products, or browse your content programmatically instead of guessing where buttons are.
This guide walks you through three approaches, ordered by complexity: the no-code declarative method, the low-code snippet approach, and a full custom plugin build. Pick the one that matches your comfort level and move on.
The no-code approach: declarative HTML attributes
How it works with WordPress form plugins
The fastest path to WebMCP on WordPress uses the declarative API. Instead of writing JavaScript to register tools, you add HTML attributes directly to your form elements. The browser reads those attributes and automatically registers them as tools that AI agents can discover.
This works with every major WordPress form plugin because it operates at the HTML level. Contact Form 7, WPForms, Gravity Forms, Ninja Forms: they all output standard HTML form elements. You just need to add the right attributes.
The key attributes are toolname and tooldescription. Add these to any element, and it becomes a WebMCP tool. The form's input fields become the tool's parameters. When an AI agent calls the tool, the form gets submitted with the values the agent provides.
So a contact form that normally waits for a human to fill it out? Now it's a structured tool an AI agent can use to send a message on behalf of its user.
Step by step: making a contact form agent-discoverable
Let me walk you through a real example. Say you have a Contact Form 7 form on your WordPress site. Here's what the process looks like.
First, identify the form's HTML output. Visit the page with your form, right-click it, and choose "Inspect." You'll see something like wrapping your input fields.
Second, add the WebMCP attributes. In your WordPress editor, switch to the HTML block or use the Custom HTML block to wrap or modify the form. You need two attributes on the form tag:
<form toolname="contact-us"
tooldescription="Send a message to our team. Include your name, email, and message."
class="wpcf7-form">
<!-- existing form fields stay the same -->
</form>
Each input field's name attribute becomes a parameter in the tool's schema. If your form has name="your-name" and name="your-email" and name="your-message", those become the parameters an AI agent sees.
Third, test it. Open Chrome Canary with the navigator.modelContext flag enabled, navigate to your page, and check the console. You should see your form registered as a discoverable tool. Any AI agent operating in that browser can now find and call it.
That's it. No JavaScript. No plugin installations beyond what you already have. Just two HTML attributes on your existing form.
Where declarative attributes work best in WordPress
The declarative approach is perfect for forms that already exist on your site. Think about what forms you currently have:
A search form in your header or sidebar. Add toolname="site-search" and tooldescription="Search articles and pages on this website" to make it agent-callable. Now an AI can search your site's content programmatically instead of scraping your pages.
A newsletter signup form. Add toolname="subscribe" and tooldescription="Subscribe to our email newsletter with your email address". An AI assistant helping a user manage their subscriptions could handle this directly.
A WooCommerce product filter. If your shop has a filter form for categories, price ranges, or attributes, those become structured tools. An AI shopping assistant could filter your products the same way a human would, but through clean API calls instead of clicking around.
The beauty of this approach is speed. You can make five forms agent-discoverable in under an hour, and you haven't written a single line of JavaScript.
The low-code approach: snippet plugins
Loading the WebMCP polyfill
The declarative API handles forms beautifully. But what if you want to register tools that aren't tied to a form? That's where the low-code approach comes in.
You'll use a code snippets plugin like WPCode or the Code Snippets plugin to inject small pieces of JavaScript into your site. No custom plugin development needed.
Start by loading the WebMCP polyfill. This is a lightweight script (around 5KB) that adds navigator.modelContext support to browsers that don't have it natively yet. Add this snippet through your code snippets plugin and set it to load in the footer:
<script src="https://cdn.jsdelivr.net/npm/@anthropic-ai/webmcp-polyfill@latest/dist/polyfill.min.js"></script>
Set it to run on all pages, or get selective. If you only need WebMCP on your shop pages, configure the snippet to load conditionally. WPCode lets you set page-level rules, and Code Snippets has similar conditional logic.
One thing I'd recommend: load it in wp_footer rather than wp_head. The polyfill needs the DOM to be ready, and footer loading also means it won't block your initial page render.
WordPress-specific tools worth registering
Once the polyfill is loaded, you can register custom tools using JavaScript. Here are the tools that make the most sense for a typical WordPress site.
Site search is the highest-value tool for content-heavy sites. WordPress has a built-in REST API for search, so your tool handler can call it directly:
navigator.modelContext.registerTool({
name: "search-articles",
description: "Search all published articles and pages on this site by keyword",
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "Search term" }
},
required: ["query"]
},
execute: async ({ query }) => {
const response = await fetch(`/wp-json/wp/v2/search?search=${encodeURIComponent(query)}&per_page=5`);
const results = await response.json();
return results.map(r => ({ title: r.title, url: r.url, type: r.subtype }));
}
});
Post content retrieval is another strong candidate. An AI agent browsing your site might want to read a specific article without parsing the full HTML page:
navigator.modelContext.registerTool({
name: "get-post",
description: "Get the full content of a specific article by its ID or slug",
inputSchema: {
type: "object",
properties: {
slug: { type: "string", description: "The URL slug of the post" }
},
required: ["slug"]
},
execute: async ({ slug }) => {
const response = await fetch(`/wp-json/wp/v2/posts?slug=${encodeURIComponent(slug)}`);
const posts = await response.json();
if (posts.length === 0) return { error: "Post not found" };
return { title: posts[0].title.rendered, content: posts[0].content.rendered, date: posts[0].date };
}
});
For WooCommerce sites, product search is the obvious winner. Expose your product catalog as a searchable tool and AI shopping agents can help users find what they need:
navigator.modelContext.registerTool({
name: "search-products",
description: "Search products by keyword, returns names, prices, and links",
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "Product search term" },
category: { type: "string", description: "Product category filter (optional)" }
},
required: ["query"]
},
execute: async ({ query, category }) => {
let url = `/wp-json/wc/v3/products?search=${encodeURIComponent(query)}&per_page=5`;
if (category) url += `&category=${encodeURIComponent(category)}`;
const response = await fetch(url);
const products = await response.json();
return products.map(p => ({ name: p.name, price: p.price, url: p.permalink }));
}
});
Add each of these as a separate snippet in your code snippets plugin. Test them individually. Once they work, you've turned your WordPress site into a structured toolbox that AI agents can interact with.
Building a custom WebMCP WordPress plugin
Plugin architecture
If you're managing multiple WordPress sites or want a reusable solution, building a lightweight plugin makes sense. The architecture is simple: enqueue the polyfill, read configuration from the admin, and register tools on the front end.
Start with the standard WordPress plugin header and a class to hold everything together. Your plugin needs three pieces: a settings page where site owners configure which tools to enable, a script that loads the polyfill and tool registrations on the front end, and proper enqueueing using WordPress hooks.
The enqueueing part matters more than you'd think. WordPress has a specific way to load scripts, and ignoring it causes conflicts with caching plugins, minification tools, and other performance optimizations. Use wp_enqueue_script with the polyfill as a dependency for your tool registration script:
function webmcp_enqueue_scripts() {
wp_enqueue_script(
'webmcp-polyfill',
'https://cdn.jsdelivr.net/npm/@anthropic-ai/webmcp-polyfill@latest/dist/polyfill.min.js',
array(),
null,
true
);
wp_enqueue_script(
'webmcp-tools',
plugin_dir_url(__FILE__) . 'js/tools.js',
array('webmcp-polyfill'),
'1.0.0',
true
);
wp_localize_script('webmcp-tools', 'webmcpConfig', array(
'restUrl' => rest_url(),
'nonce' => wp_create_nonce('wp_rest'),
'enabledTools' => get_option('webmcp_enabled_tools', array('search', 'posts'))
));
}
add_action('wp_enqueue_scripts', 'webmcp_enqueue_scripts');
The wp_localize_script call passes your PHP configuration to JavaScript. Your front-end script reads webmcpConfig.enabledTools to decide which tools to register, and uses webmcpConfig.restUrl and webmcpConfig.nonce to make authenticated API calls.
WooCommerce integration
For WooCommerce sites, the plugin approach really shines because you can expose the full shopping experience as structured tools.
Product catalog search is the foundation. But the real power comes from cart operations. Imagine an AI shopping assistant that can add items to a user's cart, check the current cart total, and walk them through checkout. Each of those becomes a separate WebMCP tool.
Here's what the cart tool looks like conceptually. Your plugin registers an add-to-cart tool that takes a product ID and quantity, calls the WooCommerce cart API, and returns the updated cart state. The AI agent doesn't need to find the "Add to Cart" button or figure out your page layout. It calls a structured function and gets a structured response.
Order tracking is another strong use case. A returning customer asks their AI assistant, "Where's my package?" The agent visits your site, finds the track-order tool, passes the order number, and gets back shipping status, tracking number, and estimated delivery date. All through a single structured call.
The key with WooCommerce integration is deciding what to expose. Product browsing and search are safe to offer to any visitor. Cart operations require session awareness. Order tracking needs authentication. Your plugin's settings page should let the site owner toggle each tool independently and set access requirements.
Performance and security considerations
Keeping your WordPress site fast
The polyfill adds roughly 5KB to your page weight. That's negligible compared to the average WordPress page, which loads several hundred KB of CSS and JavaScript from themes and plugins alone.
But loading matters. Conditional loading is the smart approach. If you only have WebMCP tools on your shop pages, only load the polyfill there. The snippet plugin approach gives you this control natively. With a custom plugin, check the current page template or post type before enqueueing:
function webmcp_conditional_load() {
if (is_shop() || is_product() || is_page('contact')) {
webmcp_enqueue_scripts();
}
}
add_action('wp_enqueue_scripts', 'webmcp_conditional_load');
Caching is the other consideration. WordPress caching plugins like WP Super Cache or W3 Total Cache will cache your pages with the WebMCP scripts included. That's fine and expected. The tools register fresh on each page load in the browser, so cached HTML doesn't cause issues.
Securing your tools
Every tool you register is callable by any AI agent that visits your page. For public-facing tools like search and content retrieval, that's the point. But for anything that modifies data, you need guardrails.
Use WordPress nonces for any tool that writes data. The wp_localize_script pattern shown earlier passes a nonce to your JavaScript, and your tool's execute function includes it in API requests. This prevents cross-site request forgery from rogue agents.
Rate limiting is worth considering for tools that hit your database. A simple counter in session storage or a server-side check prevents an agent from calling your product search 500 times in a minute. WordPress plugins like Wordfence already handle rate limiting at the server level, so this might already be covered for you.
Never expose admin actions as WebMCP tools. User deletion, post editing, plugin management: those stay behind the WordPress admin dashboard where they belong. WebMCP tools should be limited to read operations and controlled write operations like form submissions.
What this means for your WordPress site
You don't need to wait for an official WordPress plugin to land in the plugin directory. The three approaches above work today with tools that already exist.
If you're running a content site, the declarative form attributes and a site search tool cover 90% of what AI agents would want to do on your pages. If you're running a WooCommerce store, the snippet approach or a custom plugin turns your product catalog into a structured API that shopping agents can interact with.
The WordPress sites that add these tools first will have an advantage when AI agents become a meaningful traffic source. And based on how fast browser AI features are shipping in Chrome and Edge, that timeline is shorter than most WordPress site owners expect.
Start with the declarative approach today. Add toolname and tooldescription to your contact form. See how it works. Then decide if the snippet or plugin approach makes sense for your site.
Frequently asked questions
Is there an official WebMCP plugin for WordPress?
Not yet as of early 2026. The W3C specification is still being finalized, so official plugins are likely to follow browser adoption. The declarative API and snippet approaches described in this guide work today and will be forward-compatible with any future plugins.
Will WebMCP slow down my WordPress site?
The polyfill is roughly 5KB, which is negligible compared to the average WordPress page load. Use conditional loading to only include it on pages where you've registered tools. If your site uses a caching plugin, the polyfill will be cached alongside your other static assets with zero additional performance impact.
Can WooCommerce products become WebMCP tools?
Yes. You can expose product search, category filtering, and cart operations as structured WebMCP tools using the imperative JavaScript API. The product data comes from WooCommerce's built-in REST API endpoints, so you're not duplicating anything. An AI shopping agent can search your catalog, compare products, and add items to a cart through clean function calls.
Do I need to modify my WordPress theme?
For the declarative approach, you only need to add HTML attributes to your existing forms. No theme changes required. For the snippet and plugin approaches, scripts are loaded through WordPress hooks (wp_enqueue_scripts), which also doesn't require theme modifications. Your theme stays untouched in all three approaches.
How do I test WebMCP tools on my WordPress site?
Download Chrome Canary and enable the navigator.modelContext flag in chrome://flags. Navigate to your WordPress site and open the browser console. Type navigator.modelContext.tools() to see all registered tools. You can also call individual tools directly from the console to verify they return the expected data.