type MaybePromise = T | Promise; /** The JSON Schema subset used for tool arguments. Extra JSON Schema keys are allowed. */ interface JsonSchema { type?: string | readonly string[]; description?: string; properties?: Readonly>; required?: readonly string[]; items?: JsonSchema | readonly JsonSchema[]; enum?: readonly unknown[]; const?: unknown; minimum?: number; maximum?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; minLength?: number; maxLength?: number; minItems?: number; maxItems?: number; pattern?: string; format?: string; additionalProperties?: boolean | JsonSchema; [keyword: string]: unknown; } interface ToolAnnotations { /** The tool does not modify application or external state. */ readOnlyHint?: boolean; /** The tool may return user-generated or otherwise untrusted content. */ untrustedContentHint?: boolean; /** The tool has significant real-world or non-reversible effects. */ consequentialHint?: boolean; } interface ToolContext { signal: AbortSignal; invocationId: string; /** Adapter-defined origin such as `agent`, `voice`, `accessibility`, or `automation`. */ source: string; /** Adapter metadata is context, not an authenticated identity. */ metadata?: Readonly>; /** Original natural-language input when available. Kept for AgentTool compatibility. */ input: string; /** Chain step when available, otherwise 1. Kept for AgentTool compatibility. */ step: number; } interface Tool = Record, TResult = unknown> { /** WebMCP-compatible identifier: 1-128 letters, numbers, underscores, hyphens, or periods. */ name: string; /** Optional human-readable label for interfaces that display the tool. */ title?: string; /** Explain when to use the tool and what a successful call returns. */ description: string; inputSchema: JsonSchema; annotations?: ToolAnnotations; execute: (arguments_: TArguments, context: ToolContext) => MaybePromise; } interface ToolSchema { name: string; title?: string; description: string; inputSchema: JsonSchema; annotations?: ToolAnnotations; } interface ToolValidationIssue { instancePath: string; schemaPath: string; keyword: string; message?: string; params: Readonly>; } type ToolInvocationErrorCode = "unknown-tool" | "invalid-arguments" | "denied" | "confirmation-required" | "aborted" | "execution-failed"; interface ToolInvocationError { code: ToolInvocationErrorCode; message: string; validationIssues?: readonly ToolValidationIssue[]; } interface ToolInvocationEventBase { invocationId: string; tool: Tool; source: string; } type ToolInvocationEvent = (ToolInvocationEventBase & { phase: "started" | "succeeded"; }) | (ToolInvocationEventBase & { phase: "failed" | "denied" | "aborted"; error: ToolInvocationError; }); type ToolInvocationListener = (event: ToolInvocationEvent) => void; interface ToolInvocationRequest { tool: Tool; arguments: Record; context: ToolContext; } interface ToolPolicy { /** Authorization runs for every invocation. Return false to deny it. */ authorize?: (request: ToolInvocationRequest) => MaybePromise; /** Called for tools marked `consequentialHint`. Missing confirmation denies safely. */ confirm?: (request: ToolInvocationRequest) => MaybePromise; } interface ToolInvokeOptions { source?: string; signal?: AbortSignal; metadata?: Readonly>; input?: string; step?: number; /** Additional invocation-specific authorization, after the registry policy. */ authorize?: (request: ToolInvocationRequest) => MaybePromise; /** Observe this invocation without changing its result. Arguments and return values are omitted. */ onInvocation?: ToolInvocationListener; } type ToolInvocationResult = { ok: true; tool: Tool; value: TResult; invocationId: string; } | { ok: false; tool?: Tool; error: ToolInvocationError; invocationId: string; }; interface ToolResolver { getSnapshot(): readonly Tool[]; getTool(name: string): Tool | undefined; getPolicy?(): ToolPolicy | undefined; } interface ToolRegistration { update(tools: readonly Tool[]): void; dispose(): void; } interface ToolPolicyRegistration { update(policy: ToolPolicy): void; dispose(): void; } interface ToolRegistryOptions { tools?: readonly Tool[]; policy?: ToolPolicy; } export type { JsonSchema as J, MaybePromise as M, Tool as T, ToolInvokeOptions as a, ToolInvocationResult as b, ToolPolicy as c, ToolInvocationListener as d, ToolAnnotations as e, ToolContext as f, ToolInvocationError as g, ToolInvocationErrorCode as h, ToolInvocationEvent as i, ToolInvocationRequest as j, ToolPolicyRegistration as k, ToolRegistration as l, ToolRegistryOptions as m, ToolResolver as n, ToolSchema as o, ToolValidationIssue as p };