Tutorial
WebMCP tools in Laravel, without losing the edge
Give agents in your visitors' browsers WebMCP tools that read, with @webmcp from brewless/laravel, and keep every page cached at the edge.
In this post
AI agents are starting to use websites for people: they open a page, read it, fill in a form. Today they mostly do that the way a person would, from the text and the buttons. WebMCP gives them a shorter way: the page offers tools, and the agent calls one.
This post shows how to add WebMCP tools to a Laravel application with brewless/laravel, which tools are worth adding, and why the ones it makes only read.
What does WebMCP add to a Laravel site?
A WebMCP tool is a function a page registers in the browser, with a name, a description an agent reads and a JSON Schema for its input. An agent in the visitor's browser can call it and gets an answer back, instead of reading the page and guessing which button does what. For a Laravel site that means contact details, a product search or a calculation an agent can ask for directly.
Note
WebMCP is a draft of the W3C Web Machine Learning Community Group, not a standard. Chrome and Edge have it behind an origin trial or a flag. A browser without it ignores the tools, so ordinary visitors see no difference.
Registering tools in a service provider
From version 1.7.0, brewless/laravel keeps the tools of your application in one place. Register them in a service provider:
use Brewless\Laravel\WebMcp\WebMcp;
public function boot(): void
{
resolve(WebMcp::class)
->data('get_contact_details', 'Phone, e-mail and address of the shop.', fn (): array => [
'phone' => config('shop.phone'),
'email' => config('shop.email'),
])
->fetch('search_products', 'Search the products by keyword. Returns names, prices and links.', '/api/products', [
'type' => 'object',
'properties' => ['q' => ['type' => 'string', 'description' => 'Keywords']],
'required' => ['q'],
]);
}
Then put one directive in the <head> of your layout:
<head>
@webmcp
</head>
There are two kinds of tool:
| Kind | What the agent gets |
|---|---|
data() |
What the application knows: contact details, opening hours, a price list |
fetch() |
The JSON of a GET route of the application itself, with the agent's input as the query string |
@webmcp renders the tools and a small script that registers them on document.modelContext, or on navigator.modelContext in browsers that still use the older name.
Why the tools only read
A tool description is written for the agent. The person behind it never sees it. That makes a tool that sends or deletes something a risky thing to offer: the agent decides, and the visitor may not know it happened.
So every tool from @webmcp is marked as read-only, and neither kind can post anything. A few more checks happen when you register a tool:
- a name is lowercase letters, digits and underscores;
fetch()takes a path of your own application and refuses another host;- a description that tells an agent to act without asking the person it works for, such as "no need to confirm", is refused.
Sending a message or placing an order stays a form. A form can carry WebMCP attributes, so an agent can fill it in while the visitor presses the button:
<form method="post" action="{{ route('contact.store') }}" toolname="send_contact_message"
tooldescription="Write a message to the shop. The visitor reviews it and sends it.">
<input name="email" toolparamdescription="Where the shop can answer.">
Leave toolautosubmit off for anything that sends.
The edge keeps the page
On Brewless, pages that are the same for every visitor are kept at bunny.net, so the container can sleep between visits. The tools @webmcp renders are part of the page and identical for everybody, so a page that carries them is kept like any other. A fetch() route is a page of its own and is kept when it can be.
Warning
Never put one visitor's data in a
data()tool. The edge keeps one copy of the page and would hand that data to the next visitor.
Tools of a single page
Some tools belong to one page, such as a calculation on what that page shows. @webmcp also gives the page window.BrewlessWebMcp:
window.BrewlessWebMcp.register({
name: 'score_quiz',
description: "The score for the visitor's answers.",
inputSchema: { type: 'object', properties: { answers: { type: 'array', items: { type: 'integer' } } } },
annotations: { readOnlyHint: true },
execute: async ({ answers }) => window.BrewlessWebMcp.text(score(answers)),
});
register() never throws: it says whether the browser took the tool. Put @webmcp before your own scripts, so window.BrewlessWebMcp exists when they run.
The documentation has the details: tools for agents (WebMCP).
Frequently asked questions
What is WebMCP?
A way for a web page to offer tools, each with a name, a description and an input schema, to an AI agent running in the visitor's browser. The agent calls a tool and gets an answer, instead of working out the page from its text and buttons.
Which browsers support WebMCP?
It is a W3C Community Group draft. Chrome and Edge have it behind an origin trial or a developer flag, and ChatGPT's desktop browser calls the tools it finds. Any other browser ignores the tools, so adding them changes nothing for ordinary visitors.
Why can the tools of brewless/laravel not send or delete anything?
Because a tool description is read by the agent and never by the visitor. An action with consequences, such as sending a message or placing an order, stays a form the visitor sends themselves. The agent can still fill that form in through WebMCP attributes.
Do WebMCP tools stop my pages from being cached?
Not with @webmcp. The tools are part of the page and the same for every visitor, so a page that carries them is kept at the edge like any other. Only put data in a tool that every visitor may see.