Skip to main content

WebMCP — on-page AI co-piloting

WebMCP is the "on your page" surface. It exposes your site's forms and actions as in-browser tools that AI agents can discover and invoke through the browser's document.modelContext API — so an agent can complete tasks for your visitor, starting with form-filling.

NxisAI auto-generates the WebMCP tool contract from the Action structured data on your page — no hand-written tool code required.

Honest scope

WebMCP makes your forms actionable by in-browser agents — form-filling works today, with more app actions on the roadmap. It's a mechanical capability; it doesn't change whether an agent chooses to use your site.

How it works​

When a page contains NxisAI Action JSON-LD, the WebMCP module reads each Action, converts it into a tool with a JSON Schema, and registers it via document.modelContext.registerTool(). When an agent calls the tool, the library locates the matching <form>, fills it, and submits it:

  1. Parse — read all <script type="application/ld+json"> blocks and extract Action nodes (SearchAction, RegisterAction, etc.).
  2. Schema — convert each Action's field descriptors into a JSON Schema inputSchema.
  3. Register — call document.modelContext.registerTool() with a name, description, schema, and execute callback.
  4. Locate — when invoked, find the matching <form> by URL/method and field matching.
  5. Fill — set values using native property setters (bypassing framework interceptors) and dispatch input/change events so React, Vue, and Angular react correctly.
  6. Submit — call requestSubmit() (respecting validation) and return a structured result so the agent can self-correct on failure.

Option 1 — Enable via the CDN (no build step)​

For static sites, no manual configuration or local JavaScript is required. Just add the standard CDN script tag to your <head> (replace ${TOKEN} with your site token):

<script
type="text/javascript"
async
src="https://cdn.nxis.ai/nxis.js?token=${TOKEN}"
crossorigin="anonymous">
</script>

The NxisAI CDN customizes the script for your site at request time: it reads your webmcp entitlement from the token and prepends the right configuration into the served file automatically. When the script runs, it injects your page's JSON-LD and registers your forms as WebMCP tools — as long as your webmcp mode is browser (the default).

info

WebMCP registration through the CDN is on by default for sites whose plan includes it. There's nothing to set in your HTML beyond the script tag above.

Option 2 — Register from your app code​

If you build with a bundler, import registerActions from @nxisai/webmcp/actions and register all Action tools found in the page's JSON-LD:

npm install @nxisai/webmcp
Coming from @nxisai/nxis/webmcp?

@nxisai/nxis/webmcp is the deprecated 2.x path for the same API. Change the import to @nxisai/webmcp/actions; nothing else changes. See Migrating to @nxisai/sdk.

import { registerActions } from '@nxisai/webmcp/actions';

// Register all Action tools found in the page's JSON-LD
const cleanup = registerActions();

// Later — unregister all tools and disconnect observers:
cleanup();

Options​

import { registerActions } from '@nxisai/webmcp/actions';

const cleanup = registerActions({
doc, // Document to scan (defaults to `document`)
signal, // AbortSignal for external cancellation
observe, // MutationObserver re-scan for SPAs (default: true)
});
OptionTypeDefaultDescription
docDocumentdocumentThe document to scan for JSON-LD blocks. Useful for iframes.
signalAbortSignal—An external signal to cancel all registrations.
observebooleantrueWhen true, a MutationObserver registers new Action tools as structured data is injected (great for SPAs).

SPA support​

By default, registerActions() watches the document for newly injected <script type="application/ld+json"> blocks and registers any new Action tools automatically (de-duplicated). For fully static pages, opt out:

const cleanup = registerActions({ observe: false });

Supported Action types​

NxisAI classifies your forms into Schema.org Action subtypes:

Action TypeExample Use Case
SearchActionSite search, product search
RegisterActionEvent registration, account sign-up
SubscribeActionNewsletter opt-in, mailing list
BuyActionPurchase, checkout
OrderActionFood ordering, service booking
ScheduleActionAppointment scheduling
ReserveActionReservation forms
CommunicateActionContact forms, feedback
ApplyActionJob applications
AskActionQ&A, support tickets
QuoteActionQuote requests
ReviewActionReviews, ratings
CommentActionComment forms
AddActionAdd-to-cart, add-to-list
RsvpActionEvent RSVPs
DownloadActionGated downloads, resource requests
TrackActionOrder/shipment tracking lookups
InteractActionGeneric interaction forms

