How to Add WebMCP to a Local Business Website (Free JavaScript Template)

illustration of local business store web page layout and neon digital lines

Local search is shifting from ten blue links to AI-powered answer engines and autonomous browser agents. While traditional Local SEO relies on Google Business Profile signals and schema.org structured data, WebMCP (Web Model Context Protocol) takes the next logical step: allowing your website to expose direct, executable tools to AI agents.

What is Local Business WebMCP?

Local Business WebMCP (Web Model Context Protocol) is the practice of exposing structured, client-side JavaScript tools such as verified contact details, physical address, trading hours, and direct inquiry handlers via navigator.modelContext so AI browser agents and answer engines can retrieve accurate business facts and submit customer requests without scraping static HTML.

Instead of forcing an AI assistant to scrape messy HTML contact pages or guess your current trading hours from third-party directories, WebMCP lets your site hand over verified answers and accept customer inquiries directly in the browser.

Structured data tells AI agents what your local business is. WebMCP gives AI agents verified tools to interact with your business accurately.

Why Local Businesses Need WebMCP Alongside SEO and AEO

Answer Engine Optimization (AEO) focuses on making your business facts unambiguous so AI platforms recommend you accurately. However, static HTML pages create friction for browser-based AI agents trying to complete tasks for a customer:

  • Eliminates Contact Hallucinations: Obfuscated email links and outdated footer text often lead AI assistants to quote old phone numbers or wrong email addresses. A dedicated WebMCP tool returns your exact verified contact details every time.
  • Protects Service Area Accuracy: Local trades, clinics, and service providers frequently receive out-of-area inquiries. Exposing an explicit list of suburbs or cities inside your WebMCP response qualifies leads before they reach your inbox.
  • Enables Direct Lead Capture: Rather than breaking on complex JavaScript form plugins or CAPTCHAs, an AI agent can call a clean WebMCP inquiry tool to pass a customer’s name, email, and message straight to your endpoint.
  • Zero Performance Overhead: A properly written WebMCP script uses vanilla JavaScript with zero external libraries, keeping Core Web Vitals and page load speeds fast.

How the Local Business WebMCP Template Works

Using the browser’s native navigator.modelContext interface, a lightweight JavaScript file can register three core tools for any local business website across any Content Management System (WordPress, Shopify, Wix, Squarespace, Webflow, or static HTML):

  • get_contact_details — Returns your official email address, phone number, and active service areas.
  • get_location_and_hours — Provides your physical street address and weekly operating hours.
  • send_contact_inquiry — Accepts a customer’s name, email, and message, then posts the payload to your form handler with an automatic email and phone fallback when no endpoint is configured.

Because the script begins with a capability check (if (!('modelContext' in navigator)) return;), standard web browsers ignore it completely without throwing console errors, while WebMCP-enabled browsers and AI agents immediately detect and register the tools.

Step-by-Step: Adding WebMCP to Your Local Business Website

You do not need a heavy plugin to deploy WebMCP. Follow these four steps to add the CMS-agnostic starter template to your website.

Step 1: Download and Edit the JavaScript Template

Save the code below as localbusiness_webmcp_template.js (or download the localbusiness webmcp template (.ZIP)) and update the values inside the BUSINESS_CONFIG block with your actual business details:

/**
 * File: localbusiness_webmcp_template.js
 * Description: Lightweight, CMS-agnostic WebMCP template for Local Businesses.
 * Works on any HTTPS website (WordPress, Shopify, Wix, Squarespace, Webflow, or static HTML).
 */
