@mcp-b/webmcp-types 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,303 +1,91 @@
1
- import type { InputSchema, ToolResponse } from './common.js';
1
+ import type { InputSchema, WebMcpToolInput } from './common.js';
2
2
  import type { JsonSchemaForInference } from './json-schema.js';
3
- import type { ToolDescriptor, ToolDescriptorFromSchema, ToolListItem, ToolRawResult } from './tool.js';
4
- /**
5
- * Tool info returned by ModelContextTesting.listTools().
6
- */
7
- export interface ModelContextTestingToolInfo {
8
- name: string;
9
- description: string;
10
- inputSchema?: string;
11
- }
12
- /**
13
- * Tool info returned by Chromium's producer-facing ModelContext.getTools().
14
- */
15
- export interface ModelContextToolInfo extends ModelContextTestingToolInfo {
16
- title: string;
17
- origin: string;
18
- window: Window;
19
- }
20
- /**
21
- * Options supported by ModelContextTesting.executeTool().
22
- */
23
- export interface ModelContextTestingExecuteToolOptions {
24
- signal?: AbortSignal;
3
+ import type { ModelContextTool, ModelContextToolFromSchema, ToolDescriptor, ToolDescriptorFromSchema, ToolListItem, WebMcpToolAnnotations } from './tool.js';
4
+ /** Options for tools exposed by descendant documents. */
5
+ export interface ModelContextGetToolOptions {
6
+ fromOrigins?: string[];
25
7
  }
26
- /**
27
- * Chromium testing API on navigator.modelContextTesting.
28
- *
29
- * The native runtime extends EventTarget and fires `toolchange` events.
30
- */
31
- export interface ModelContextTesting extends EventTarget {
32
- listTools(): ModelContextTestingToolInfo[];
33
- executeTool(toolName: string, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise<string | null>;
34
- getCrossDocumentScriptToolResult?(): Promise<string>;
35
- ontoolchange: ((this: ModelContextTesting, ev: Event) => unknown) | null;
36
- /**
37
- * @deprecated Use `addEventListener('toolchange', ...)` instead.
38
- */
39
- registerToolsChangedCallback?(callback: () => void): void;
40
- }
41
- /**
42
- * Polyfill-only testing extensions layered on top of ModelContextTesting.
43
- */
44
- export interface ModelContextTestingPolyfillExtensions {
45
- /**
46
- * Registers a callback invoked when the tool list changes.
47
- * @deprecated Use `addEventListener('toolchange', ...)` on native runtimes.
48
- * Kept for polyfill backward compatibility.
49
- */
50
- registerToolsChangedCallback(callback: () => void): void;
51
- getToolCalls(): Array<{
52
- toolName: string;
53
- arguments: Record<string, unknown>;
54
- timestamp: number;
55
- }>;
56
- clearToolCalls(): void;
57
- setMockToolResponse(toolName: string, response: ToolResponse): void;
58
- clearMockToolResponse(toolName: string): void;
59
- clearAllMockToolResponses(): void;
60
- getRegisteredTools(): ReturnType<ModelContextExtensions['listTools']>;
61
- reset(): void;
62
- }
63
- /**
64
- * Any supported tool descriptor.
65
- *
66
- * Uses `never` for args so descriptors with stricter argument objects remain assignable.
67
- */
68
- export type AnyToolDescriptor = ToolDescriptor<never, unknown, string>;
69
- /**
70
- * Infers argument shape from a tool descriptor.
71
- */
72
- export type InferToolArgs<TTool> = TTool extends ToolDescriptor<infer TArgs, infer _TResult, infer _TName> ? TArgs : never;
73
- /**
74
- * Infers result shape from a tool descriptor.
75
- */
76
- export type InferToolResult<TTool> = TTool extends ToolDescriptor<infer _TArgs, infer TResult, infer _TName> ? TResult : never;
77
- /**
78
- * Union of tool names from a tuple/array of descriptors.
79
- */
80
- export type ToolName<TTools extends readonly {
81
- name: string;
82
- }[]> = TTools[number]['name'];
83
- /**
84
- * Extracts a tool descriptor by name from a tuple/array.
85
- */
86
- export type ToolByName<TTools extends readonly {
8
+ /** Tool metadata returned by `document.modelContext.getTools()`. */
9
+ export interface RegisteredTool {
87
10
  name: string;
88
- }[], TName extends ToolName<TTools>> = Extract<TTools[number], {
89
- name: TName;
90
- }>;
91
- /**
92
- * Tool argument type by tool name from a tuple/array.
93
- */
94
- export type ToolArgsByName<TTools extends readonly {
95
- name: string;
96
- }[], TName extends ToolName<TTools>> = InferToolArgs<ToolByName<TTools, TName>>;
97
- /**
98
- * Tool result type by tool name from a tuple/array.
99
- */
100
- export type ToolResultByName<TTools extends readonly {
101
- name: string;
102
- }[], TName extends ToolName<TTools>> = InferToolResult<ToolByName<TTools, TName>>;
103
- /**
104
- * Typed parameters for MCP-B compatibility `callTool`.
105
- *
106
- * When a tool has no args (`Record<string, never>`), `arguments` becomes optional.
107
- */
108
- export type ToolCallParams<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, never>> = {
109
- name: TName;
110
- } & (TArgs extends Record<string, never> ? {
111
- arguments?: TArgs;
112
- } : {
113
- arguments: TArgs;
114
- });
115
- /**
116
- * Event dispatched when a tool is called.
117
- */
118
- export interface ToolCallEvent extends Event {
119
11
  /**
120
- * Tool name being invoked.
12
+ * Present on every tool Chrome and `@mcp-b/webmcp-polyfill` return today --
13
+ * the spec defaults it to the empty string when a tool registers no title.
14
+ * Kept optional deliberately: webmcp#224 proposes dropping that default and
15
+ * omitting the member instead. Read it as `tool.title || tool.name`: today the
16
+ * spec default makes it an empty string, which `??` does not fall through.
121
17
  */
122
- name: string;
18
+ title?: string;
19
+ description: string;
123
20
  /**
124
- * Tool arguments supplied by the caller.
21
+ * A JSON Schema object since webmcp#241, rolling out from Chrome 154.0.8013
22
+ * (cross-document tools first). Chrome 149-153 -- most of the Origin Trial
23
+ * population -- and 154's same-document tools still return the serialized
24
+ * JSON string the change replaced. Consumers that support both generations
25
+ * must branch on `typeof` and guard the parse of the string arm.
125
26
  */
126
- arguments: Record<string, unknown>;
27
+ inputSchema?: InputSchema | string;
28
+ window: Window;
29
+ origin: string;
127
30
  /**
128
- * Intercepts execution with a custom tool response.
31
+ * Absent when the tool registered no annotations -- both the spec and the
32
+ * polyfill omit the member rather than emitting an empty object. Each hint
33
+ * inside it is always populated, but the object itself is not guaranteed.
129
34
  */
130
- respondWith: (response: ToolResponse) => void;
35
+ annotations?: WebMcpToolAnnotations;
131
36
  }
132
- /**
133
- * Tool identity accepted by compatibility unregister flows.
134
- *
135
- * Current Chromium exposes string-name unregistration.
136
- * MCP-B compatibility runtimes may also accept the originally registered tool object.
137
- */
138
- export interface ModelContextToolReference {
37
+ export interface ChromeModelContextExecuteToolOptions {
38
+ signal?: AbortSignal;
39
+ }
40
+ /** Experimental Chromium methods; feature-detect them before use. */
41
+ export interface ChromeModelContextExtensions {
42
+ executeTool?(tool: RegisteredTool, inputArguments: string, options?: ChromeModelContextExecuteToolOptions): Promise<string | null>;
43
+ }
44
+ /** @deprecated Metadata returned by `navigator.modelContextTesting`. */
45
+ export interface ModelContextTestingToolInfo {
139
46
  name: string;
47
+ description: string;
48
+ inputSchema?: string;
140
49
  }
141
- /**
142
- * Non-standard compatibility handle returned by some runtimes after registerTool().
143
- *
144
- * @deprecated Use `options.signal` on `registerTool(tool, options)`. Will be removed in the next major.
145
- */
146
- export interface ModelContextToolRegistrationHandle {
147
- unregister(): void;
50
+ /** @deprecated Compatibility surface for Chromium's removed testing API. */
51
+ export interface ModelContextTesting extends EventTarget {
52
+ listTools(): ModelContextTestingToolInfo[];
53
+ executeTool(toolName: string, inputArgsJson: string, options?: ChromeModelContextExecuteToolOptions): Promise<string | null>;
54
+ ontoolchange: ((this: ModelContextTesting, event: Event) => unknown) | null;
148
55
  }
149
- /**
150
- * @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-modelcontextregistertooloptions}
151
- */
56
+ /** Options accepted by `ModelContext.registerTool()`. */
152
57
  export interface ModelContextRegisterToolOptions {
153
- /**
154
- * An `AbortSignal` whose abortion unregisters the tool. A pre-aborted signal short-circuits registration.
155
- */
156
58
  signal?: AbortSignal;
157
- /**
158
- * Origins that can observe this tool from other documents in the same tree.
159
- */
160
59
  exposedTo?: string[];
161
60
  }
61
+ type WidenedSchema<TSchema extends InputSchema> = string extends TSchema['type'] ? unknown : never;
162
62
  /**
163
- * Strict WebMCP core interface on document.modelContext.
63
+ * Standard `document.modelContext` API.
64
+ * @see https://webmachinelearning.github.io/webmcp/#modelcontext
164
65
  */
165
- export interface ModelContextCore {
166
- /**
167
- * Registers a dynamic tool with JSON Schema-driven inference.
168
- *
169
- * `execute(args)` is inferred from `inputSchema`, and when a literal object
170
- * `outputSchema` is provided, `execute(...).structuredContent` is inferred too.
171
- */
172
- registerTool<TInputSchema extends JsonSchemaForInference, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>, options?: ModelContextRegisterToolOptions): Promise<void>;
173
- /**
174
- * Registers a dynamic tool with explicitly typed args/result.
175
- */
176
- registerTool<TInputSchema extends InputSchema, TArgs extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(tool: ToolDescriptor<TArgs, ToolRawResult, TName> & {
66
+ export interface ModelContext extends EventTarget {
67
+ registerTool<const TInputSchema extends JsonSchemaForInference, TResult = unknown, TName extends string = string>(tool: ModelContextToolFromSchema<TInputSchema, TResult, TName>, options?: ModelContextRegisterToolOptions): Promise<void>;
68
+ registerTool<TInputSchema extends InputSchema, TArgs extends WebMcpToolInput = WebMcpToolInput, TResult = unknown, TName extends string = string>(tool: ModelContextTool<TArgs, TResult, TName> & {
177
69
  inputSchema: TInputSchema;
178
- } & (TInputSchema extends InputSchema ? string extends TInputSchema['type'] ? unknown : never : unknown), options?: ModelContextRegisterToolOptions): Promise<void>;
179
- /**
180
- * Registers a dynamic tool without an explicit inputSchema.
181
- * Runtime defaults this to an empty object schema.
182
- */
183
- registerTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(tool: Omit<ToolDescriptor<TArgs, ToolRawResult, TName>, 'inputSchema'> & {
70
+ } & WidenedSchema<TInputSchema>, options?: ModelContextRegisterToolOptions): Promise<void>;
71
+ registerTool<TArgs extends WebMcpToolInput = Record<string, unknown>, TResult = unknown, TName extends string = string>(tool: Omit<ModelContextTool<TArgs, TResult, TName>, 'inputSchema'> & {
184
72
  inputSchema?: undefined;
185
73
  }, options?: ModelContextRegisterToolOptions): Promise<void>;
186
- /**
187
- * Lists currently registered producer tools using the native Chromium preview
188
- * shape. Current Chromium returns JSON-stringified schemas here, matching
189
- * ModelContextTesting.listTools().
190
- */
191
- getTools(): Promise<ModelContextToolInfo[]>;
192
- /**
193
- * Executes a registered tool object returned from getTools().
194
- *
195
- * This mirrors Chromium's current producer-facing preview API. The testing API
196
- * still executes by `(toolName, inputArgsJson)`.
197
- */
198
- executeTool(tool: ModelContextToolInfo, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise<string | null>;
199
- /**
200
- * Handler invoked when the producer tool list changes.
201
- */
202
- ontoolchange: ((this: ModelContextCore, ev: Event) => unknown) | null;
203
- addEventListener(type: 'toolchange', listener: () => void, options?: boolean | AddEventListenerOptions): void;
204
- removeEventListener(type: 'toolchange', listener: () => void, options?: boolean | EventListenerOptions): void;
205
- dispatchEvent(event: Event): boolean;
74
+ getTools(options?: ModelContextGetToolOptions): Promise<RegisteredTool[]>;
75
+ ontoolchange: ((this: ModelContext, event: Event) => unknown) | null;
206
76
  }
207
- /**
208
- * MCPB extension surface layered on top of strict WebMCP core.
209
- * These members are intentionally non-standard.
210
- */
77
+ /** Non-standard methods exposed by MCP-B runtimes. */
211
78
  export interface ModelContextExtensions {
212
- /**
213
- * Unregisters a dynamic tool by name or tool reference.
214
- *
215
- * @deprecated Removed from the WebMCP spec on April 23, 2026. Use `registerTool(tool, { signal })`. Will be removed in the next major.
216
- */
217
- unregisterTool(nameOrTool: string | ModelContextToolReference): void;
218
- /**
219
- * Lists currently registered tools.
220
- */
79
+ registerTool<const TInputSchema extends JsonSchemaForInference, const TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>, options?: ModelContextRegisterToolOptions): Promise<void>;
80
+ registerTool<TInputSchema extends InputSchema, TArgs extends WebMcpToolInput = WebMcpToolInput, TName extends string = string>(tool: ToolDescriptor<TArgs, unknown, TName> & {
81
+ inputSchema: TInputSchema;
82
+ } & WidenedSchema<TInputSchema>, options?: ModelContextRegisterToolOptions): Promise<void>;
83
+ registerTool<TArgs extends WebMcpToolInput = Record<string, unknown>, TName extends string = string>(tool: Omit<ToolDescriptor<TArgs, unknown, TName>, 'inputSchema'> & {
84
+ inputSchema?: undefined;
85
+ }, options?: ModelContextRegisterToolOptions): Promise<void>;
221
86
  listTools(): ToolListItem[];
222
- /**
223
- * Executes a registered tool by name.
224
- *
225
- * @deprecated Prefer the WebMCP standard producer path: get a descriptor from
226
- * `getTools()` and pass it to `executeTool(tool, inputArgsJson)`. This method
227
- * remains as an MCP-B compatibility convenience.
228
- */
229
- callTool<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>>(params: {
230
- name: TName;
231
- arguments?: TArgs;
232
- }): Promise<ToolResponse>;
233
- /**
234
- * Adds a listener for tool invocation events.
235
- */
236
- addEventListener(type: 'toolcall', listener: (event: ToolCallEvent) => void | Promise<void>, options?: boolean | AddEventListenerOptions): void;
237
- /**
238
- * Adds a listener for tool list changes.
239
- */
240
- addEventListener(type: 'toolchange', listener: () => void, options?: boolean | AddEventListenerOptions): void;
241
- /**
242
- * @deprecated Use `'toolchange'` instead. Will be removed in the next major.
243
- */
244
- addEventListener(type: 'toolschanged', listener: () => void, options?: boolean | AddEventListenerOptions): void;
245
- /**
246
- * Removes a listener for tool invocation events.
247
- */
248
- removeEventListener(type: 'toolcall', listener: (event: ToolCallEvent) => void | Promise<void>, options?: boolean | EventListenerOptions): void;
249
- /**
250
- * Removes a listener for tool list changes.
251
- */
252
- removeEventListener(type: 'toolchange', listener: () => void, options?: boolean | EventListenerOptions): void;
253
- /**
254
- * @deprecated Use `'toolchange'` instead. Will be removed in the next major.
255
- */
256
- removeEventListener(type: 'toolschanged', listener: () => void, options?: boolean | EventListenerOptions): void;
257
- /**
258
- * Dispatches an event.
259
- */
260
- dispatchEvent(event: Event): boolean;
261
87
  }
262
- /**
263
- * Public document.modelContext type (strict core only).
264
- */
265
- export type ModelContext = ModelContextCore;
266
- /**
267
- * Full runtime shape including MCPB extensions.
268
- */
269
- export type ModelContextWithExtensions = ModelContextCore & ModelContextExtensions;
270
- /**
271
- * Strongly-typed `ModelContext` view derived from known tool descriptors.
272
- *
273
- * This is useful when your project has a static tool registry and you want
274
- * name-aware inference for MCP-B compatibility `callTool`.
275
- */
276
- export type TypedModelContext<TTools extends readonly {
277
- name: string;
278
- }[] = readonly ToolDescriptor[]> = ModelContextWithExtensions & {
279
- /**
280
- * Executes a known tool with name-aware argument and response inference.
281
- *
282
- * @deprecated Prefer the WebMCP standard producer path: get a descriptor from
283
- * `getTools()` and pass it to `executeTool(tool, inputArgsJson)`. This typed
284
- * convenience remains available for MCP-B compatibility.
285
- */
286
- callTool<TName extends ToolName<TTools>>(params: ToolCallParams<TName, ToolArgsByName<TTools, TName>>): Promise<ToolResultByName<TTools, TName>>;
287
- /**
288
- * Fallback call signature for unknown or dynamically-discovered tools.
289
- *
290
- * @deprecated Prefer the WebMCP standard producer path: get a descriptor from
291
- * `getTools()` and pass it to `executeTool(tool, inputArgsJson)`. This typed
292
- * convenience remains available for MCP-B compatibility.
293
- */
294
- callTool(params: {
295
- name: string;
296
- arguments?: Record<string, unknown>;
297
- }): Promise<ToolResponse>;
298
- /**
299
- * Lists tools with a narrowed name union.
300
- */
301
- listTools(): Array<ToolListItem<ToolName<TTools>>>;
302
- };
88
+ export type ChromeModelContext = ModelContext & ChromeModelContextExtensions;
89
+ export type ModelContextWithExtensions = Omit<ModelContext, 'registerTool'> & ModelContextExtensions;
90
+ export {};
303
91
  //# sourceMappingURL=model-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-context.d.ts","sourceRoot":"","sources":["../src/model-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACd,MAAM,WAAW,CAAC;AAMnB;;GAEG;AACH,MAAM,WAAW,2BAA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,KAAK,SAAS,eAAe,GAAG,eAAe,EAC/C,KAAK,SAAS,MAAM,GAAG,MAAM,EAE7B,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG;QAC5C,WAAW,EAAE,YAAY,CAAC;KAC3B,GAAG,aAAa,CAAC,YAAY,CAAC,EAC/B,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,YAAY,CACV,KAAK,SAAS,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvD,KAAK,SAAS,MAAM,GAAG,MAAM,EAE7B,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,aAAa,CAAC,GAAG;QACjE,WAAW,CAAC,EAAE,SAAS,CAAC;KACzB,EACD,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,SAAS,IAAI,YAAY,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,4BAA4B,CAAC;AAC7E,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,GACzE,sBAAsB,CAAC"}
package/dist/tool.d.ts CHANGED
@@ -1,174 +1,56 @@
1
- import type { CallToolResult, ElicitationParams, ElicitationResult, InputSchema } from './common.js';
1
+ import type { CallToolResult, InputSchema, WebMcpToolInput } from './common.js';
2
2
  import type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaForInference } from './json-schema.js';
3
+ import type { ToolAnnotations as McpToolAnnotations } from '@modelcontextprotocol/server';
3
4
  /**
4
- * Annotations providing hints about tool behavior.
5
- *
6
- * @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations}
7
- * @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
5
+ * Annotations in the WebMCP tool dictionary.
6
+ * @see https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations
8
7
  */
9
- export interface ToolAnnotations {
10
- /**
11
- * Optional display title.
12
- */
13
- title?: string;
14
- /**
15
- * Indicates the tool is read-only.
16
- */
17
- readOnlyHint?: boolean | 'true' | 'false';
18
- /**
19
- * Indicates the tool's output may include content from outside the page's trust boundary.
20
- */
21
- untrustedContentHint?: boolean | 'true' | 'false';
22
- /**
23
- * Indicates the tool may perform destructive actions.
24
- */
25
- destructiveHint?: boolean | 'true' | 'false';
26
- /**
27
- * Indicates the tool can be called repeatedly without changing outcome.
28
- */
29
- idempotentHint?: boolean | 'true' | 'false';
30
- /**
31
- * Indicates the tool may reach beyond local context (network, external systems, etc.).
32
- */
33
- openWorldHint?: boolean | 'true' | 'false';
8
+ export interface WebMcpToolAnnotations {
9
+ readOnlyHint?: boolean;
10
+ untrustedContentHint?: boolean;
34
11
  }
35
- /**
36
- * Raw tool result values accepted by execute handlers before runtime normalization.
37
- */
38
- export type ToolRawResult = unknown;
39
- /**
40
- * Tool execute return value accepted by WebMCP descriptor types.
41
- */
42
- export type ToolExecuteResult<TResult = ToolRawResult> = TResult extends CallToolResult ? TResult : CallToolResult | TResult;
43
- /**
44
- * Per-call client provided to tool handlers.
45
- */
46
- export interface ModelContextClient {
47
- /**
48
- * Requests user interaction during the current tool call.
49
- */
50
- requestUserInteraction(callback: () => Promise<unknown>): Promise<unknown>;
51
- }
52
- /**
53
- * MCPB extension context with additional elicitation helper.
54
- */
55
- export interface ToolExecutionContext extends ModelContextClient {
56
- /**
57
- * Requests user input for the current tool call.
58
- *
59
- * This function is bound to the active tool call and should only be used
60
- * during execution of that call.
61
- */
62
- elicitInput(params: ElicitationParams): Promise<ElicitationResult>;
63
- }
64
- /**
65
- * Value that may be returned synchronously or via Promise.
66
- */
12
+ /** MCP annotations plus WebMCP's untrusted-content hint. */
13
+ export type ToolAnnotations = McpToolAnnotations & WebMcpToolAnnotations;
67
14
  export type MaybePromise<T> = T | Promise<T>;
68
15
  /**
69
- * Tool descriptor for the Web Model Context API.
70
- *
71
- * Tools are functions that AI models can call to perform actions or retrieve
72
- * information. This interface uses JSON Schema for input/output typing.
73
- *
74
- * @template TArgs - Tool input arguments.
75
- * @template TResult - Tool execution raw result shape (or full CallToolResult).
76
- * @template TName - Tool name literal type.
77
- *
78
- * @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
16
+ * Tool dictionary accepted by the standard browser API.
17
+ * @see https://webmachinelearning.github.io/webmcp/#dictdef-modelcontexttool
79
18
  */
80
- export interface ToolDescriptor<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = ToolRawResult, TName extends string = string> {
81
- /**
82
- * Unique tool identifier.
83
- */
19
+ export interface ModelContextTool<TArgs extends WebMcpToolInput = Record<string, unknown>, TResult = unknown, TName extends string = string> {
84
20
  name: TName;
85
- /**
86
- * Optional user-facing label.
87
- */
88
21
  title?: string;
89
- /**
90
- * Human-readable summary of what the tool does.
91
- */
92
22
  description: string;
93
- /**
94
- * Schema describing accepted input arguments.
95
- */
96
- inputSchema?: InputSchema;
97
- /**
98
- * Optional schema describing output payload shape.
99
- */
23
+ inputSchema?: InputSchema | undefined;
24
+ annotations?: WebMcpToolAnnotations;
25
+ execute: (input: TArgs) => MaybePromise<TResult>;
26
+ }
27
+ /** Standard tool dictionary with input inferred from a JSON Schema literal. */
28
+ export type ModelContextToolFromSchema<TInputSchema extends InputSchema, TResult = unknown, TName extends string = string> = Omit<ModelContextTool<InferArgsFromInputSchema<TInputSchema>, TResult, TName>, 'inputSchema'> & {
29
+ inputSchema: TInputSchema;
30
+ };
31
+ /** MCP-B tool dictionary with output metadata. */
32
+ export type ToolDescriptor<TArgs extends WebMcpToolInput = Record<string, unknown>, TResult = unknown, TName extends string = string> = Omit<ModelContextTool<TArgs, TResult, TName>, 'annotations'> & {
100
33
  outputSchema?: JsonSchemaForInference;
101
- /**
102
- * Optional behavior hints for LLM planners.
103
- */
104
34
  annotations?: ToolAnnotations;
105
- /**
106
- * Tool execution function.
107
- */
108
- execute: (args: TArgs, client: ModelContextClient) => MaybePromise<ToolExecuteResult<TResult>>;
109
- }
110
- /**
111
- * Tool response shape inferred from an `outputSchema`.
112
- *
113
- * When a literal object output schema is provided, `structuredContent` is
114
- * narrowed to the inferred schema type for wrapped MCP responses.
115
- *
116
- * @template TOutputSchema - Optional literal JSON object schema.
117
- */
118
- export type ToolResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = TOutputSchema extends JsonSchemaForInference ? Omit<CallToolResult, 'structuredContent'> & {
35
+ };
36
+ /** MCP response with `structuredContent` inferred from an output schema. */
37
+ export type ToolResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = [TOutputSchema] extends [undefined] ? CallToolResult : TOutputSchema extends JsonSchemaForInference ? Omit<CallToolResult, 'structuredContent'> & {
119
38
  structuredContent: InferJsonSchema<TOutputSchema>;
120
- } : CallToolResult;
121
- /**
122
- * Execute result typing derived from an optional output schema.
123
- */
124
- export type ToolExecuteResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = TOutputSchema extends JsonSchemaForInference ? InferJsonSchema<TOutputSchema> | ToolResultFromOutputSchema<TOutputSchema> : ToolExecuteResult;
125
- /**
126
- * Tool descriptor whose `execute` args are inferred from a JSON Schema.
127
- *
128
- * For widened/non-literal schemas, arguments fall back to `Record<string, unknown>`.
129
- * When `outputSchema` is an inferable literal object schema, `structuredContent` is inferred.
130
- *
131
- * @template TInputSchema - JSON Schema for tool arguments.
132
- * @template TOutputSchema - Optional JSON schema for `structuredContent`.
133
- * @template TName - Tool name literal type.
134
- * @template TResult - Optional result type override constrained by inferred output schema.
135
- */
136
- export type ToolDescriptorFromSchema<TInputSchema extends {
137
- type?: string | readonly string[];
138
- }, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string> = Omit<ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ToolExecuteResultFromOutputSchema<TOutputSchema>, TName>, 'execute' | 'inputSchema' | 'outputSchema'> & {
39
+ } : never;
40
+ type ExecuteResult<TOutputSchema extends JsonSchemaForInference | undefined> = [
41
+ TOutputSchema
42
+ ] extends [undefined] ? unknown : TOutputSchema extends JsonSchemaForInference ? InferJsonSchema<TOutputSchema> | ToolResultFromOutputSchema<TOutputSchema> : never;
43
+ /** Tool dictionary with input and output inferred from JSON Schema literals. */
44
+ export type ToolDescriptorFromSchema<TInputSchema extends InputSchema, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string> = Omit<ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ExecuteResult<TOutputSchema>, TName>, 'inputSchema' | 'outputSchema'> & {
139
45
  inputSchema: TInputSchema;
140
- execute: (args: InferArgsFromInputSchema<TInputSchema>, client: ModelContextClient) => MaybePromise<ToolExecuteResultFromOutputSchema<TOutputSchema>>;
141
- } & (TOutputSchema extends JsonSchemaForInference ? {
142
- outputSchema: TOutputSchema;
143
- } : {
46
+ } & ([TOutputSchema] extends [undefined] ? {
144
47
  outputSchema?: undefined;
48
+ } : {
49
+ outputSchema: TOutputSchema;
145
50
  });
146
- /**
147
- * Tool information returned by listTools().
148
- * Provides metadata about a registered tool without exposing the execute function.
149
- *
150
- * @template TName - Tool name literal type.
151
- */
152
- export interface ToolListItem<TName extends string = string> {
153
- /**
154
- * Unique tool identifier.
155
- */
156
- name: TName;
157
- /**
158
- * Human-readable summary of what the tool does.
159
- */
160
- description: string;
161
- /**
162
- * JSON Schema describing accepted input arguments.
163
- */
51
+ /** Tool metadata returned by the MCP-B `listTools()` extension. */
52
+ export type ToolListItem<TName extends string = string> = Omit<ToolDescriptor<Record<string, unknown>, unknown, TName>, 'execute' | 'inputSchema'> & {
164
53
  inputSchema: InputSchema;
165
- /**
166
- * Optional JSON Schema describing output payload shape.
167
- */
168
- outputSchema?: JsonSchemaForInference;
169
- /**
170
- * Optional behavior hints for LLM planners.
171
- */
172
- annotations?: ToolAnnotations;
173
- }
54
+ };
55
+ export {};
174
56
  //# sourceMappingURL=t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