@mcp-b/webmcp-types 2.3.2 → 3.0.0-beta.20260702171253
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.
- package/README.md +10 -7
- package/dist/common.d.ts +1 -1
- package/dist/common.d.ts.map +1 -1
- package/dist/index.d.ts +20 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/model-context.d.ts +47 -39
- package/dist/model-context.d.ts.map +1 -1
- package/dist/tool.d.ts +10 -5
- package/dist/tool.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/common.ts +1 -1
- package/src/index.ts +21 -5
- package/src/model-context.ts +54 -49
- package/src/tool.ts +16 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mcp-b/webmcp-types
|
|
2
2
|
|
|
3
|
-
Strict TypeScript type definitions for the WebMCP core API (`
|
|
3
|
+
Strict TypeScript type definitions for the WebMCP core API (`document.modelContext`).
|
|
4
4
|
|
|
5
5
|
Zero runtime. Zero side effects. Just `.d.ts` types.
|
|
6
6
|
|
|
@@ -15,7 +15,8 @@ This package is the type-safety source of truth for WebMCP.
|
|
|
15
15
|
|
|
16
16
|
## Why This Package
|
|
17
17
|
|
|
18
|
-
- Global `
|
|
18
|
+
- Global `Document` augmentation for `document.modelContext`
|
|
19
|
+
- Deprecated global `Navigator` augmentation for backward-compatible `navigator.modelContext`
|
|
19
20
|
- Strongly typed tool descriptors and tool responses
|
|
20
21
|
- Literal JSON Schema inference for tool args and `structuredContent`
|
|
21
22
|
- Name-aware helper types for typed tool registries
|
|
@@ -90,7 +91,7 @@ const outputSchema = {
|
|
|
90
91
|
additionalProperties: false,
|
|
91
92
|
} as const satisfies JsonSchemaForInference;
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
document.modelContext.registerTool({
|
|
94
95
|
name: 'search',
|
|
95
96
|
description: 'Search indexed docs',
|
|
96
97
|
inputSchema,
|
|
@@ -188,14 +189,15 @@ await modelContext.callTool({ name: 'ping' });
|
|
|
188
189
|
|
|
189
190
|
## Core and Extension Surfaces
|
|
190
191
|
|
|
191
|
-
`
|
|
192
|
+
`Document['modelContext']` is typed as strict core WebMCP methods only.
|
|
193
|
+
`Navigator['modelContext']` remains typed as a deprecated backward-compatible alias.
|
|
192
194
|
|
|
193
195
|
Extension methods are available via `ModelContextExtensions` and `ModelContextWithExtensions`:
|
|
194
196
|
|
|
195
197
|
```ts
|
|
196
198
|
import type { ModelContextExtensions } from '@mcp-b/webmcp-types';
|
|
197
199
|
|
|
198
|
-
const modelContext =
|
|
200
|
+
const modelContext = document.modelContext as Document['modelContext'] & ModelContextExtensions;
|
|
199
201
|
const tools = modelContext.listTools();
|
|
200
202
|
const result = await modelContext.callTool({
|
|
201
203
|
name: 'search',
|
|
@@ -210,7 +212,7 @@ void result;
|
|
|
210
212
|
|
|
211
213
|
| Export | Purpose |
|
|
212
214
|
| ------------------------------------ | ------------------------------------------------------------ |
|
|
213
|
-
| `ModelContext` | Strict core `
|
|
215
|
+
| `ModelContext` | Strict core `document.modelContext` type |
|
|
214
216
|
| `ToolDescriptor` | Explicitly typed tool descriptor |
|
|
215
217
|
| `ToolDescriptorFromSchema` | Schema-driven descriptor with inferred args/result |
|
|
216
218
|
| `JsonSchemaForInference` | Supported JSON Schema subset for inference |
|
|
@@ -225,7 +227,8 @@ void result;
|
|
|
225
227
|
|
|
226
228
|
- This package does not install any runtime behavior.
|
|
227
229
|
- Runtime validation/execution behavior depends on your WebMCP runtime package.
|
|
228
|
-
- `
|
|
230
|
+
- Prefer `document.modelContext` for new code. `navigator.modelContext` is retained as a deprecated backward-compatible alias during the WebMCP migration.
|
|
231
|
+
- `provideContext()` and `clearContext()` were removed from the upstream WebMCP spec on March 5, 2026 and are intentionally not typed.
|
|
229
232
|
- `unregisterTool(name)` is `@deprecated`. The April 23, 2026 WebMCP draft removed it from the spec in favor of an `AbortSignal` passed via `registerTool(tool, { signal })`. The type is retained for compatibility with older native previews and existing MCP-B wrappers; it will be removed in the next major version.
|
|
230
233
|
- `registerTool(tool, options?)` accepts a `ModelContextRegisterToolOptions` dictionary with an optional `signal: AbortSignal`. Aborting the signal unregisters the tool.
|
|
231
234
|
- `ToolAnnotations.untrustedContentHint` was added to the spec on April 23, 2026 to flag tools whose output may include externally-sourced content.
|
package/dist/common.d.ts
CHANGED
package/dist/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,EAAE,CAAC;AAEjE;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAE7B;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAMD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AAC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;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IAExC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC,CAAC;CAChE;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import type { ModelContext, ModelContextTesting } from './model-context.js';
|
|
2
2
|
export type { AudioContent, BlobResourceContents, CallToolResult, ContentBlock, ElicitationFormParams, ElicitationParams, ElicitationResult, ElicitationUrlParams, EmbeddedResource, ImageContent, InputSchema, InputSchemaProperty, JsonObject, JsonPrimitive, JsonValue, LooseContentBlock, RegistrationHandle, ResourceContents, ResourceLink, TextContent, TextResourceContents, ToolResponse, } from './common.js';
|
|
3
3
|
export type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaArray, JsonSchemaBoolean, JsonSchemaEnumValue, JsonSchemaForInference, JsonSchemaMultiType, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaString, JsonSchemaType, JsonSchemaTypeArray, } from './json-schema.js';
|
|
4
|
-
export type { AnyToolDescriptor, InferToolArgs, InferToolResult, ModelContext, ModelContextCore, ModelContextExtensions,
|
|
4
|
+
export type { AnyToolDescriptor, InferToolArgs, InferToolResult, ModelContext, ModelContextCore, ModelContextExtensions, ModelContextRegisterToolOptions, ModelContextTesting, ModelContextTestingExecuteToolOptions, ModelContextTestingPolyfillExtensions, ModelContextTestingToolInfo, ModelContextToolInfo, ModelContextToolReference, ModelContextToolRegistrationHandle, ModelContextWithExtensions, ToolArgsByName, ToolByName, ToolCallEvent, ToolCallParams, ToolName, ToolResultByName, TypedModelContext, } from './model-context.js';
|
|
5
5
|
export type { MaybePromise, ModelContextClient, ToolAnnotations, ToolDescriptor, ToolDescriptorFromSchema, ToolExecuteResult, ToolExecutionContext, ToolListItem, ToolRawResult, ToolResultFromOutputSchema, } from './tool.js';
|
|
6
6
|
declare global {
|
|
7
|
+
interface Document {
|
|
8
|
+
/**
|
|
9
|
+
* Web Model Context API strict core surface.
|
|
10
|
+
*
|
|
11
|
+
* Per WebMCP spec PR webmachinelearning/webmcp#184, each Document owns its
|
|
12
|
+
* associated ModelContext. This is the canonical install location as of
|
|
13
|
+
* Chrome 150. Prefer `document.modelContext` for new code.
|
|
14
|
+
*/
|
|
15
|
+
readonly modelContext: ModelContext;
|
|
16
|
+
}
|
|
7
17
|
interface Navigator {
|
|
8
18
|
/**
|
|
9
19
|
* Web Model Context API strict core surface.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated The modelContext getter moved from Navigator to Document in
|
|
22
|
+
* Chrome 150 (see webmachinelearning/webmcp#173 / PR #184). Use
|
|
23
|
+
* `document.modelContext` instead. `navigator.modelContext` is kept as a
|
|
24
|
+
* backward-compatible alias and will be removed in a future Chrome release.
|
|
10
25
|
*/
|
|
11
|
-
modelContext: ModelContext;
|
|
26
|
+
readonly modelContext: ModelContext;
|
|
12
27
|
/**
|
|
13
28
|
* Web Model Context testing API surface (Chromium early preview).
|
|
14
|
-
* @deprecated
|
|
15
|
-
*
|
|
29
|
+
* @deprecated Chromium still exposes this API for testing flows. Producer
|
|
30
|
+
* discovery/execution should prefer document.modelContext.getTools() and
|
|
31
|
+
* document.modelContext.executeTool(...).
|
|
16
32
|
*/
|
|
17
33
|
modelContextTesting?: ModelContextTesting;
|
|
18
34
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG5E,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG5E,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,+BAA+B,EAC/B,mBAAmB,EACnB,qCAAqC,EACrC,qCAAqC,EACrC,2BAA2B,EAC3B,oBAAoB,EACpB,yBAAyB,EACzB,kCAAkC,EAClC,0BAA0B,EAC1B,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,0BAA0B,GAC3B,MAAM,WAAW,CAAC;AAMnB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,QAAQ;QAChB;;;;;;WAMG;QACH,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;KACrC;IAED,UAAU,SAAS;QACjB;;;;;;;WAOG;QACH,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;QAEpC;;;;;WAKG;QACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;KAC3C;CACF"}
|
package/dist/model-context.d.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import type { InputSchema, ToolResponse } from './common.js';
|
|
2
2
|
import type { JsonSchemaForInference } from './json-schema.js';
|
|
3
3
|
import type { ToolDescriptor, ToolDescriptorFromSchema, ToolListItem, ToolRawResult } from './tool.js';
|
|
4
|
-
/**
|
|
5
|
-
* Context provided to models via provideContext().
|
|
6
|
-
*/
|
|
7
|
-
export interface ModelContextInput<TTools extends readonly ToolDescriptor[] = ToolDescriptor[]> {
|
|
8
|
-
/**
|
|
9
|
-
* Base tool descriptors to expose.
|
|
10
|
-
*/
|
|
11
|
-
tools?: TTools;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Public options accepted by provideContext().
|
|
15
|
-
*/
|
|
16
|
-
export type ModelContextOptions = ModelContextInput;
|
|
17
4
|
/**
|
|
18
5
|
* Tool info returned by ModelContextTesting.listTools().
|
|
19
6
|
*/
|
|
@@ -22,6 +9,14 @@ export interface ModelContextTestingToolInfo {
|
|
|
22
9
|
description: string;
|
|
23
10
|
inputSchema?: string;
|
|
24
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
|
+
}
|
|
25
20
|
/**
|
|
26
21
|
* Options supported by ModelContextTesting.executeTool().
|
|
27
22
|
*/
|
|
@@ -36,7 +31,7 @@ export interface ModelContextTestingExecuteToolOptions {
|
|
|
36
31
|
export interface ModelContextTesting extends EventTarget {
|
|
37
32
|
listTools(): ModelContextTestingToolInfo[];
|
|
38
33
|
executeTool(toolName: string, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise<string | null>;
|
|
39
|
-
getCrossDocumentScriptToolResult(): Promise<string>;
|
|
34
|
+
getCrossDocumentScriptToolResult?(): Promise<string>;
|
|
40
35
|
ontoolchange: ((this: ModelContextTesting, ev: Event) => unknown) | null;
|
|
41
36
|
/**
|
|
42
37
|
* @deprecated Use `addEventListener('toolchange', ...)` instead.
|
|
@@ -106,7 +101,7 @@ export type ToolResultByName<TTools extends readonly {
|
|
|
106
101
|
name: string;
|
|
107
102
|
}[], TName extends ToolName<TTools>> = InferToolResult<ToolByName<TTools, TName>>;
|
|
108
103
|
/**
|
|
109
|
-
* Typed parameters for `callTool`.
|
|
104
|
+
* Typed parameters for MCP-B compatibility `callTool`.
|
|
110
105
|
*
|
|
111
106
|
* When a tool has no args (`Record<string, never>`), `arguments` becomes optional.
|
|
112
107
|
*/
|
|
@@ -159,42 +154,48 @@ export interface ModelContextRegisterToolOptions {
|
|
|
159
154
|
* An `AbortSignal` whose abortion unregisters the tool. A pre-aborted signal short-circuits registration.
|
|
160
155
|
*/
|
|
161
156
|
signal?: AbortSignal;
|
|
157
|
+
/**
|
|
158
|
+
* Origins that can observe this tool from other documents in the same tree.
|
|
159
|
+
*/
|
|
160
|
+
exposedTo?: string[];
|
|
162
161
|
}
|
|
163
162
|
/**
|
|
164
|
-
* Strict WebMCP core interface on
|
|
163
|
+
* Strict WebMCP core interface on document.modelContext.
|
|
165
164
|
*/
|
|
166
165
|
export interface ModelContextCore {
|
|
167
|
-
/**
|
|
168
|
-
* Replaces base context with provided tools.
|
|
169
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
170
|
-
*/
|
|
171
|
-
provideContext(options?: ModelContextOptions): void;
|
|
172
166
|
/**
|
|
173
167
|
* Registers a dynamic tool with JSON Schema-driven inference.
|
|
174
168
|
*
|
|
175
169
|
* `execute(args)` is inferred from `inputSchema`, and when a literal object
|
|
176
170
|
* `outputSchema` is provided, `execute(...).structuredContent` is inferred too.
|
|
177
171
|
*/
|
|
178
|
-
registerTool<TInputSchema extends JsonSchemaForInference, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>, options?: ModelContextRegisterToolOptions): void
|
|
172
|
+
registerTool<TInputSchema extends JsonSchemaForInference, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
179
173
|
/**
|
|
180
174
|
* Registers a dynamic tool with explicitly typed args/result.
|
|
181
175
|
*/
|
|
182
176
|
registerTool<TInputSchema extends InputSchema, TArgs extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(tool: ToolDescriptor<TArgs, ToolRawResult, TName> & {
|
|
183
177
|
inputSchema: TInputSchema;
|
|
184
|
-
} & (TInputSchema extends InputSchema ? string extends TInputSchema['type'] ? unknown : never : unknown), options?: ModelContextRegisterToolOptions): void
|
|
178
|
+
} & (TInputSchema extends InputSchema ? string extends TInputSchema['type'] ? unknown : never : unknown), options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
185
179
|
/**
|
|
186
180
|
* Registers a dynamic tool without an explicit inputSchema.
|
|
187
181
|
* Runtime defaults this to an empty object schema.
|
|
188
182
|
*/
|
|
189
183
|
registerTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(tool: Omit<ToolDescriptor<TArgs, ToolRawResult, TName>, 'inputSchema'> & {
|
|
190
184
|
inputSchema?: undefined;
|
|
191
|
-
}, options?: ModelContextRegisterToolOptions): void
|
|
185
|
+
}, options?: ModelContextRegisterToolOptions): Promise<void>;
|
|
192
186
|
/**
|
|
193
187
|
* Lists currently registered producer tools using the native Chromium preview
|
|
194
188
|
* shape. Current Chromium returns JSON-stringified schemas here, matching
|
|
195
189
|
* ModelContextTesting.listTools().
|
|
196
190
|
*/
|
|
197
|
-
getTools():
|
|
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>;
|
|
198
199
|
/**
|
|
199
200
|
* Handler invoked when the producer tool list changes.
|
|
200
201
|
*/
|
|
@@ -202,29 +203,28 @@ export interface ModelContextCore {
|
|
|
202
203
|
addEventListener(type: 'toolchange', listener: () => void, options?: boolean | AddEventListenerOptions): void;
|
|
203
204
|
removeEventListener(type: 'toolchange', listener: () => void, options?: boolean | EventListenerOptions): void;
|
|
204
205
|
dispatchEvent(event: Event): boolean;
|
|
205
|
-
/**
|
|
206
|
-
* Unregisters a dynamic tool by name or tool reference.
|
|
207
|
-
*
|
|
208
|
-
* @deprecated Removed from the WebMCP spec on April 23, 2026. Use `registerTool(tool, { signal })`. Will be removed in the next major.
|
|
209
|
-
*/
|
|
210
|
-
unregisterTool(nameOrTool: string | ModelContextToolReference): void;
|
|
211
|
-
/**
|
|
212
|
-
* Clears all context (base + dynamic registrations).
|
|
213
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
214
|
-
*/
|
|
215
|
-
clearContext(): void;
|
|
216
206
|
}
|
|
217
207
|
/**
|
|
218
208
|
* MCPB extension surface layered on top of strict WebMCP core.
|
|
219
209
|
* These members are intentionally non-standard.
|
|
220
210
|
*/
|
|
221
211
|
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;
|
|
222
218
|
/**
|
|
223
219
|
* Lists currently registered tools.
|
|
224
220
|
*/
|
|
225
221
|
listTools(): ToolListItem[];
|
|
226
222
|
/**
|
|
227
|
-
* Executes a registered tool.
|
|
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
228
|
*/
|
|
229
229
|
callTool<TName extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>>(params: {
|
|
230
230
|
name: TName;
|
|
@@ -260,7 +260,7 @@ export interface ModelContextExtensions {
|
|
|
260
260
|
dispatchEvent(event: Event): boolean;
|
|
261
261
|
}
|
|
262
262
|
/**
|
|
263
|
-
* Public
|
|
263
|
+
* Public document.modelContext type (strict core only).
|
|
264
264
|
*/
|
|
265
265
|
export type ModelContext = ModelContextCore;
|
|
266
266
|
/**
|
|
@@ -271,17 +271,25 @@ export type ModelContextWithExtensions = ModelContextCore & ModelContextExtensio
|
|
|
271
271
|
* Strongly-typed `ModelContext` view derived from known tool descriptors.
|
|
272
272
|
*
|
|
273
273
|
* This is useful when your project has a static tool registry and you want
|
|
274
|
-
* name-aware inference for `callTool`.
|
|
274
|
+
* name-aware inference for MCP-B compatibility `callTool`.
|
|
275
275
|
*/
|
|
276
276
|
export type TypedModelContext<TTools extends readonly {
|
|
277
277
|
name: string;
|
|
278
278
|
}[] = readonly ToolDescriptor[]> = ModelContextWithExtensions & {
|
|
279
279
|
/**
|
|
280
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.
|
|
281
285
|
*/
|
|
282
286
|
callTool<TName extends ToolName<TTools>>(params: ToolCallParams<TName, ToolArgsByName<TTools, TName>>): Promise<ToolResultByName<TTools, TName>>;
|
|
283
287
|
/**
|
|
284
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.
|
|
285
293
|
*/
|
|
286
294
|
callTool(params: {
|
|
287
295
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-context.d.ts","sourceRoot":"","sources":["../src/model-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;IAER;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,gBAAgB,GAAG,sBAAsB,CAAC;AAMnF;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAC3B,MAAM,SAAS,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,SAAS,cAAc,EAAE,IACpE,0BAA0B,GAAG;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,EACrC,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAC3D,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAE5C;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE/F;;OAEG;IACH,SAAS,IAAI,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CACpD,CAAC"}
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CallToolResult, ElicitationParams, ElicitationResult, InputSchema } from './common.js';
|
|
2
|
-
import type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaForInference
|
|
2
|
+
import type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaForInference } from './json-schema.js';
|
|
3
3
|
/**
|
|
4
4
|
* Annotations providing hints about tool behavior.
|
|
5
5
|
*
|
|
@@ -82,6 +82,10 @@ export interface ToolDescriptor<TArgs extends Record<string, unknown> = Record<s
|
|
|
82
82
|
* Unique tool identifier.
|
|
83
83
|
*/
|
|
84
84
|
name: TName;
|
|
85
|
+
/**
|
|
86
|
+
* Optional user-facing label.
|
|
87
|
+
*/
|
|
88
|
+
title?: string;
|
|
85
89
|
/**
|
|
86
90
|
* Human-readable summary of what the tool does.
|
|
87
91
|
*/
|
|
@@ -111,13 +115,13 @@ export interface ToolDescriptor<TArgs extends Record<string, unknown> = Record<s
|
|
|
111
115
|
*
|
|
112
116
|
* @template TOutputSchema - Optional literal JSON object schema.
|
|
113
117
|
*/
|
|
114
|
-
export type ToolResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = TOutputSchema extends
|
|
115
|
-
structuredContent
|
|
118
|
+
export type ToolResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = TOutputSchema extends JsonSchemaForInference ? Omit<CallToolResult, 'structuredContent'> & {
|
|
119
|
+
structuredContent: InferJsonSchema<TOutputSchema>;
|
|
116
120
|
} : CallToolResult;
|
|
117
121
|
/**
|
|
118
122
|
* Execute result typing derived from an optional output schema.
|
|
119
123
|
*/
|
|
120
|
-
export type ToolExecuteResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = TOutputSchema extends
|
|
124
|
+
export type ToolExecuteResultFromOutputSchema<TOutputSchema extends JsonSchemaForInference | undefined = undefined> = TOutputSchema extends JsonSchemaForInference ? InferJsonSchema<TOutputSchema> | ToolResultFromOutputSchema<TOutputSchema> : ToolExecuteResult;
|
|
121
125
|
/**
|
|
122
126
|
* Tool descriptor whose `execute` args are inferred from a JSON Schema.
|
|
123
127
|
*
|
|
@@ -131,8 +135,9 @@ export type ToolExecuteResultFromOutputSchema<TOutputSchema extends JsonSchemaFo
|
|
|
131
135
|
*/
|
|
132
136
|
export type ToolDescriptorFromSchema<TInputSchema extends {
|
|
133
137
|
type?: string | readonly string[];
|
|
134
|
-
}, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string> = Omit<ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ToolExecuteResultFromOutputSchema<TOutputSchema>, TName>, 'inputSchema' | 'outputSchema'> & {
|
|
138
|
+
}, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string> = Omit<ToolDescriptor<InferArgsFromInputSchema<TInputSchema>, ToolExecuteResultFromOutputSchema<TOutputSchema>, TName>, 'execute' | 'inputSchema' | 'outputSchema'> & {
|
|
135
139
|
inputSchema: TInputSchema;
|
|
140
|
+
execute: (args: InferArgsFromInputSchema<TInputSchema>, client: ModelContextClient) => MaybePromise<ToolExecuteResultFromOutputSchema<TOutputSchema>>;
|
|
136
141
|
} & (TOutputSchema extends JsonSchemaForInference ? {
|
|
137
142
|
outputSchema: TOutputSchema;
|
|
138
143
|
} : {
|
package/dist/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,sBAAsB,
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAM1B;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,C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AE,kBAAkB,KACvB,YAAY,CAAC,iCAAiC,CAAC,aAAa,CAAC,CAAC,CAAC;CACrE,GAAG,CAAC,aAAa,SAAS,sBAAsB,GAC3C;IACE,YAAY,EAAE,aAAa,CAAC;CAC7B,GACD;IACE,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B,CAAC,CAAC;AAMT;;;;;GAKG;AACH,MAAM,WAAW,YAAY,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACzD;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC;IAEZ;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,sBAAsB,CAAC;IAEtC;;OAEG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/webmcp-types",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Strict TypeScript type definitions for the WebMCP core API (
|
|
3
|
+
"version": "3.0.0-beta.20260702171253",
|
|
4
|
+
"description": "Strict TypeScript type definitions for the WebMCP core API (document.modelContext)",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"document-modelcontext",
|
|
6
7
|
"model-context",
|
|
7
8
|
"navigator-modelcontext",
|
|
8
9
|
"types",
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
"web-standard",
|
|
11
12
|
"webmcp"
|
|
12
13
|
],
|
|
13
|
-
"homepage": "https://docs.mcp-b.ai/packages/webmcp-types",
|
|
14
|
+
"homepage": "https://docs.mcp-b.ai/packages/webmcp-types/reference",
|
|
14
15
|
"bugs": {
|
|
15
16
|
"url": "https://github.com/WebMCP-org/npm-packages/issues"
|
|
16
17
|
},
|
|
@@ -43,10 +44,10 @@
|
|
|
43
44
|
"registry": "https://registry.npmjs.org/"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@vitest/coverage-v8": "^4.1.
|
|
47
|
-
"playwright": "^1.
|
|
47
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
48
|
+
"playwright": "^1.60.0",
|
|
48
49
|
"typescript": "^5.8.3",
|
|
49
|
-
"vite-plus": "
|
|
50
|
+
"vite-plus": "^0.1.22",
|
|
50
51
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
package/src/common.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -48,13 +48,12 @@ export type {
|
|
|
48
48
|
ModelContext,
|
|
49
49
|
ModelContextCore,
|
|
50
50
|
ModelContextExtensions,
|
|
51
|
-
ModelContextInput,
|
|
52
|
-
ModelContextOptions,
|
|
53
51
|
ModelContextRegisterToolOptions,
|
|
54
52
|
ModelContextTesting,
|
|
55
53
|
ModelContextTestingExecuteToolOptions,
|
|
56
54
|
ModelContextTestingPolyfillExtensions,
|
|
57
55
|
ModelContextTestingToolInfo,
|
|
56
|
+
ModelContextToolInfo,
|
|
58
57
|
ModelContextToolReference,
|
|
59
58
|
ModelContextToolRegistrationHandle,
|
|
60
59
|
ModelContextWithExtensions,
|
|
@@ -84,16 +83,33 @@ export type {
|
|
|
84
83
|
// ============================================================================
|
|
85
84
|
|
|
86
85
|
declare global {
|
|
86
|
+
interface Document {
|
|
87
|
+
/**
|
|
88
|
+
* Web Model Context API strict core surface.
|
|
89
|
+
*
|
|
90
|
+
* Per WebMCP spec PR webmachinelearning/webmcp#184, each Document owns its
|
|
91
|
+
* associated ModelContext. This is the canonical install location as of
|
|
92
|
+
* Chrome 150. Prefer `document.modelContext` for new code.
|
|
93
|
+
*/
|
|
94
|
+
readonly modelContext: ModelContext;
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
interface Navigator {
|
|
88
98
|
/**
|
|
89
99
|
* Web Model Context API strict core surface.
|
|
100
|
+
*
|
|
101
|
+
* @deprecated The modelContext getter moved from Navigator to Document in
|
|
102
|
+
* Chrome 150 (see webmachinelearning/webmcp#173 / PR #184). Use
|
|
103
|
+
* `document.modelContext` instead. `navigator.modelContext` is kept as a
|
|
104
|
+
* backward-compatible alias and will be removed in a future Chrome release.
|
|
90
105
|
*/
|
|
91
|
-
modelContext: ModelContext;
|
|
106
|
+
readonly modelContext: ModelContext;
|
|
92
107
|
|
|
93
108
|
/**
|
|
94
109
|
* Web Model Context testing API surface (Chromium early preview).
|
|
95
|
-
* @deprecated
|
|
96
|
-
*
|
|
110
|
+
* @deprecated Chromium still exposes this API for testing flows. Producer
|
|
111
|
+
* discovery/execution should prefer document.modelContext.getTools() and
|
|
112
|
+
* document.modelContext.executeTool(...).
|
|
97
113
|
*/
|
|
98
114
|
modelContextTesting?: ModelContextTesting;
|
|
99
115
|
}
|
package/src/model-context.ts
CHANGED
|
@@ -7,25 +7,6 @@ import type {
|
|
|
7
7
|
ToolRawResult,
|
|
8
8
|
} from './tool.js';
|
|
9
9
|
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Model Context Input
|
|
12
|
-
// ============================================================================
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Context provided to models via provideContext().
|
|
16
|
-
*/
|
|
17
|
-
export interface ModelContextInput<TTools extends readonly ToolDescriptor[] = ToolDescriptor[]> {
|
|
18
|
-
/**
|
|
19
|
-
* Base tool descriptors to expose.
|
|
20
|
-
*/
|
|
21
|
-
tools?: TTools;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Public options accepted by provideContext().
|
|
26
|
-
*/
|
|
27
|
-
export type ModelContextOptions = ModelContextInput;
|
|
28
|
-
|
|
29
10
|
// ============================================================================
|
|
30
11
|
// Model Context Testing
|
|
31
12
|
// ============================================================================
|
|
@@ -39,6 +20,15 @@ export interface ModelContextTestingToolInfo {
|
|
|
39
20
|
inputSchema?: string;
|
|
40
21
|
}
|
|
41
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Tool info returned by Chromium's producer-facing ModelContext.getTools().
|
|
25
|
+
*/
|
|
26
|
+
export interface ModelContextToolInfo extends ModelContextTestingToolInfo {
|
|
27
|
+
title: string;
|
|
28
|
+
origin: string;
|
|
29
|
+
window: Window;
|
|
30
|
+
}
|
|
31
|
+
|
|
42
32
|
/**
|
|
43
33
|
* Options supported by ModelContextTesting.executeTool().
|
|
44
34
|
*/
|
|
@@ -58,7 +48,7 @@ export interface ModelContextTesting extends EventTarget {
|
|
|
58
48
|
inputArgsJson: string,
|
|
59
49
|
options?: ModelContextTestingExecuteToolOptions
|
|
60
50
|
): Promise<string | null>;
|
|
61
|
-
getCrossDocumentScriptToolResult(): Promise<string>;
|
|
51
|
+
getCrossDocumentScriptToolResult?(): Promise<string>;
|
|
62
52
|
ontoolchange: ((this: ModelContextTesting, ev: Event) => unknown) | null;
|
|
63
53
|
/**
|
|
64
54
|
* @deprecated Use `addEventListener('toolchange', ...)` instead.
|
|
@@ -142,7 +132,7 @@ export type ToolResultByName<
|
|
|
142
132
|
> = InferToolResult<ToolByName<TTools, TName>>;
|
|
143
133
|
|
|
144
134
|
/**
|
|
145
|
-
* Typed parameters for `callTool`.
|
|
135
|
+
* Typed parameters for MCP-B compatibility `callTool`.
|
|
146
136
|
*
|
|
147
137
|
* When a tool has no args (`Record<string, never>`), `arguments` becomes optional.
|
|
148
138
|
*/
|
|
@@ -204,6 +194,11 @@ export interface ModelContextRegisterToolOptions {
|
|
|
204
194
|
* An `AbortSignal` whose abortion unregisters the tool. A pre-aborted signal short-circuits registration.
|
|
205
195
|
*/
|
|
206
196
|
signal?: AbortSignal;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Origins that can observe this tool from other documents in the same tree.
|
|
200
|
+
*/
|
|
201
|
+
exposedTo?: string[];
|
|
207
202
|
}
|
|
208
203
|
|
|
209
204
|
// ============================================================================
|
|
@@ -211,17 +206,9 @@ export interface ModelContextRegisterToolOptions {
|
|
|
211
206
|
// ============================================================================
|
|
212
207
|
|
|
213
208
|
/**
|
|
214
|
-
* Strict WebMCP core interface on
|
|
209
|
+
* Strict WebMCP core interface on document.modelContext.
|
|
215
210
|
*/
|
|
216
211
|
export interface ModelContextCore {
|
|
217
|
-
// ==================== CONTEXT ====================
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Replaces base context with provided tools.
|
|
221
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
222
|
-
*/
|
|
223
|
-
provideContext(options?: ModelContextOptions): void;
|
|
224
|
-
|
|
225
212
|
// ==================== TOOLS ====================
|
|
226
213
|
|
|
227
214
|
/**
|
|
@@ -237,7 +224,7 @@ export interface ModelContextCore {
|
|
|
237
224
|
>(
|
|
238
225
|
tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>,
|
|
239
226
|
options?: ModelContextRegisterToolOptions
|
|
240
|
-
): void
|
|
227
|
+
): Promise<void>;
|
|
241
228
|
|
|
242
229
|
/**
|
|
243
230
|
* Registers a dynamic tool with explicitly typed args/result.
|
|
@@ -255,7 +242,7 @@ export interface ModelContextCore {
|
|
|
255
242
|
: never
|
|
256
243
|
: unknown),
|
|
257
244
|
options?: ModelContextRegisterToolOptions
|
|
258
|
-
): void
|
|
245
|
+
): Promise<void>;
|
|
259
246
|
|
|
260
247
|
/**
|
|
261
248
|
* Registers a dynamic tool without an explicit inputSchema.
|
|
@@ -269,14 +256,26 @@ export interface ModelContextCore {
|
|
|
269
256
|
inputSchema?: undefined;
|
|
270
257
|
},
|
|
271
258
|
options?: ModelContextRegisterToolOptions
|
|
272
|
-
): void
|
|
259
|
+
): Promise<void>;
|
|
273
260
|
|
|
274
261
|
/**
|
|
275
262
|
* Lists currently registered producer tools using the native Chromium preview
|
|
276
263
|
* shape. Current Chromium returns JSON-stringified schemas here, matching
|
|
277
264
|
* ModelContextTesting.listTools().
|
|
278
265
|
*/
|
|
279
|
-
getTools():
|
|
266
|
+
getTools(): Promise<ModelContextToolInfo[]>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Executes a registered tool object returned from getTools().
|
|
270
|
+
*
|
|
271
|
+
* This mirrors Chromium's current producer-facing preview API. The testing API
|
|
272
|
+
* still executes by `(toolName, inputArgsJson)`.
|
|
273
|
+
*/
|
|
274
|
+
executeTool(
|
|
275
|
+
tool: ModelContextToolInfo,
|
|
276
|
+
inputArgsJson: string,
|
|
277
|
+
options?: ModelContextTestingExecuteToolOptions
|
|
278
|
+
): Promise<string | null>;
|
|
280
279
|
|
|
281
280
|
/**
|
|
282
281
|
* Handler invoked when the producer tool list changes.
|
|
@@ -296,7 +295,13 @@ export interface ModelContextCore {
|
|
|
296
295
|
): void;
|
|
297
296
|
|
|
298
297
|
dispatchEvent(event: Event): boolean;
|
|
298
|
+
}
|
|
299
299
|
|
|
300
|
+
/**
|
|
301
|
+
* MCPB extension surface layered on top of strict WebMCP core.
|
|
302
|
+
* These members are intentionally non-standard.
|
|
303
|
+
*/
|
|
304
|
+
export interface ModelContextExtensions {
|
|
300
305
|
/**
|
|
301
306
|
* Unregisters a dynamic tool by name or tool reference.
|
|
302
307
|
*
|
|
@@ -304,25 +309,17 @@ export interface ModelContextCore {
|
|
|
304
309
|
*/
|
|
305
310
|
unregisterTool(nameOrTool: string | ModelContextToolReference): void;
|
|
306
311
|
|
|
307
|
-
/**
|
|
308
|
-
* Clears all context (base + dynamic registrations).
|
|
309
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
310
|
-
*/
|
|
311
|
-
clearContext(): void;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* MCPB extension surface layered on top of strict WebMCP core.
|
|
316
|
-
* These members are intentionally non-standard.
|
|
317
|
-
*/
|
|
318
|
-
export interface ModelContextExtensions {
|
|
319
312
|
/**
|
|
320
313
|
* Lists currently registered tools.
|
|
321
314
|
*/
|
|
322
315
|
listTools(): ToolListItem[];
|
|
323
316
|
|
|
324
317
|
/**
|
|
325
|
-
* Executes a registered tool.
|
|
318
|
+
* Executes a registered tool by name.
|
|
319
|
+
*
|
|
320
|
+
* @deprecated Prefer the WebMCP standard producer path: get a descriptor from
|
|
321
|
+
* `getTools()` and pass it to `executeTool(tool, inputArgsJson)`. This method
|
|
322
|
+
* remains as an MCP-B compatibility convenience.
|
|
326
323
|
*/
|
|
327
324
|
callTool<
|
|
328
325
|
TName extends string = string,
|
|
@@ -395,7 +392,7 @@ export interface ModelContextExtensions {
|
|
|
395
392
|
}
|
|
396
393
|
|
|
397
394
|
/**
|
|
398
|
-
* Public
|
|
395
|
+
* Public document.modelContext type (strict core only).
|
|
399
396
|
*/
|
|
400
397
|
export type ModelContext = ModelContextCore;
|
|
401
398
|
|
|
@@ -412,13 +409,17 @@ export type ModelContextWithExtensions = ModelContextCore & ModelContextExtensio
|
|
|
412
409
|
* Strongly-typed `ModelContext` view derived from known tool descriptors.
|
|
413
410
|
*
|
|
414
411
|
* This is useful when your project has a static tool registry and you want
|
|
415
|
-
* name-aware inference for `callTool`.
|
|
412
|
+
* name-aware inference for MCP-B compatibility `callTool`.
|
|
416
413
|
*/
|
|
417
414
|
export type TypedModelContext<
|
|
418
415
|
TTools extends readonly { name: string }[] = readonly ToolDescriptor[],
|
|
419
416
|
> = ModelContextWithExtensions & {
|
|
420
417
|
/**
|
|
421
418
|
* Executes a known tool with name-aware argument and response inference.
|
|
419
|
+
*
|
|
420
|
+
* @deprecated Prefer the WebMCP standard producer path: get a descriptor from
|
|
421
|
+
* `getTools()` and pass it to `executeTool(tool, inputArgsJson)`. This typed
|
|
422
|
+
* convenience remains available for MCP-B compatibility.
|
|
422
423
|
*/
|
|
423
424
|
callTool<TName extends ToolName<TTools>>(
|
|
424
425
|
params: ToolCallParams<TName, ToolArgsByName<TTools, TName>>
|
|
@@ -426,6 +427,10 @@ export type TypedModelContext<
|
|
|
426
427
|
|
|
427
428
|
/**
|
|
428
429
|
* Fallback call signature for unknown or dynamically-discovered tools.
|
|
430
|
+
*
|
|
431
|
+
* @deprecated Prefer the WebMCP standard producer path: get a descriptor from
|
|
432
|
+
* `getTools()` and pass it to `executeTool(tool, inputArgsJson)`. This typed
|
|
433
|
+
* convenience remains available for MCP-B compatibility.
|
|
429
434
|
*/
|
|
430
435
|
callTool(params: { name: string; arguments?: Record<string, unknown> }): Promise<ToolResponse>;
|
|
431
436
|
|
package/src/tool.ts
CHANGED
|
@@ -8,7 +8,6 @@ import type {
|
|
|
8
8
|
InferArgsFromInputSchema,
|
|
9
9
|
InferJsonSchema,
|
|
10
10
|
JsonSchemaForInference,
|
|
11
|
-
JsonSchemaObject,
|
|
12
11
|
} from './json-schema.js';
|
|
13
12
|
|
|
14
13
|
// ============================================================================
|
|
@@ -119,6 +118,11 @@ export interface ToolDescriptor<
|
|
|
119
118
|
*/
|
|
120
119
|
name: TName;
|
|
121
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Optional user-facing label.
|
|
123
|
+
*/
|
|
124
|
+
title?: string;
|
|
125
|
+
|
|
122
126
|
/**
|
|
123
127
|
* Human-readable summary of what the tool does.
|
|
124
128
|
*/
|
|
@@ -155,8 +159,10 @@ export interface ToolDescriptor<
|
|
|
155
159
|
*/
|
|
156
160
|
export type ToolResultFromOutputSchema<
|
|
157
161
|
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
158
|
-
> = TOutputSchema extends
|
|
159
|
-
? CallToolResult & {
|
|
162
|
+
> = TOutputSchema extends JsonSchemaForInference
|
|
163
|
+
? Omit<CallToolResult, 'structuredContent'> & {
|
|
164
|
+
structuredContent: InferJsonSchema<TOutputSchema>;
|
|
165
|
+
}
|
|
160
166
|
: CallToolResult;
|
|
161
167
|
|
|
162
168
|
/**
|
|
@@ -164,11 +170,9 @@ export type ToolResultFromOutputSchema<
|
|
|
164
170
|
*/
|
|
165
171
|
export type ToolExecuteResultFromOutputSchema<
|
|
166
172
|
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
167
|
-
> = TOutputSchema extends
|
|
173
|
+
> = TOutputSchema extends JsonSchemaForInference
|
|
168
174
|
? InferJsonSchema<TOutputSchema> | ToolResultFromOutputSchema<TOutputSchema>
|
|
169
|
-
:
|
|
170
|
-
? InferJsonSchema<TOutputSchema> | CallToolResult
|
|
171
|
-
: ToolExecuteResult;
|
|
175
|
+
: ToolExecuteResult;
|
|
172
176
|
|
|
173
177
|
/**
|
|
174
178
|
* Tool descriptor whose `execute` args are inferred from a JSON Schema.
|
|
@@ -191,9 +195,13 @@ export type ToolDescriptorFromSchema<
|
|
|
191
195
|
ToolExecuteResultFromOutputSchema<TOutputSchema>,
|
|
192
196
|
TName
|
|
193
197
|
>,
|
|
194
|
-
'inputSchema' | 'outputSchema'
|
|
198
|
+
'execute' | 'inputSchema' | 'outputSchema'
|
|
195
199
|
> & {
|
|
196
200
|
inputSchema: TInputSchema;
|
|
201
|
+
execute: (
|
|
202
|
+
args: InferArgsFromInputSchema<TInputSchema>,
|
|
203
|
+
client: ModelContextClient
|
|
204
|
+
) => MaybePromise<ToolExecuteResultFromOutputSchema<TOutputSchema>>;
|
|
197
205
|
} & (TOutputSchema extends JsonSchemaForInference
|
|
198
206
|
? {
|
|
199
207
|
outputSchema: TOutputSchema;
|