(function initLocalBusinessWebMCP() {
  if (!('modelContext' in navigator)) {
    return;
  }
  if (window.__localBusinessWebMCPInitialized) {
    return;
  }
  window.__localBusinessWebMCPInitialized = true;
  const BUSINESS_CONFIG = {
    name: "Acme Local Plumbing & Heating",
    email: "[email protected]",
    phone: "+1 555-019-2834",
    address: {
      street: "123 High Street",
      city: "Springfield",
      state: "VIC",
      postcode: "3000",
      country: "Australia"
    },
    serviceAreas: ["Springfield", "Northside", "West End", "Oak Park"],
    hours: {
      monday_friday: "08:00 - 17:30",
      saturday: "09:00 - 13:00",
      sunday: "Closed"
    },
    // Optional: Add any JSON POST form handler URL (e.g., Formspree, webhook, or custom API).
    // Leave blank ("") to automatically return your direct email and phone number instead.
    contactEndpoint: ""
  };
  navigator.modelContext.registerTool({
    name: "get_contact_details",
    description: `Returns the verified email address, phone number, and service areas for ${BUSINESS_CONFIG.name}.`,
    inputSchema: {
      type: "object",
      properties: {
        inquiryType: {
          type: "string",
          description: "Optional category of the inquiry (e.g., quote, emergency, booking, general)."
        }
      }
    },
    execute: async (args) => {
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              business: BUSINESS_CONFIG.name,
              email: BUSINESS_CONFIG.email,
              phone: BUSINESS_CONFIG.phone,
              serviceAreas: BUSINESS_CONFIG.serviceAreas,
              topic: args?.inquiryType || "general"
            })
          }
        ]
      };
    }
  });
  navigator.modelContext.registerTool({
    name: "get_location_and_hours",
    description: `Returns the street address and current opening hours for ${BUSINESS_CONFIG.name}.`,
    inputSchema: {
      type: "object",
      properties: {}
    },
    execute: async () => {
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              business: BUSINESS_CONFIG.name,
              address: BUSINESS_CONFIG.address,
              hours: BUSINESS_CONFIG.hours
            })
          }
        ]
      };
    }
  });
  navigator.modelContext.registerTool({
    name: "send_contact_inquiry",
    description: `Submits a direct customer message or quote request to ${BUSINESS_CONFIG.name}.`,
    inputSchema: {
      type: "object",
      properties: {
        customerName: {
          type: "string",
          description: "Full name of the customer."
        },
        customerEmail: {
          type: "string",
          description: "Email address where the business should reply."
        },
        message: {
          type: "string",
          description: "Details of the customer's question, service request, or quote."
        }
      },
      required: ["customerName", "customerEmail", "message"]
    },
    execute: async (args) => {
      if (!args?.customerEmail || !args.customerEmail.includes("@")) {
        return {
          isError: true,
          content: [{ type: "text", text: "Invalid or missing customerEmail address." }]
        };
      }

      if (!BUSINESS_CONFIG.contactEndpoint) {
        return {
          content: [
            {
              type: "text",
              text: `Direct form submission is not enabled. Please email ${BUSINESS_CONFIG.email} or call ${BUSINESS_CONFIG.phone} with your inquiry.`
            }
          ]
        };
      }
      try {
        const response = await fetch(BUSINESS_CONFIG.contactEndpoint, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Accept": "application/json"
          },
          body: JSON.stringify({
            name: args.customerName,
            email: args.customerEmail,
            message: args.message,
            source: "WebMCP_Agent"
          })
        });

        if (!response.ok) {
          throw new Error(`HTTP ${response.status}`);
        }
        return {
          content: [
            {
              type: "text",
              text: `Confirmation: Your inquiry has been sent to ${BUSINESS_CONFIG.name}.`
            }
          ]
        };
      } catch (error) {
        return {
          isError: true,
          content: [
            {
              type: "text",
              text: `Form submission failed (${error.message}). Please email ${BUSINESS_CONFIG.email} or call ${BUSINESS_CONFIG.phone} directly.`
            }
          ]
        };
      }
    }
  });
})();

Step 2: Upload the File to Your Server

Upload localbusiness_webmcp_template.js to your website’s public scripts or assets directory (for example, /js/localbusiness_webmcp_template.js). Serving it as an external same-origin file prevents Content Security Policy (CSP) blocks that often affect inline script tags.

Step 3: Load the Script in Your Website Footer

Reference the script right before your closing </body> tag using the defer attribute so it never blocks initial page rendering:

<script src="/js/localbusiness_webmcp_template.js" defer></script>

Step 4: Keep NAP Data Consistent Across Schema and WebMCP

Make sure the business name, street address, phone number, and opening hours inside BUSINESS_CONFIG match your LocalBusiness JSON-LD Schema markup and your Google Business Profile character-for-character. Consistent entity signals build trust across traditional search engines and AI answer engines alike.

3 Technical Checks Before Going Live

  1. Verify HTTPS: The navigator.modelContext API only runs in secure contexts. Confirm your entire domain redirects cleanly to https://.
  2. Exclude from Delay-JS Caching Rules: If you use caching or speed optimization tools that delay JavaScript execution until human mouse movement or scrolling, add localbusiness_webmcp_template.js to your exclusion list so automated agents register the tools immediately on page load.
  3. Test Your Contact Fallback or Webhook: Leaving contactEndpoint blank ("") safely directs AI agents to your email and phone number out of the box. If you connect a JSON webhook or form endpoint later, submit a test payload to verify delivery.

Setting up clean technical foundations, fast semantic HTML, accurate and nested JSON-LD Schema, and lightweight WebMCP tools will position your local business ahead of competitors still relying on outdated SEO tactics. If you need help auditing your website’s technical SEO, AEO readiness, or custom site performance setup, reach out to RankYa for professional assistance.

By Tolga Savas

Tolga Savas is an Australian web developer, technical SEO consultant, and digital content creator. As the founder of RankYa, Tolga brings over 10 years of hands-on expertise in WordPress and Shopify code-level optimization, technical search engine optimization, Agentic AI discovery, and Google Search Console remediation.

Questions? Leave a Comment!

Your email address will not be published. Required fields are marked *