Packages

The WebMCP package

Experimental. A Culm plug-in whose one content is a script that registers a page's declared tools with the browser's document.modelContext⁠. A browser without document.modelContext gets no tools: the script returns at once.

The tools are proved only in Chromium launched with --enable-features=WebMCPTesting (HeadlessChrome 156). No trial token has been tried. Safari and Firefox were not run.

Set up

Nothing is on npm yet. In a checkout of this repository run npm run pack:all⁠, which writes the tarballs to .pack/ (first run makes a site from them). Then, in the site folder:

  1. npm install <checkout>/.pack/culmjs-webmcp-0.0.0.tgz

    . culm init does not add this package.

  2. In culm.json⁠, add the package to plugins⁠:

    "plugins": ["@culmjs/webmcp"]

    .

  3. Run culm agents on and type the site's name. It needs a terminal.

The script is on a built page only when that page has a tool that is drawn. culm check lists each page's declared tools.

What is listed

The script registers a tool when the element a visitor would press is visible by checkVisibility()⁠: it and everything around it is displayed, and it is not inside a closed details⁠. For a trigger-loaded tool that is the firing element; for an island's act it is the island's element. It registers again on a window resize⁠, if the set of such elements has changed.

A class read tool carries the read-only hint and a class send tool the consequential hint. An island's act also carries the untrusted-content hint.

What a call does

Tool

What the script does

Result

Tool

Click

What the script does

Clicks the element

Result

{ "state": … } or {}

Tool

Live form

What the script does

Sets the fields, checks the form's validity, calls requestSubmit()

Result

{ "state": … }

Tool

Static form

What the script does

The same

Result

None: the page navigates

Tool

Form that waits

What the script does

Sets the fields and focuses the form's first [type=submit] button. Sends nothing

Result

{ "pending": "visitor" }

Tool

Trigger-loaded node

What the script does

Sets and checks the form on or around the node, if any, then presses the firing element

Result

{ "state": … }

Tool

Act of an island

What the script does

Dispatches culm-act on the island's element

Result

The island's reply

  • A click on a tool that changes a state returns { "state": … }⁠, the state's new value (⁠null if no element around the button holds it). Any other click returns {}⁠.

  • A live result's state is ready⁠, empty or error⁠, written by the live script when the request settles. A click, form or trigger result holds no text the backend sent. An act's result is whatever the island replies.

  • An island's reply is copied through JSON. A reply that cannot be copied is null⁠.

  • A form that waits (⁠confirm: "visitor"⁠) is not checked for validity by the script.

Fields

  • Setting a field writes its value and dispatches input and change⁠. A number is written as its text. In a textarea, CRLF and CR become LF.

  • An optional parameter the agent leaves out keeps whatever its field already holds, including text the visitor typed, and that is sent.

  • In a live form or a trigger-loaded tool, the first control with the field's data-key is set. In a static form, whether it waits or not, where several controls share a name: the first that is not type="hidden" and is visible, else the first that is not hidden.

Failures

A refused call returns { "ok": false, "reason": … }⁠.

reason

When

reason

invalid

When

The input does not fit the tool's schema (a missing required name, an unknown name, a wrong type). A parameter has no matching field, or a tool with parameters has no form. A field would change the value (a text input strips line breaks, an email field trims spaces) or the value is longer than the field allows. The form fails checkValidity()

reason

not-started

When

A live gesture started no request, for example because the form's trap field is filled

reason

not-ready

When

The element is no longer visible, or an island did not acknowledge the act

reason

timeout

When

The outcome is unknown: nothing settled in 10 seconds (including an island that never replies), or a later request on the same live node replaced the call's own

Nothing is sent after invalid⁠. A missing field is found before any field is written. After the other invalid cases that follow writing, fields may be left holding the agent's text: when a field changes the value or finds it too long, that field and the ones filled before it; when the form fails its validity check, every field set.

An unforeseen error rejects the call instead of returning a reason; an island that replies with a promise that rejects is one.

Limits

  • A call sends more than the agent's parameters. It does what the visitor's press does, so a live request is the one the page declares, made as the visitor: the fields, stored values and fixed text its send names, the signed-in key as Authorization to its own backend, and cookies when the source has cookies: true (only to a backend on the page's own origin). This is so whatever the tool's class. A reply that stores a value makes each live node that sends it, has already asked and does not send on submit ask again. A static form posts all its fields, not only the parameters.

  • A tool inside a popover, dialog or details that is closed when the page loads is not listed. Opening one fires no resize: the tool is listed only after a window resize while it is open.

  • An element hidden with visibility: hidden or opacity: 0 is still listed, and a call acts on it, because entrance animations start at visibility: hidden⁠.

  • A tool whose element stops being visible stays listed until a window resize; a call returns not-ready⁠.

  • An act is listed before its island has mounted, and returns not-ready until it has: an island that loads when visible until it is within 200 pixels of the screen, interact until the visitor points at, presses or focuses it, idle until the browser is idle. An island that fails to mount stays not-ready⁠.

  • input and change fire once per field, not once per keystroke.

  • A static form, and a live reply that navigates, promise no result: the document that would answer is gone.

  • After a timeout⁠, or a navigation during a call, the outcome is unknown: a send may or may not have gone out.

  • A later request on the same live node (a second call, the visitor's press, a re-run on a value change, an every reload) replaces the one in flight: the earlier call returns timeout at once. Its request may already have reached the backend.

  • A scripted click does not move focus to the button as a pointer does. Only a form that waits sets focus; one with no [type=submit] button leaves focus where it is and still returns { "pending": "visitor" }⁠.

  • If the browser refuses to register a tool, the script says nothing and registers the rest.

Edit this page on GitHub