Blog

Adding declarative WebMCP to Rails, Next.js and shops

How to add declarative WebMCP attributes to existing HTML forms in Rails, Next.js and online stores following Google's Modern Web Guidance rules.

Published · 4 min read

Google Antigravity’s modern-web-guidance@latest skill (GoogleChrome/modern-web-guidance) targets the HTML <form> elements web apps already ship for search, filtering, bookings and support tickets. Declarative WebMCP turns those forms into structured browser tools with HTML attributes, leaving browsers without WebMCP unaffected.

In our 25 November 2026 CrawlWise 0.4.35 scans, 0 of 55 scored global top-100 e-commerce homepages and 0 of 10 scored Polish top-20 online stores exposed any WebMCP tools. Adding a declarative search or lookup form takes a few lines in Rails, Next.js or a server-rendered storefront.

Rails (ERB with form_with)

In a Rails view, standard form_with helpers accept arbitrary HTML attributes directly, so your existing controller, CSRF token and server-side validation stay unchanged:

<%= form_with url: products_path, method: :get, local: true,
              toolname: "search-products",
              tooldescription: "Search the product catalog by keyword and category.",
              toolautosubmit: true do |form| %>
  <%= form.label :q, "Keyword" %>
  <%= form.search_field :q, required: true,
                        toolparamdescription: "Product name, brand or SKU, e.g. trail shoes" %>

  <%= form.label :category, "Category" %>
  <%= form.select :category, [["All", ""], ["Shoes", "shoes"], ["Jackets", "jackets"]] %>

  <%= form.submit "Search" %>
<% end %>

Google’s Modern Web Guidance advises against listing field names, types or <option> values inside tooldescription, because the browser builds the tool’s JSON Schema from the <input> and <select> controls automatically.

For radio groups (such as shipping speed or size ranges), put toolparamdescription on the enclosing <fieldset> so Chrome applies one description to the parameter group:

<fieldset toolparamdescription="Preferred delivery speed for the estimate.">
  <legend>Delivery</legend>
  <label><input type="radio" name="delivery" value="standard" checked> Standard</label>
  <label><input type="radio" name="delivery" value="express"> Express</label>
</fieldset>

React and Next.js: plain HTML forms vs use-webmcp-tool

For server-rendered Next.js forms that submit to a route or Server Action without custom state syncing, you can put toolname, tooldescription and toolparamdescription straight on the <form> and its inputs. Watch React’s TypeScript types for custom HTML attributes if you use strict JSX checking, and keep standard name and <label htmlFor> attributes intact.

When a React or Next.js view relies on client state, dynamic routes or multi-step flows, modern-web-guidance explicitly warns against calling document.modelContext.registerTool() inside components or writing your own useEffect lifecycle wrapper. Use the official use-webmcp-tool hook (useWebMCP), which handles feature detection, AbortSignal cleanup on unmount and conditional exposure via an enabled option. Vue apps have useWebMCP in @vueuse/core, and Angular Signal Forms use provideExperimentalWebMcpForms() (do not stack declarative toolname attributes on top of Angular Signal Forms, or the form registers twice).

Handling agent submissions without full-page navigation

When a browser agent submits a declarative form, the SubmitEvent carries event.agentInvoked and event.respondWith(promise). If your storefront enhances search with fetch, return structured results or clear validation messages straight to the agent:

form.addEventListener("submit", (event) => {
  if (!event.agentInvoked) return;
  event.preventDefault();
  const query = new URLSearchParams(new FormData(event.currentTarget));
  event.respondWith(
    fetch(`/api/products?${query}`).then((res) => res.json()),
  );
});

Browsers also expose two CSS pseudo-classes while an agent works on a form: form:tool-form-active highlights the active form, and button:tool-submit-active highlights the submit button when toolautosubmit is omitted and the browser pauses for human confirmation.

Where to leave toolautosubmit off

Use toolautosubmit only on read-only queries (catalog search, filters, stock checks, store locators) and reversible drafts. Leave it off checkout, payment, order placement, account deletion, password change and outbound contact or email forms. Without toolautosubmit, the agent fills the fields and the human clicks submit.

Validating your form before shipping

Every declarative WebMCP form needs to run over HTTPS (Secure Context), avoid duplicate toolname values on the same page, keep name on every enabled control, and provide a parameter description through toolparamdescription, <fieldset toolparamdescription>, <label> or aria-description.

Paste your URL into the free WebMCP checker to validate those rules in Chromium without executing your form, read the full WebMCP guide, or inspect how major retailers currently score in our global top 100 e-commerce study and Poland top 20 online stores scan.

Check your own site

Run a free 25-page preview of the whole-site audit. No account needed.

Start the audit

More from the blog

All posts

Last updated .