Using WebMCP with SSR frameworks​

WebMCP is a browser-only feature — it depends on the live DOM and document.modelContext, so it can't run during the server render. In SSR/SSG environments (server components, getServerSideProps, loaders, the Nuxt/SvelteKit server pass), registerActions() detects there's no document and safely no-ops.

This composes cleanly with SSR: your server render injects the JSON-LD (via NxisClient.getStructuredData), and registerActions() then reads those same <script type="application/ld+json"> tags in the browser after hydration. Call it from a client-only lifecycle hook.

Without a build step, the CDN tag with a token in ssr mode does the same thing: it registers tools from the server-rendered JSON-LD and doesn't inject a second copy.

Next.js (App Router) — a client component:

'use client';
import { useEffect } from 'react';
import { registerActions } from '@nxisai/webmcp/actions';

export function NxisWebMCP() {
useEffect(() => {
const cleanup = registerActions(); // runs only in the browser
return cleanup; // unregister on unmount
}, []);
return null;
}

Render <NxisWebMCP /> once in your layout. Equivalent hooks for other frameworks: Nuxt onMounted() (or wrap in <ClientOnly>), Remix useEffect, SvelteKit onMount.

note

The @nxisai/webmcp/actions entry point ships as an ES module that is safe to import on the server (it no-ops without a DOM). A CommonJS require() of this entry point is not supported — import it with ESM import syntax.

Browser support​

WebMCP requires document.modelContext, available natively in Chrome 138+. On older browsers, NxisAI installs the @nxisai/webmcp polyfill automatically so your tool registrations still work, and registerActions() gracefully no-ops in non-browser environments (SSR, Node.js, workers).


Advanced exports​

For consumers who need lower-level access, @nxisai/webmcp/actions also exports:

// Parse Action JSON-LD without registering tools
import { readActions } from '@nxisai/webmcp/actions';
const actions = readActions(document);

// Build a JSON Schema from an Action (for testing or custom registration)
import { buildInputSchema } from '@nxisai/webmcp/actions';
const schema = buildInputSchema(action);

// Contract types
import type {
NxisAction,
NxisEntryPoint,
NxisPropertyValueSpecification,
} from '@nxisai/webmcp/actions';

Advanced: the WebMCP polyfill​

The root of @nxisai/webmcp (the same package that provides /actions) is a standalone TypeScript polyfill for the WebMCP API. Use it to write against document.modelContext directly — for custom, hand-built tools beyond the auto-generated form tools.

npm install @nxisai/webmcp

Register a custom tool​

import '@nxisai/webmcp/auto';

const controller = new AbortController();

document.modelContext.registerTool(
{
name: 'add-todo',
description: "Add a new item to the user's active todo list",
inputSchema: {
type: 'object',
properties: {
text: { type: 'string', description: 'The text content of the todo item' },
},
required: ['text'],
},
async execute({ text }) {
await addTodoItemToCollection(text);
return {
content: [{ type: 'text', text: `Added todo item: "${text}" successfully.` }],
};
},
},
{ signal: controller.signal }
);

// Later: unregister by aborting.
controller.abort();

Swap the toolset on navigation​

Use provideContext() to replace the page-level toolset wholesale — handy on SPA route changes:

document.modelContext.provideContext({ tools: [searchTool, filterTool] });

// Navigating to checkout? Swap the toolset:
document.modelContext.provideContext({ tools: [checkoutTool] });

Polyfill API​

MemberDescription
registerTool(tool, { signal? })Register one tool. Re-registering a name replaces it; abort the signal to unregister.
provideContext({ tools? })Set the page-level toolset; each call replaces the previous one.
getTools()Resolve the list of registered tools (without execute).
executeTool(name, input?)Validate input against the tool's inputSchema and run it. Returns { content: [...] }.
toolchange eventFired when the toolset changes.

When a native WebMCP implementation is present, the polyfill steps aside automatically.