webToolSignature
Returns a string of what WebMCP sees of a tool.
Returns a string of what WebMCP sees of a tool. When it changes, the tool must re-register; when it does not, it must not, because Chrome cancels the calls of a tool whose definition changes. Reach for it when you build your own registration on top of registerWebTool.
Import
import { webToolSignature } from "@webmcp-agents/core";
Example
Re-register a tool only when the definition the agent sees changed.
import { type WebTool, webToolSignature } from "@webmcp-agents/core";
let registered: string | undefined;
/** Re-register only when what the agent sees changed. */
export function needsReregistration(next: WebTool): boolean {
const signature = webToolSignature(next);
const changed = signature !== registered;
registered = signature;
return changed;
}
Options
webToolSignature(tool).
| Name | Type | Default | Description |
|---|---|---|---|
tool |
WebTool |
required | The tool to describe, made with defineWebTool. |
Returns
A string: JSON.stringify of [id, title, description, jsonSchema, annotations ?? null, !!requireConfirmation, target ?? null], where annotations are the merged hints (the tool’s annotations with its flags written over them), so changing a flag changes the signature.
Notes
executeis not part of the signature: a newexecutealone needs no re-registration. Neither arematch,fillorfields: a registered tool reads them from its latest definition on every call.- A locator or selector
targetis part of the signature. A functiontargetstringifies tonull, so swapping one functiontargetfor another does not change the signature (the new one is read on the next call). createToolRegistryuses it inupdate(catalog), anduseWebTooluses it to decide when to re-register.
See also
- Define a tool, what a definition holds
createToolRegistry, which compares signaturesdefineWebTool, the definition it reads- Tool lifecycle, why a changed tool cancels calls