1 Dec 2026 · Pinto kumar
Why a plain form isn’t enough for AI agents
A contact form built for people is easy for an agent to misuse. It has visible labels, but nothing says which fields are required, how long a message may be, or what happens after Send. The agent guesses before it submits, and afterwards it gets a page reload and has to guess again whether anything worked.
WebMCP lets a page publish tools that agents call directly. Two parts of a tool definition remove those two guesses: inputSchema describes what goes in, and outputSchema describes what comes back. This post builds both on a real form, the contact form on theuniversalcommerceprotocol.com, from the schema to a tested result.
What inputSchema and outputSchema do
Both are JSON Schema, the same format used to describe API requests. The agent reads them before it calls the tool, so it can build a valid call the first time and know what a result looks like.
| Part | Question it answers | In our contact form |
|---|---|---|
inputSchema | What must I send? | name, email and message are required, subject is optional, each with a length limit |
outputSchema | What do I get back? | ok, status and message, so success or failure is a field, not a guess |
Together they turn “fill in a form and hope” into “call a function and read the result”.

The example: the UCP contact form
The form has four fields: Name, Email, Subject and Message, plus a Send Message button. People fill it in and submit it. The site’s server already validates every submission, checks the fields, limits how often one visitor can send, and delivers the inquiry.
The WebMCP tool does not replace any of that. It is a second front door to the same handler, so an agent and a human go through the same validation and the same limits. What changes is how the agent learns what to send and how it learns the outcome, which is exactly what the two schemas provide.
The tool lives in a small snippet that runs only on the contact page, and the human form is untouched.

Step 1: write the inputSchema
Start with what the server will accept, then describe it field by field.
var inputSchema = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 100, description: 'Full name of the person' },
email: { type: 'string', format: 'email', maxLength: 254, description: 'Email address for the reply' },
subject: { type: 'string', maxLength: 150, description: 'Short topic of the inquiry (optional)' },
message: { type: 'string', minLength: 1, maxLength: 2000, description: 'The inquiry or question about UCP' }
},
required: ['name', 'email', 'message'],
additionalProperties: false
};
requiredlists the three fields a submission cannot do without.subjectis left optional, as it is on the form.additionalProperties: falsestops an agent from inventing extra fields.format: 'email'tells the agent the value must look like an address, so it asks the user instead of sending a placeholder.- Length limits for
name,subjectandmessagematch what our server applies, so an agent that follows the schema does not hit a rejection. descriptionis read by the model. Keep each one short and plain; they are the instructions for filling that field.
Step 2: write the outputSchema and the execute function
The outputSchema fixes the shape of the answer. A single status value says what happened, and ok gives a quick yes or no.
var outputSchema = {
type: 'object',
properties: {
ok: { type: 'boolean' },
status: { type: 'string', enum: ['received', 'invalid', 'rate_limited', 'error'] },
message: { type: 'string' }
},
required: ['ok', 'status', 'message']
};
The execute function is what runs when an agent calls the tool. It sends the same form data a human submission sends, then turns the server’s answer into that shape.
async function execute(input, ctx) {
var body = new URLSearchParams();
['name', 'email', 'subject', 'message'].forEach(function (k) {
body.set(k, String((input && input[k]) || ''));
});
try {
var res = await fetch('/contact/', { method: 'POST', body: body,
credentials: 'same-origin', signal: ctx && ctx.signal });
var code = new URL(res.url).searchParams.get('ucp_sent');
if (code === '1') return { ok: true, status: 'received', message: 'Inquiry received. The site owner will reply by email.' };
if (code === 'invalid') return { ok: false, status: 'invalid', message: 'Name, a valid email and a message are required.' };
if (code === 'limit') return { ok: false, status: 'rate_limited', message: 'Too many submissions. Try again later.' };
return { ok: false, status: 'error', message: 'Unexpected response (HTTP ' + res.status + ').' };
} catch (e) {
return { ok: false, status: 'error', message: 'Network error. Nothing was sent.' };
}
}
The server answers a submission with a redirect that carries a result code in the address. fetch follows the redirect, and the function reads the code from the final URL. No new server code was needed for the tool.
status | ok | Meaning | What an agent can do |
|---|---|---|---|
received | true | The inquiry was accepted | Tell the user it was sent |
invalid | false | A required field was missing or the email was malformed | Ask the user to fix the input and call again |
rate_limited | false | Too many submissions from one visitor | Stop and tell the user to try later |
error | false | Network failure or an unexpected response | Report it; do not assume the message was sent |

Step 3: register the tool
Registration ties the name, description, both schemas and execute together.
function init() {
if (!document.querySelector('#ucp-contact-form')) return;
var mc = document.modelContext || navigator.modelContext;
if (!mc || !mc.registerTool) return;
mc.registerTool({
name: 'submit_inquiry',
description: 'Send an inquiry or question about the Universal Commerce Protocol to the site owner. Sends a real email, so only call it with details the user gave you.',
inputSchema: inputSchema,
outputSchema: outputSchema,
annotations: { readOnlyHint: false, consequentialHint: true },
execute: execute
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
- Run it after the page has loaded, and only on the page that has the form. In a WordPress header snippet the form does not exist yet when the script first runs.
- Check for support first. In a browser without WebMCP the function returns quietly, and the human form works exactly as before.
document.modelContextis the newer name. In the Chrome Canary build we tested,document.modelContextexisted andnavigator.modelContextdid not, so the code tries the new one first.- Say that the action has a real effect. The description tells the agent this sends an email, and
consequentialHint: trueflags the same thing to the tooling around it.
Testing it in Chrome
- In Chrome (we used Chrome Canary), open
chrome://flags, enable WebMCP for testing and relaunch. - Install the WebMCP – Model Context Tool Inspector extension from the Chrome Web Store.
- Open the contact page and open the extension’s side panel. It lists
submit_inquirywith its description, itsinputSchemaand its annotations. Canary’s DevTools also lists registered tools under Application, then WebMCP. - Under Interact with the Page, pick
submit_inquiry, enter the arguments and click Execute Tool.
The call returned this, which is the outputSchema shape:
{"ok":true,"status":"received","message":"Inquiry received. The site owner will reply by email."}
Running the tool sends a real inquiry, so use obvious test text. Also try a malformed email: the server should answer invalid with ok: false, which is the case an agent most needs to handle.
Why this is useful
- Fewer wrong calls. The agent knows the required fields, the email format and the length limits before it calls, so it asks the user for what is missing instead of guessing.
- A real answer instead of a page reload.
ok,statusandmessagetell the agent exactly what happened. - Errors an agent can act on.
invalidmeans fix the input and retry,rate_limitedmeans stop,errormeans do not assume it was sent. A plain form gives all three the same blank result. - One path for humans and agents. The tool calls the same handler as the form, so validation, rate limits and delivery are identical and there is only one thing to maintain.
- Safer by design. A clear description,
consequentialHintandadditionalProperties: falsemake a tool that sends email hard to call by accident. - Small to ship and easy to undo. The whole tool is a short script in one snippet. Deactivating the snippet removes it and leaves the form as it was.
Start small: one form, one tool, two schemas. Once the contact form behaves, the same pattern fits any form on your site, such as search or a newsletter signup.
Leave a Reply