import type { StandardSchemaV1 } from '@standard-schema/spec'; interface InputSchemaProperty { type?: string; description?: string; [key: string]: unknown; } /** JSON Schema definition for tool input parameters. */ export interface InputSchema { type?: string; properties?: Record; required?: readonly string[]; [key: string]: unknown; } type JsonObject = Record; /** The result returned from tool execution (MCP CallToolResult shape). */ interface CallToolResult { content: Array<{ type: string; [key: string]: unknown; }>; structuredContent?: JsonObject; isError?: boolean; } /** Per-call client provided to tool handlers. */ export interface ModelContextClient { requestUserInteraction(callback: () => Promise): Promise; } type MaybePromise = T | Promise; type ToolRawResult = unknown; type ToolExecuteResult = TResult extends CallToolResult ? TResult : CallToolResult | TResult; /** Standard WebMCP tool annotations (native accepts booleans or 'true'/'false'). */ interface ToolAnnotations { title?: string; readOnlyHint?: boolean | 'true' | 'false'; untrustedContentHint?: boolean | 'true' | 'false'; destructiveHint?: boolean | 'true' | 'false'; idempotentHint?: boolean | 'true' | 'false'; openWorldHint?: boolean | 'true' | 'false'; } /** Tool descriptor for the Web Model Context API. */ export interface ToolDescriptor = Record, TResult = ToolRawResult, TName extends string = string> { name: TName; title?: string; description: string; inputSchema?: InputSchema; outputSchema?: Record; annotations?: ToolAnnotations; execute: (args: TArgs, client: ModelContextClient) => MaybePromise>; } /** Tool info returned by ModelContextTesting.listTools(). */ export interface ModelContextTestingToolInfo { name: string; description: string; /** JSON Schema, serialized as a JSON STRING (Chromium's native contract). */ inputSchema?: string; } /** Tool info returned by the producer-facing ModelContext.getTools(). */ export interface ModelContextToolInfo extends ModelContextTestingToolInfo { title: string; origin: string; /** [edge-mcp fork] Standard annotations, carried through getTools(). */ annotations?: ToolAnnotations; } export interface ModelContextTestingExecuteToolOptions { signal?: AbortSignal; } /** Chromium testing API on navigator.modelContextTesting. */ export interface ModelContextTesting extends EventTarget { listTools(): ModelContextTestingToolInfo[]; executeTool(toolName: string, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise; getCrossDocumentScriptToolResult(): Promise; ontoolchange: ((this: ModelContextTesting, ev: Event) => unknown) | null; /** @deprecated Use `addEventListener('toolchange', ...)` instead. */ registerToolsChangedCallback?(callback: () => void): void; } /** Tool identity accepted by compatibility unregister flows. */ export interface ModelContextToolReference { name: string; } export interface ModelContextRegisterToolOptions { signal?: AbortSignal; exposedTo?: string[]; } /** The standard document.modelContext surface (the members the polyfill provides). */ export interface ModelContext extends EventTarget { registerTool(tool: ToolDescriptor, options?: ModelContextRegisterToolOptions): void | Promise; getTools(): Promise; executeTool(tool: ModelContextToolInfo, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise; } declare global { interface Navigator { /** @deprecated Legacy alias — `document.modelContext` is the canonical surface. */ modelContext?: ModelContext; /** Chromium testing API location; the polyfill's testing shim installs here. */ modelContextTesting?: ModelContextTesting; } } export type StandardInputValidatorSchema = StandardSchemaV1, Record>; export interface StandardJSONSchemaV1 { readonly '~standard': { readonly version: 1; readonly vendor: string; readonly types?: { readonly input: Input; readonly output: Output; } | undefined; readonly jsonSchema: { readonly input: (options: { readonly target: 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | ({} & string); readonly libraryOptions?: Record | undefined; }) => Record; readonly output: (options: { readonly target: 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | ({} & string); readonly libraryOptions?: Record | undefined; }) => Record; }; }; } export type StandardInputJsonSchema = StandardJSONSchemaV1, Record>; export type ToolInputSchema = InputSchema | StandardInputValidatorSchema | StandardInputJsonSchema; export type ToolOutputSchema = InputSchema | StandardInputJsonSchema; type StandardValidationResult = Awaited>; type StandardValidationIssue = NonNullable[number]; /** * The `document.modelContext` implementation that was replaced at install time * (a native browser implementation or a foreign polyfill), if any. Retained for * diagnostics and possible future forwarding into the browser's own registry. */ export declare function getReplacedModelContext(): ModelContext | undefined; export interface WebMCPPolyfillInitOptions { /** * Controls whether the polyfill auto-initializes when loaded. * Set to false to prevent auto-initialization; then call initializeWebMCPPolyfill() manually. * @default true */ autoInitialize?: boolean; /** * Controls installation of navigator.modelContextTesting when this polyfill provides modelContext. * - true or 'if-missing' (default): install only when modelContextTesting is missing. * - 'always': install even when modelContextTesting already exists. * - false: do not install. * @default 'if-missing' */ installTestingShim?: boolean | 'always' | 'if-missing'; /** * When this polyfill takes over a NATIVE browser WebMCP surface, integrate * with that displaced native registry so native-registry consumers — Chrome's * DevTools WebMCP panel and any built-in browser agent that enumerates the * native store rather than reading the JS `document.modelContext` property — * can see the tools AND the calls made to them. Without this they see an empty * registry, because our takeover routes all `registerTool` calls into our own * surface. Two things happen when it's enabled: * * 1. Every registered tool is mirrored into the native registry as a discovery * replica (the panel lists it). The native replica drops annotations * (native has no field for them). * 2. Real (non-testing) executions are routed THROUGH native (the panel logs * each call). Our surface stays the front door and validation authority: * args are validated on our side FIRST (bad input never reaches native, * keeping our input-error messages). The tool runs exactly once, inside * native's execute path; native shapes the error the calling script sees * (it substitutes a generic message — thrown-error detail reaches the * DevTools panel, not the caller). Native execution failure is surfaced with * no local retry. * * The JS surface this polyfill installs stays the PRIMARY, annotation- * preserving surface. No-op (execution stays fully local, keeping our error * formatting) when there is no native surface, when a foreign polyfill * occupied the slot, or when the native surface lacks `registerTool`. * @default true */ mirrorToNativeRegistry?: boolean; /** * Deprecated no-op kept for backward compatibility with previous wrappers. */ disableIframeTransportByDefault?: boolean; } export declare function isPlainObject(value: unknown): value is Record; export declare function validateArgsWithSchema(args: Record, schema: InputSchema): StandardValidationIssue | null; export declare function initializeWebMCPPolyfill(options?: WebMCPPolyfillInitOptions): void; export declare function cleanupWebMCPPolyfill(): void; export { initializeWebMCPPolyfill as initializeWebModelContextPolyfill }; declare global { interface Window { __webMCPPolyfillOptions?: WebMCPPolyfillInitOptions; } } //# sourceMappingURL=index.d.ts.map