///
import { MaybeRefOrGetter, Ref, ShallowRef, ComputedRef, InjectionKey } from 'vue';
import { W as WebMCPToolAnnotations, a as WebMCPToolExecuteOptions, R as RegisteredTool, b as WebMCPToolResponse } from './shared/vue-webmcp.BUJ4eDiy.mjs';
export { E as ExecuteToolOptions, G as GetToolsOptions, M as ModelContext, c as RegisterToolOptions, d as WebMCPContentBlock, e as WebMCPToolDescriptor } from './shared/vue-webmcp.BUJ4eDiy.mjs';
interface UseWebMCPToolOptions, Result = unknown> {
/**
* Tool identifier the agent sees. 1–128 characters of `[a-zA-Z0-9_.-]`;
* Chrome's guidance is at most 30.
*/
name: MaybeRefOrGetter;
/** Human-readable label for user-agent UI. Agents reason over `name` and `description`. */
title?: MaybeRefOrGetter;
/** Natural-language description for the agent. Chrome's guidance: keep under 500 characters. */
description: MaybeRefOrGetter;
/** JSON Schema for the tool arguments. Compared by content, not identity. */
inputSchema?: MaybeRefOrGetter;
annotations?: MaybeRefOrGetter;
/**
* Secure origins (for example an iframe-hosted agent) that may discover and
* call the tool, in addition to the registering page, its same-origin
* frames, and the browser's own agent.
*/
exposedTo?: MaybeRefOrGetter;
/**
* Runs when the agent invokes the tool. Reads reactive state live at call
* time; swapping the function never re-registers the tool.
*
* `options.signal` aborts when the caller cancels the execution or goes
* away: hand it to `fetch` and other cancellable work.
*/
execute: (args: Args, options: WebMCPToolExecuteOptions) => Result | Promise;
/** Register only while true. May be a ref or getter — the tool follows it reactively. */
enabled?: MaybeRefOrGetter;
/** Optional shaper applied to the result before MCP normalization. */
formatOutput?: (result: Result, args: Args) => unknown;
/**
* Side effect when `execute` throws or returns an `Error`. The agent still
* receives an `isError` response afterwards.
*/
onError?: (error: unknown) => void;
}
interface UseWebMCPToolReturn {
/** A modelContext API exists in this environment. Flips reactively if injected late. */
isSupported: Readonly[>;
/** The tool is currently registered with the browser. */
isRegistered: Readonly][>;
/** Registration failure, e.g. `NotAllowedError` from a `tools` Permissions Policy. */
error: Readonly][>;
}
/**
* Registers a WebMCP tool with the browser and ties its lifetime to the
* current component or effect scope, so the set of tools an agent sees stays
* in lockstep with what is actually on screen.
*
* Feature-detects `document.modelContext` and degrades to a no-op everywhere
* the API is absent, including during SSR.
*/
declare function useWebMCPTool], Result = unknown>(options: UseWebMCPToolOptions): UseWebMCPToolReturn;
/**
* Typed identity helper, so a tool definition can live in a plain module
* (importable, testable, no component needed to write it) and keep the
* inferred `Args` and `Result` types, and its literal name, when it is
* registered later.
*/
declare function defineWebMCPTool, Result = unknown, const Name extends MaybeRefOrGetter = string>(definition: Omit, 'name'> & {
name: Name;
}): Omit, 'name'> & {
name: Name;
};
type AnyToolOptions = UseWebMCPToolOptions;
/** Options applied to every tool in the group unless the tool sets its own. */
interface UseWebMCPToolsSharedOptions {
enabled?: MaybeRefOrGetter;
annotations?: MaybeRefOrGetter;
exposedTo?: MaybeRefOrGetter;
/** Receives the failing tool's name as well, since one handler serves the group. */
onError?: (error: unknown, name: string) => void;
}
/** Static tool names in a definitions tuple; reactive names fall back to `string`. */
type ToolNames = T[number]['name'] extends string ? T[number]['name'] : string;
interface UseWebMCPToolsReturn {
/** A modelContext API exists in this environment. */
isSupported: Readonly[>;
/**
* Every enabled tool in the group is registered. Tools switched off through
* `enabled` are left out, so a group with its read tools on and its write
* tools off still counts as registered; `false` while no tool is enabled.
*/
isRegistered: Readonly][>;
/** The first registration failure in the group, if any. */
error: Readonly][>;
/** Per-tool state, keyed by each tool's name at setup time. */
byName: Readonly]>;
}
/**
* Registers a group of tools from one component or scope, with options
* shared across the group. Each tool still goes through `useWebMCPTool`, so
* per-tool `enabled`, `annotations`, `exposedTo` and `onError` win over the
* shared ones, the per-tool state stays reachable through `byName`, and one
* tool failing to register leaves the others registered.
*/
declare function useWebMCPTools(definitions: T, shared?: UseWebMCPToolsSharedOptions): UseWebMCPToolsReturn>;
interface UseRegisteredToolsOptions {
/**
* Origins whose tools to include on top of the same-origin default. Each
* must be a secure origin whose document listed this page in `exposedTo`.
*/
fromOrigins?: MaybeRefOrGetter;
/**
* How to hand arguments to `executeTool()`. Leave unset to detect it: the
* JSON string Chrome shipped with is tried first, and the object form the
* spec adopted in PR #246 (2026-08-17) is used from then on if the browser
* rejects the string with a `TypeError`. Set it to skip the detection.
*/
argumentFormat?: 'object' | 'json';
}
/**
* Options for the composable's `execute`; the browser-level counterpart is
* `ExecuteToolOptions`.
*/
interface ExecuteRegisteredToolOptions {
/** Aborts the execution; the tool's `execute` sees it through its own signal. */
signal?: AbortSignal;
}
interface UseRegisteredToolsReturn {
/** `getTools()` and `executeTool()` exist here. Flips reactively if injected late. */
isSupported: Readonly[>;
/** Tools this document may call, sorted by name, refreshed on `toolchange`. */
tools: Readonly]>;
/** Failure of the last `getTools()` call. */
error: Readonly[>;
/** Query `getTools()` again. Runs by itself on every `toolchange` event. */
refresh: () => Promise];
/**
* Run a discovered tool in its owner's document. Resolves with the tool's
* result parsed from the JSON the browser returns, so an MCP-shaped result
* comes back as `{ content: [...] }`. Rejects with the browser's
* `DOMException` when the tool or the browser fails, and with a
* `NotSupportedError` when the API is absent.
*/
execute: (tool: RegisteredTool, args?: object, options?: ExecuteRegisteredToolOptions) => Promise;
}
/**
* Lists the WebMCP tools this document may call and lets it run them, for
* in-page agents, dev panels, or an iframe-hosted agent reading a partner
* page's tools. Follows the `toolchange` event, so the list stays current as
* components register and unregister tools.
*
* Feature-detects `document.modelContext.getTools` and stays empty where the
* consumer side of the API is absent, including during SSR.
*/
declare function useRegisteredTools(options?: UseRegisteredToolsOptions): UseRegisteredToolsReturn;
declare global {
interface SubmitEvent {
/** True when an agent submitted the form through its WebMCP tool. */
readonly agentInvoked: boolean;
/**
* Hands the agent the tool result: the resolved value is serialized and
* returned to the model. Call `preventDefault()` first, and call it while
* the event is being dispatched.
*/
respondWith(agentResponse: Promise): void;
}
/** `toolactivated` / `toolcancel` on `window`; neither bubbles nor cancels. */
interface WebMCPEvent extends Event {
readonly toolName: string;
}
interface WindowEventMap {
toolactivated: WebMCPEvent;
toolcancel: WebMCPEvent;
}
}
/** One entry, or every entry when a name repeats (a checkbox group, ``). */
type FormFieldValue = FormDataEntryValue | FormDataEntryValue[];
type FormFields = Record;
interface UseWebMCPFormOptions {
/** The form's `toolname`. */
name: MaybeRefOrGetter;
/** The form's `tooldescription`. */
description: MaybeRefOrGetter;
/** Let the agent submit without a click (`toolautosubmit`). */
autosubmit?: MaybeRefOrGetter;
/**
* Handles a submission, by a person or by an agent, with the form's fields
* as `FormData` entries. The return value is normalized like a
* `useWebMCPTool` result and handed to the agent when one asked.
*/
execute: (fields: Fields, event: SubmitEvent) => Result | Promise;
/** Optional shaper applied to the result before normalization. */
formatOutput?: (result: Result, fields: Fields) => unknown;
/** Side effect when `execute` throws; the failure also lands in `error`. */
onError?: (error: unknown) => void;
}
interface WebMCPFormAttrs {
toolname: string;
tooldescription: string;
toolautosubmit?: '';
onSubmit: (event: Event) => Promise;
}
interface UseWebMCPFormReturn {
/** Spread onto the form: `