@mcp-b/webmcp-types 2.2.0 → 2.3.1-beta.20260528050333
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 +36 -31
- package/dist/index.d.ts +20 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/model-context.d.ts +70 -34
- package/dist/model-context.d.ts.map +1 -1
- package/dist/tool.d.ts +11 -2
- package/dist/tool.d.ts.map +1 -1
- package/package.json +31 -31
- package/src/index.ts +22 -5
- package/src/json-schema.ts +20 -18
- package/src/model-context.ts +114 -59
- package/src/tool.ts +13 -2
- package/dist/standard-schema.d.ts +0 -32
- package/dist/standard-schema.d.ts.map +0 -1
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
|
|
@@ -23,11 +24,11 @@ This package is the type-safety source of truth for WebMCP.
|
|
|
23
24
|
|
|
24
25
|
## Package Selection
|
|
25
26
|
|
|
26
|
-
| Package
|
|
27
|
-
|
|
|
28
|
-
| `@mcp-b/webmcp-types`
|
|
29
|
-
| `@mcp-b/webmcp-polyfill` | You need strict WebMCP core runtime behavior
|
|
30
|
-
| `@mcp-b/global`
|
|
27
|
+
| Package | Use When |
|
|
28
|
+
| ------------------------ | ----------------------------------------------------------------------------- |
|
|
29
|
+
| `@mcp-b/webmcp-types` | You only need compile-time types |
|
|
30
|
+
| `@mcp-b/webmcp-polyfill` | You need strict WebMCP core runtime behavior |
|
|
31
|
+
| `@mcp-b/global` | You want core + MCPB bridge extensions (`callTool`, prompts, resources, etc.) |
|
|
31
32
|
|
|
32
33
|
## Install
|
|
33
34
|
|
|
@@ -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,
|
|
@@ -118,7 +119,7 @@ Use `as const satisfies JsonSchemaForInference` so TypeScript preserves literal
|
|
|
118
119
|
If schema types are widened (for example `InputSchema` loaded at runtime), inference intentionally falls back to:
|
|
119
120
|
|
|
120
121
|
```ts
|
|
121
|
-
Record<string, unknown
|
|
122
|
+
Record<string, unknown>;
|
|
122
123
|
```
|
|
123
124
|
|
|
124
125
|
### 2. Input inference rules
|
|
@@ -138,12 +139,12 @@ Other schema keywords are accepted as metadata but do not add new inferred struc
|
|
|
138
139
|
|
|
139
140
|
### 3. `additionalProperties` behavior
|
|
140
141
|
|
|
141
|
-
| Schema shape
|
|
142
|
-
|
|
|
143
|
-
| `additionalProperties: false`
|
|
144
|
-
| `additionalProperties` omitted/`true`
|
|
145
|
-
| `additionalProperties: { ... }` with no named `properties` | Map-like `Record<string, ...>`
|
|
146
|
-
| `additionalProperties: { ... }` with named `properties`
|
|
142
|
+
| Schema shape | Inferred extras |
|
|
143
|
+
| ---------------------------------------------------------- | -------------------------------------------------- |
|
|
144
|
+
| `additionalProperties: false` | No extra keys |
|
|
145
|
+
| `additionalProperties` omitted/`true` | Extra keys allowed as `unknown` |
|
|
146
|
+
| `additionalProperties: { ... }` with no named `properties` | Map-like `Record<string, ...>` |
|
|
147
|
+
| `additionalProperties: { ... }` with named `properties` | Named properties inferred, extras remain `unknown` |
|
|
147
148
|
|
|
148
149
|
### 4. Required keys depend on literal `required`
|
|
149
150
|
|
|
@@ -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',
|
|
@@ -208,25 +210,28 @@ void result;
|
|
|
208
210
|
|
|
209
211
|
## Commonly Used Exports
|
|
210
212
|
|
|
211
|
-
| Export
|
|
212
|
-
|
|
|
213
|
-
| `ModelContext`
|
|
214
|
-
| `ToolDescriptor`
|
|
215
|
-
| `ToolDescriptorFromSchema`
|
|
216
|
-
| `JsonSchemaForInference`
|
|
217
|
-
| `InferArgsFromInputSchema`
|
|
218
|
-
| `ToolResultFromOutputSchema`
|
|
219
|
-
| `TypedModelContext`
|
|
220
|
-
| `CallToolResult`
|
|
221
|
-
| `ContentBlock` / `LooseContentBlock` | Strict and pragmatic content block typing
|
|
222
|
-
| `ModelContextClient`
|
|
213
|
+
| Export | Purpose |
|
|
214
|
+
| ------------------------------------ | ------------------------------------------------------------ |
|
|
215
|
+
| `ModelContext` | Strict core `document.modelContext` type |
|
|
216
|
+
| `ToolDescriptor` | Explicitly typed tool descriptor |
|
|
217
|
+
| `ToolDescriptorFromSchema` | Schema-driven descriptor with inferred args/result |
|
|
218
|
+
| `JsonSchemaForInference` | Supported JSON Schema subset for inference |
|
|
219
|
+
| `InferArgsFromInputSchema` | Derive args shape from a schema type |
|
|
220
|
+
| `ToolResultFromOutputSchema` | Derive `structuredContent` type from output schema |
|
|
221
|
+
| `TypedModelContext` | Name-aware typed `callTool`/`listTools` for known registries |
|
|
222
|
+
| `CallToolResult` | Tool response type |
|
|
223
|
+
| `ContentBlock` / `LooseContentBlock` | Strict and pragmatic content block typing |
|
|
224
|
+
| `ModelContextClient` | Tool execution client (`requestUserInteraction`) |
|
|
223
225
|
|
|
224
226
|
## Important Notes
|
|
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
|
-
- `
|
|
229
|
-
-
|
|
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.
|
|
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.
|
|
233
|
+
- `registerTool(tool, options?)` accepts a `ModelContextRegisterToolOptions` dictionary with an optional `signal: AbortSignal`. Aborting the signal unregisters the tool.
|
|
234
|
+
- `ToolAnnotations.untrustedContentHint` was added to the spec on April 23, 2026 to flag tools whose output may include externally-sourced content.
|
|
230
235
|
- `navigator.modelContextTesting` is typed as optional for compatibility with Chromium preview/testing surfaces.
|
|
231
236
|
|
|
232
237
|
## License
|
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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C,SAAS,CAAC,KAAK,CAAC,GACpC,aAAa,CAAC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACrD,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,GAC9C,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AAElD,KAAK,oBAAoB,CAAC,YAAY,IAAI,MAAM,SAAS,YAAY,GACjE,IAAI,GACJ,YAAY,SAAS,SAAS,OAAO,EAAE,GACrC,MAAM,SAAS,YAAY,CAAC,MAAM,CAAC,GACjC,IAAI,GACJ,KAAK,GACP,KAAK,CAAC;AAEZ,KAAK,kBAAkB,CAAC,OAAO,IAC7B,aAAa,CAAC,OAAO,CAAC,SAAS,KAAK,GAChC,KAAK,GACL,QAAQ,SAAS,aAAa,CAAC,OAAO,CAAC,GACrC,IAAI,GACJ,KAAK,CAAC;AAEd;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAC1C,oBAAoB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,SAAS,IAAI,GACrD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,kBAAkB,CAAC,OAAO,CAAC,SAAS,IAAI,GACtC,WAAW,CAAC,OAAO,CAAC,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
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
|
*/
|
|
@@ -29,18 +24,30 @@ export interface ModelContextTestingExecuteToolOptions {
|
|
|
29
24
|
signal?: AbortSignal;
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
|
-
* Chromium
|
|
27
|
+
* Chromium testing API on navigator.modelContextTesting.
|
|
28
|
+
*
|
|
29
|
+
* The native runtime extends EventTarget and fires `toolchange` events.
|
|
33
30
|
*/
|
|
34
|
-
export interface ModelContextTesting {
|
|
31
|
+
export interface ModelContextTesting extends EventTarget {
|
|
35
32
|
listTools(): ModelContextTestingToolInfo[];
|
|
36
33
|
executeTool(toolName: string, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise<string | null>;
|
|
37
|
-
registerToolsChangedCallback(callback: () => void): void;
|
|
38
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;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Polyfill-only testing extensions layered on top of ModelContextTesting.
|
|
42
43
|
*/
|
|
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;
|
|
44
51
|
getToolCalls(): Array<{
|
|
45
52
|
toolName: string;
|
|
46
53
|
arguments: Record<string, unknown>;
|
|
@@ -134,59 +141,80 @@ export interface ModelContextToolReference {
|
|
|
134
141
|
/**
|
|
135
142
|
* Non-standard compatibility handle returned by some runtimes after registerTool().
|
|
136
143
|
*
|
|
137
|
-
*
|
|
138
|
-
* This handle is kept only for compatibility with older non-standard runtimes.
|
|
144
|
+
* @deprecated Use `options.signal` on `registerTool(tool, options)`. Will be removed in the next major.
|
|
139
145
|
*/
|
|
140
146
|
export interface ModelContextToolRegistrationHandle {
|
|
141
147
|
unregister(): void;
|
|
142
148
|
}
|
|
143
149
|
/**
|
|
144
|
-
*
|
|
150
|
+
* @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-modelcontextregistertooloptions}
|
|
145
151
|
*/
|
|
146
|
-
export interface
|
|
152
|
+
export interface ModelContextRegisterToolOptions {
|
|
147
153
|
/**
|
|
148
|
-
*
|
|
149
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
154
|
+
* An `AbortSignal` whose abortion unregisters the tool. A pre-aborted signal short-circuits registration.
|
|
150
155
|
*/
|
|
151
|
-
|
|
156
|
+
signal?: AbortSignal;
|
|
157
|
+
/**
|
|
158
|
+
* Origins that can observe this tool from other documents in the same tree.
|
|
159
|
+
*/
|
|
160
|
+
exposedTo?: string[];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Strict WebMCP core interface on document.modelContext.
|
|
164
|
+
*/
|
|
165
|
+
export interface ModelContextCore {
|
|
152
166
|
/**
|
|
153
167
|
* Registers a dynamic tool with JSON Schema-driven inference.
|
|
154
168
|
*
|
|
155
169
|
* `execute(args)` is inferred from `inputSchema`, and when a literal object
|
|
156
170
|
* `outputSchema` is provided, `execute(...).structuredContent` is inferred too.
|
|
157
171
|
*/
|
|
158
|
-
registerTool<TInputSchema extends JsonSchemaForInference, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName
|
|
172
|
+
registerTool<TInputSchema extends JsonSchemaForInference, TOutputSchema extends JsonSchemaForInference | undefined = undefined, TName extends string = string>(tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>, options?: ModelContextRegisterToolOptions): void;
|
|
159
173
|
/**
|
|
160
174
|
* Registers a dynamic tool with explicitly typed args/result.
|
|
161
175
|
*/
|
|
162
176
|
registerTool<TInputSchema extends InputSchema, TArgs extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(tool: ToolDescriptor<TArgs, ToolRawResult, TName> & {
|
|
163
177
|
inputSchema: TInputSchema;
|
|
164
|
-
} & (TInputSchema extends InputSchema ? string extends TInputSchema['type'] ? unknown : never : unknown)): void;
|
|
178
|
+
} & (TInputSchema extends InputSchema ? string extends TInputSchema['type'] ? unknown : never : unknown), options?: ModelContextRegisterToolOptions): void;
|
|
165
179
|
/**
|
|
166
180
|
* Registers a dynamic tool without an explicit inputSchema.
|
|
167
181
|
* Runtime defaults this to an empty object schema.
|
|
168
182
|
*/
|
|
169
183
|
registerTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(tool: Omit<ToolDescriptor<TArgs, ToolRawResult, TName>, 'inputSchema'> & {
|
|
170
184
|
inputSchema?: undefined;
|
|
171
|
-
}): void;
|
|
185
|
+
}, options?: ModelContextRegisterToolOptions): void;
|
|
172
186
|
/**
|
|
173
|
-
*
|
|
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().
|
|
174
194
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
195
|
+
* This mirrors Chromium's current producer-facing preview API. The testing API
|
|
196
|
+
* still executes by `(toolName, inputArgsJson)`.
|
|
177
197
|
*/
|
|
178
|
-
|
|
198
|
+
executeTool(tool: ModelContextToolInfo, inputArgsJson: string, options?: ModelContextTestingExecuteToolOptions): Promise<string | null>;
|
|
179
199
|
/**
|
|
180
|
-
*
|
|
181
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
200
|
+
* Handler invoked when the producer tool list changes.
|
|
182
201
|
*/
|
|
183
|
-
|
|
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;
|
|
184
206
|
}
|
|
185
207
|
/**
|
|
186
208
|
* MCPB extension surface layered on top of strict WebMCP core.
|
|
187
209
|
* These members are intentionally non-standard.
|
|
188
210
|
*/
|
|
189
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;
|
|
190
218
|
/**
|
|
191
219
|
* Lists currently registered tools.
|
|
192
220
|
*/
|
|
@@ -205,6 +233,10 @@ export interface ModelContextExtensions {
|
|
|
205
233
|
/**
|
|
206
234
|
* Adds a listener for tool list changes.
|
|
207
235
|
*/
|
|
236
|
+
addEventListener(type: 'toolchange', listener: () => void, options?: boolean | AddEventListenerOptions): void;
|
|
237
|
+
/**
|
|
238
|
+
* @deprecated Use `'toolchange'` instead. Will be removed in the next major.
|
|
239
|
+
*/
|
|
208
240
|
addEventListener(type: 'toolschanged', listener: () => void, options?: boolean | AddEventListenerOptions): void;
|
|
209
241
|
/**
|
|
210
242
|
* Removes a listener for tool invocation events.
|
|
@@ -213,6 +245,10 @@ export interface ModelContextExtensions {
|
|
|
213
245
|
/**
|
|
214
246
|
* Removes a listener for tool list changes.
|
|
215
247
|
*/
|
|
248
|
+
removeEventListener(type: 'toolchange', listener: () => void, options?: boolean | EventListenerOptions): void;
|
|
249
|
+
/**
|
|
250
|
+
* @deprecated Use `'toolchange'` instead. Will be removed in the next major.
|
|
251
|
+
*/
|
|
216
252
|
removeEventListener(type: 'toolschanged', listener: () => void, options?: boolean | EventListenerOptions): void;
|
|
217
253
|
/**
|
|
218
254
|
* Dispatches an event.
|
|
@@ -220,7 +256,7 @@ export interface ModelContextExtensions {
|
|
|
220
256
|
dispatchEvent(event: Event): boolean;
|
|
221
257
|
}
|
|
222
258
|
/**
|
|
223
|
-
* Public
|
|
259
|
+
* Public document.modelContext type (strict core only).
|
|
224
260
|
*/
|
|
225
261
|
export type ModelContext = ModelContextCore;
|
|
226
262
|
/**
|
|
@@ -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,YA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AAgB,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;;OAEG;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;;OAEG;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
|
@@ -3,6 +3,7 @@ import type { InferArgsFromInputSchema, InferJsonSchema, JsonSchemaForInference,
|
|
|
3
3
|
/**
|
|
4
4
|
* Annotations providing hints about tool behavior.
|
|
5
5
|
*
|
|
6
|
+
* @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations}
|
|
6
7
|
* @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
|
|
7
8
|
*/
|
|
8
9
|
export interface ToolAnnotations {
|
|
@@ -14,6 +15,10 @@ export interface ToolAnnotations {
|
|
|
14
15
|
* Indicates the tool is read-only.
|
|
15
16
|
*/
|
|
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';
|
|
17
22
|
/**
|
|
18
23
|
* Indicates the tool may perform destructive actions.
|
|
19
24
|
*/
|
|
@@ -77,6 +82,10 @@ export interface ToolDescriptor<TArgs extends Record<string, unknown> = Record<s
|
|
|
77
82
|
* Unique tool identifier.
|
|
78
83
|
*/
|
|
79
84
|
name: TName;
|
|
85
|
+
/**
|
|
86
|
+
* Optional user-facing label.
|
|
87
|
+
*/
|
|
88
|
+
title?: string;
|
|
80
89
|
/**
|
|
81
90
|
* Human-readable summary of what the tool does.
|
|
82
91
|
*/
|
|
@@ -88,7 +97,7 @@ export interface ToolDescriptor<TArgs extends Record<string, unknown> = Record<s
|
|
|
88
97
|
/**
|
|
89
98
|
* Optional schema describing output payload shape.
|
|
90
99
|
*/
|
|
91
|
-
outputSchema?:
|
|
100
|
+
outputSchema?: JsonSchemaForInference;
|
|
92
101
|
/**
|
|
93
102
|
* Optional behavior hints for LLM planners.
|
|
94
103
|
*/
|
|
@@ -155,7 +164,7 @@ export interface ToolListItem<TName extends string = string> {
|
|
|
155
164
|
/**
|
|
156
165
|
* Optional JSON Schema describing output payload shape.
|
|
157
166
|
*/
|
|
158
|
-
outputSchema?:
|
|
167
|
+
outputSchema?: JsonSchemaForInference;
|
|
159
168
|
/**
|
|
160
169
|
* Optional behavior hints for LLM planners.
|
|
161
170
|
*/
|
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,EACtB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAM1B
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAA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GAAG,SAAS,MAAM,EAAE,CAAA;CAAE,EAC1D,aAAa,SAAS,sBAAsB,GAAG,SAAS,GAAG,SAAS,EACpE,KAAK,SAAS,MAAM,GAAG,MAAM,IAC3B,IAAI,CACN,cAAc,CACZ,wBAAwB,CAAC,YAAY,CAAC,EACtC,iCAAiC,CAAC,aAAa,CAAC,EAChD,KAAK,CACN,EACD,aAAa,GAAG,cAAc,CAC/B,GAAG;IACF,WAAW,EAAE,YAAY,CAAC;CAC3B,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,35 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/webmcp-types",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Strict TypeScript type definitions for the WebMCP core API (
|
|
3
|
+
"version": "2.3.1-beta.20260528050333",
|
|
4
|
+
"description": "Strict TypeScript type definitions for the WebMCP core API (document.modelContext)",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"document-modelcontext",
|
|
7
7
|
"model-context",
|
|
8
8
|
"navigator-modelcontext",
|
|
9
9
|
"types",
|
|
10
10
|
"typescript",
|
|
11
|
-
"web-standard"
|
|
11
|
+
"web-standard",
|
|
12
|
+
"webmcp"
|
|
12
13
|
],
|
|
13
14
|
"homepage": "https://docs.mcp-b.ai/packages/webmcp-types",
|
|
14
15
|
"bugs": {
|
|
15
16
|
"url": "https://github.com/WebMCP-org/npm-packages/issues"
|
|
16
17
|
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Alex Nahas",
|
|
17
20
|
"repository": {
|
|
18
21
|
"type": "git",
|
|
19
22
|
"url": "git+https://github.com/WebMCP-org/npm-packages.git",
|
|
20
23
|
"directory": "packages/webmcp-types"
|
|
21
24
|
},
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"author": "Alex Nahas",
|
|
24
|
-
"sideEffects": false,
|
|
25
|
-
"type": "module",
|
|
26
|
-
"exports": {
|
|
27
|
-
".": {
|
|
28
|
-
"types": "./dist/index.d.ts"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"main": "",
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
33
25
|
"files": [
|
|
34
26
|
"dist",
|
|
35
27
|
"src/common.ts",
|
|
@@ -38,30 +30,38 @@
|
|
|
38
30
|
"src/model-context.ts",
|
|
39
31
|
"src/tool.ts"
|
|
40
32
|
],
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
33
|
+
"type": "module",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"main": "",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts"
|
|
40
|
+
}
|
|
48
41
|
},
|
|
49
42
|
"publishConfig": {
|
|
50
43
|
"access": "public",
|
|
51
44
|
"registry": "https://registry.npmjs.org/"
|
|
52
45
|
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
48
|
+
"playwright": "^1.60.0",
|
|
49
|
+
"typescript": "^5.8.3",
|
|
50
|
+
"vite-plus": "^0.1.22",
|
|
51
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
52
|
+
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "tsc -p tsconfig.build.json",
|
|
55
|
-
"check": "
|
|
56
|
-
"clean": "rm -rf dist
|
|
57
|
-
"format": "
|
|
58
|
-
"lint": "
|
|
55
|
+
"check": "vp check --fix",
|
|
56
|
+
"clean": "rm -rf dist",
|
|
57
|
+
"format": "vp fmt --write",
|
|
58
|
+
"lint": "vp lint --fix",
|
|
59
59
|
"publish:dry": "pnpm publish --access public --dry-run",
|
|
60
60
|
"publish:npm": "pnpm publish --access public",
|
|
61
|
-
"test": "
|
|
62
|
-
"test:browser": "
|
|
63
|
-
"test:browser:ui": "
|
|
64
|
-
"test:conformance": "
|
|
65
|
-
"typecheck": "tsc --noEmit &&
|
|
61
|
+
"test": "vp test run && pnpm run test:conformance",
|
|
62
|
+
"test:browser": "vp test run --config vitest.browser.config.ts --browser.headless",
|
|
63
|
+
"test:browser:ui": "vp test --config vitest.browser.config.ts --browser",
|
|
64
|
+
"test:conformance": "vp test run --config vitest.conformance.config.ts",
|
|
65
|
+
"typecheck": "tsc --noEmit && vp test run --typecheck --silent"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/index.ts
CHANGED
|
@@ -48,12 +48,12 @@ export type {
|
|
|
48
48
|
ModelContext,
|
|
49
49
|
ModelContextCore,
|
|
50
50
|
ModelContextExtensions,
|
|
51
|
-
|
|
52
|
-
ModelContextOptions,
|
|
51
|
+
ModelContextRegisterToolOptions,
|
|
53
52
|
ModelContextTesting,
|
|
54
53
|
ModelContextTestingExecuteToolOptions,
|
|
55
54
|
ModelContextTestingPolyfillExtensions,
|
|
56
55
|
ModelContextTestingToolInfo,
|
|
56
|
+
ModelContextToolInfo,
|
|
57
57
|
ModelContextToolReference,
|
|
58
58
|
ModelContextToolRegistrationHandle,
|
|
59
59
|
ModelContextWithExtensions,
|
|
@@ -83,16 +83,33 @@ export type {
|
|
|
83
83
|
// ============================================================================
|
|
84
84
|
|
|
85
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
|
+
|
|
86
97
|
interface Navigator {
|
|
87
98
|
/**
|
|
88
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.
|
|
89
105
|
*/
|
|
90
|
-
modelContext: ModelContext;
|
|
106
|
+
readonly modelContext: ModelContext;
|
|
91
107
|
|
|
92
108
|
/**
|
|
93
109
|
* Web Model Context testing API surface (Chromium early preview).
|
|
94
|
-
* @deprecated
|
|
95
|
-
*
|
|
110
|
+
* @deprecated Chromium still exposes this API for testing flows. Producer
|
|
111
|
+
* discovery/execution should prefer document.modelContext.getTools() and
|
|
112
|
+
* document.modelContext.executeTool(...).
|
|
96
113
|
*/
|
|
97
114
|
modelContextTesting?: ModelContextTesting;
|
|
98
115
|
}
|
package/src/json-schema.ts
CHANGED
|
@@ -204,9 +204,10 @@ type AdditionalSchemaOf<TSchema> = TSchema extends { additionalProperties: infer
|
|
|
204
204
|
? TAdditional
|
|
205
205
|
: undefined;
|
|
206
206
|
|
|
207
|
-
type AdditionalPropsValue<TSchema> =
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
type AdditionalPropsValue<TSchema> =
|
|
208
|
+
AdditionalSchemaOf<TSchema> extends JsonSchemaForInference
|
|
209
|
+
? InferJsonSchema<AdditionalSchemaOf<TSchema>>
|
|
210
|
+
: unknown;
|
|
210
211
|
|
|
211
212
|
type AdditionalPropsOf<TSchema> = TSchema extends { additionalProperties: false }
|
|
212
213
|
? EmptyObject
|
|
@@ -250,9 +251,10 @@ type InferFromTypeOption<TSchema, TType extends JsonSchemaType> = TType extends
|
|
|
250
251
|
? null
|
|
251
252
|
: unknown;
|
|
252
253
|
|
|
253
|
-
type InferFromTypeKeyword<TSchema> =
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
type InferFromTypeKeyword<TSchema> =
|
|
255
|
+
TypeOptionsOf<TSchema> extends never
|
|
256
|
+
? unknown
|
|
257
|
+
: InferFromTypeOption<TSchema, TypeOptionsOf<TSchema>>;
|
|
256
258
|
|
|
257
259
|
type ApplyNullable<TSchema, TValue> = TSchema extends { nullable: true } ? TValue | null : TValue;
|
|
258
260
|
|
|
@@ -275,11 +277,12 @@ type IsWidenedTypeKeyword<TTypeKeyword> = string extends TTypeKeyword
|
|
|
275
277
|
: false
|
|
276
278
|
: false;
|
|
277
279
|
|
|
278
|
-
type IncludesObjectType<TSchema> =
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
type IncludesObjectType<TSchema> =
|
|
281
|
+
TypeOptionsOf<TSchema> extends never
|
|
282
|
+
? false
|
|
283
|
+
: 'object' extends TypeOptionsOf<TSchema>
|
|
284
|
+
? true
|
|
285
|
+
: false;
|
|
283
286
|
|
|
284
287
|
/**
|
|
285
288
|
* Infers tool argument types from a root `InputSchema`.
|
|
@@ -288,10 +291,9 @@ type IncludesObjectType<TSchema> = TypeOptionsOf<TSchema> extends never
|
|
|
288
291
|
* `InputSchema` loaded at runtime), this intentionally falls back to
|
|
289
292
|
* `Record<string, unknown>`.
|
|
290
293
|
*/
|
|
291
|
-
export type InferArgsFromInputSchema<TSchema> =
|
|
292
|
-
TypeKeywordOf<TSchema
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
: Record<string, unknown>;
|
|
294
|
+
export type InferArgsFromInputSchema<TSchema> =
|
|
295
|
+
IsWidenedTypeKeyword<TypeKeywordOf<TSchema>> extends true
|
|
296
|
+
? Record<string, unknown>
|
|
297
|
+
: IncludesObjectType<TSchema> extends true
|
|
298
|
+
? InferObject<TSchema>
|
|
299
|
+
: Record<string, unknown>;
|
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
|
*/
|
|
@@ -47,23 +37,35 @@ export interface ModelContextTestingExecuteToolOptions {
|
|
|
47
37
|
}
|
|
48
38
|
|
|
49
39
|
/**
|
|
50
|
-
* Chromium
|
|
40
|
+
* Chromium testing API on navigator.modelContextTesting.
|
|
41
|
+
*
|
|
42
|
+
* The native runtime extends EventTarget and fires `toolchange` events.
|
|
51
43
|
*/
|
|
52
|
-
export interface ModelContextTesting {
|
|
44
|
+
export interface ModelContextTesting extends EventTarget {
|
|
53
45
|
listTools(): ModelContextTestingToolInfo[];
|
|
54
46
|
executeTool(
|
|
55
47
|
toolName: string,
|
|
56
48
|
inputArgsJson: string,
|
|
57
49
|
options?: ModelContextTestingExecuteToolOptions
|
|
58
50
|
): Promise<string | null>;
|
|
59
|
-
registerToolsChangedCallback(callback: () => void): void;
|
|
60
51
|
getCrossDocumentScriptToolResult(): Promise<string>;
|
|
52
|
+
ontoolchange: ((this: ModelContextTesting, ev: Event) => unknown) | null;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use `addEventListener('toolchange', ...)` instead.
|
|
55
|
+
*/
|
|
56
|
+
registerToolsChangedCallback?(callback: () => void): void;
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
/**
|
|
64
60
|
* Polyfill-only testing extensions layered on top of ModelContextTesting.
|
|
65
61
|
*/
|
|
66
62
|
export interface ModelContextTestingPolyfillExtensions {
|
|
63
|
+
/**
|
|
64
|
+
* Registers a callback invoked when the tool list changes.
|
|
65
|
+
* @deprecated Use `addEventListener('toolchange', ...)` on native runtimes.
|
|
66
|
+
* Kept for polyfill backward compatibility.
|
|
67
|
+
*/
|
|
68
|
+
registerToolsChangedCallback(callback: () => void): void;
|
|
67
69
|
getToolCalls(): Array<{
|
|
68
70
|
toolName: string;
|
|
69
71
|
arguments: Record<string, unknown>;
|
|
@@ -91,24 +93,14 @@ export type AnyToolDescriptor = ToolDescriptor<never, unknown, string>;
|
|
|
91
93
|
/**
|
|
92
94
|
* Infers argument shape from a tool descriptor.
|
|
93
95
|
*/
|
|
94
|
-
export type InferToolArgs<TTool> =
|
|
95
|
-
infer TArgs,
|
|
96
|
-
infer _TResult,
|
|
97
|
-
infer _TName
|
|
98
|
-
>
|
|
99
|
-
? TArgs
|
|
100
|
-
: never;
|
|
96
|
+
export type InferToolArgs<TTool> =
|
|
97
|
+
TTool extends ToolDescriptor<infer TArgs, infer _TResult, infer _TName> ? TArgs : never;
|
|
101
98
|
|
|
102
99
|
/**
|
|
103
100
|
* Infers result shape from a tool descriptor.
|
|
104
101
|
*/
|
|
105
|
-
export type InferToolResult<TTool> =
|
|
106
|
-
infer _TArgs,
|
|
107
|
-
infer TResult,
|
|
108
|
-
infer _TName
|
|
109
|
-
>
|
|
110
|
-
? TResult
|
|
111
|
-
: never;
|
|
102
|
+
export type InferToolResult<TTool> =
|
|
103
|
+
TTool extends ToolDescriptor<infer _TArgs, infer TResult, infer _TName> ? TResult : never;
|
|
112
104
|
|
|
113
105
|
/**
|
|
114
106
|
* Union of tool names from a tuple/array of descriptors.
|
|
@@ -188,29 +180,35 @@ export interface ModelContextToolReference {
|
|
|
188
180
|
/**
|
|
189
181
|
* Non-standard compatibility handle returned by some runtimes after registerTool().
|
|
190
182
|
*
|
|
191
|
-
*
|
|
192
|
-
* This handle is kept only for compatibility with older non-standard runtimes.
|
|
183
|
+
* @deprecated Use `options.signal` on `registerTool(tool, options)`. Will be removed in the next major.
|
|
193
184
|
*/
|
|
194
185
|
export interface ModelContextToolRegistrationHandle {
|
|
195
186
|
unregister(): void;
|
|
196
187
|
}
|
|
197
188
|
|
|
189
|
+
/**
|
|
190
|
+
* @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-modelcontextregistertooloptions}
|
|
191
|
+
*/
|
|
192
|
+
export interface ModelContextRegisterToolOptions {
|
|
193
|
+
/**
|
|
194
|
+
* An `AbortSignal` whose abortion unregisters the tool. A pre-aborted signal short-circuits registration.
|
|
195
|
+
*/
|
|
196
|
+
signal?: AbortSignal;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Origins that can observe this tool from other documents in the same tree.
|
|
200
|
+
*/
|
|
201
|
+
exposedTo?: string[];
|
|
202
|
+
}
|
|
203
|
+
|
|
198
204
|
// ============================================================================
|
|
199
205
|
// Model Context
|
|
200
206
|
// ============================================================================
|
|
201
207
|
|
|
202
208
|
/**
|
|
203
|
-
* Strict WebMCP core interface on
|
|
209
|
+
* Strict WebMCP core interface on document.modelContext.
|
|
204
210
|
*/
|
|
205
211
|
export interface ModelContextCore {
|
|
206
|
-
// ==================== CONTEXT ====================
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Replaces base context with provided tools.
|
|
210
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
211
|
-
*/
|
|
212
|
-
provideContext(options?: ModelContextOptions): void;
|
|
213
|
-
|
|
214
212
|
// ==================== TOOLS ====================
|
|
215
213
|
|
|
216
214
|
/**
|
|
@@ -223,7 +221,10 @@ export interface ModelContextCore {
|
|
|
223
221
|
TInputSchema extends JsonSchemaForInference,
|
|
224
222
|
TOutputSchema extends JsonSchemaForInference | undefined = undefined,
|
|
225
223
|
TName extends string = string,
|
|
226
|
-
>(
|
|
224
|
+
>(
|
|
225
|
+
tool: ToolDescriptorFromSchema<TInputSchema, TOutputSchema, TName>,
|
|
226
|
+
options?: ModelContextRegisterToolOptions
|
|
227
|
+
): void;
|
|
227
228
|
|
|
228
229
|
/**
|
|
229
230
|
* Registers a dynamic tool with explicitly typed args/result.
|
|
@@ -239,7 +240,8 @@ export interface ModelContextCore {
|
|
|
239
240
|
? string extends TInputSchema['type']
|
|
240
241
|
? unknown
|
|
241
242
|
: never
|
|
242
|
-
: unknown)
|
|
243
|
+
: unknown),
|
|
244
|
+
options?: ModelContextRegisterToolOptions
|
|
243
245
|
): void;
|
|
244
246
|
|
|
245
247
|
/**
|
|
@@ -252,22 +254,47 @@ export interface ModelContextCore {
|
|
|
252
254
|
>(
|
|
253
255
|
tool: Omit<ToolDescriptor<TArgs, ToolRawResult, TName>, 'inputSchema'> & {
|
|
254
256
|
inputSchema?: undefined;
|
|
255
|
-
}
|
|
257
|
+
},
|
|
258
|
+
options?: ModelContextRegisterToolOptions
|
|
256
259
|
): void;
|
|
257
260
|
|
|
258
261
|
/**
|
|
259
|
-
*
|
|
262
|
+
* Lists currently registered producer tools using the native Chromium preview
|
|
263
|
+
* shape. Current Chromium returns JSON-stringified schemas here, matching
|
|
264
|
+
* ModelContextTesting.listTools().
|
|
265
|
+
*/
|
|
266
|
+
getTools(): Promise<ModelContextToolInfo[]>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Executes a registered tool object returned from getTools().
|
|
260
270
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
271
|
+
* This mirrors Chromium's current producer-facing preview API. The testing API
|
|
272
|
+
* still executes by `(toolName, inputArgsJson)`.
|
|
263
273
|
*/
|
|
264
|
-
|
|
274
|
+
executeTool(
|
|
275
|
+
tool: ModelContextToolInfo,
|
|
276
|
+
inputArgsJson: string,
|
|
277
|
+
options?: ModelContextTestingExecuteToolOptions
|
|
278
|
+
): Promise<string | null>;
|
|
265
279
|
|
|
266
280
|
/**
|
|
267
|
-
*
|
|
268
|
-
* @deprecated Removed from the upstream WebMCP spec on March 5, 2026. Kept only as a temporary compatibility API.
|
|
281
|
+
* Handler invoked when the producer tool list changes.
|
|
269
282
|
*/
|
|
270
|
-
|
|
283
|
+
ontoolchange: ((this: ModelContextCore, ev: Event) => unknown) | null;
|
|
284
|
+
|
|
285
|
+
addEventListener(
|
|
286
|
+
type: 'toolchange',
|
|
287
|
+
listener: () => void,
|
|
288
|
+
options?: boolean | AddEventListenerOptions
|
|
289
|
+
): void;
|
|
290
|
+
|
|
291
|
+
removeEventListener(
|
|
292
|
+
type: 'toolchange',
|
|
293
|
+
listener: () => void,
|
|
294
|
+
options?: boolean | EventListenerOptions
|
|
295
|
+
): void;
|
|
296
|
+
|
|
297
|
+
dispatchEvent(event: Event): boolean;
|
|
271
298
|
}
|
|
272
299
|
|
|
273
300
|
/**
|
|
@@ -275,6 +302,13 @@ export interface ModelContextCore {
|
|
|
275
302
|
* These members are intentionally non-standard.
|
|
276
303
|
*/
|
|
277
304
|
export interface ModelContextExtensions {
|
|
305
|
+
/**
|
|
306
|
+
* Unregisters a dynamic tool by name or tool reference.
|
|
307
|
+
*
|
|
308
|
+
* @deprecated Removed from the WebMCP spec on April 23, 2026. Use `registerTool(tool, { signal })`. Will be removed in the next major.
|
|
309
|
+
*/
|
|
310
|
+
unregisterTool(nameOrTool: string | ModelContextToolReference): void;
|
|
311
|
+
|
|
278
312
|
/**
|
|
279
313
|
* Lists currently registered tools.
|
|
280
314
|
*/
|
|
@@ -286,7 +320,10 @@ export interface ModelContextExtensions {
|
|
|
286
320
|
callTool<
|
|
287
321
|
TName extends string = string,
|
|
288
322
|
TArgs extends Record<string, unknown> = Record<string, unknown>,
|
|
289
|
-
>(params: {
|
|
323
|
+
>(params: {
|
|
324
|
+
name: TName;
|
|
325
|
+
arguments?: TArgs;
|
|
326
|
+
}): Promise<ToolResponse>;
|
|
290
327
|
|
|
291
328
|
// ==================== EVENTS ====================
|
|
292
329
|
|
|
@@ -302,6 +339,15 @@ export interface ModelContextExtensions {
|
|
|
302
339
|
/**
|
|
303
340
|
* Adds a listener for tool list changes.
|
|
304
341
|
*/
|
|
342
|
+
addEventListener(
|
|
343
|
+
type: 'toolchange',
|
|
344
|
+
listener: () => void,
|
|
345
|
+
options?: boolean | AddEventListenerOptions
|
|
346
|
+
): void;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* @deprecated Use `'toolchange'` instead. Will be removed in the next major.
|
|
350
|
+
*/
|
|
305
351
|
addEventListener(
|
|
306
352
|
type: 'toolschanged',
|
|
307
353
|
listener: () => void,
|
|
@@ -320,6 +366,15 @@ export interface ModelContextExtensions {
|
|
|
320
366
|
/**
|
|
321
367
|
* Removes a listener for tool list changes.
|
|
322
368
|
*/
|
|
369
|
+
removeEventListener(
|
|
370
|
+
type: 'toolchange',
|
|
371
|
+
listener: () => void,
|
|
372
|
+
options?: boolean | EventListenerOptions
|
|
373
|
+
): void;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @deprecated Use `'toolchange'` instead. Will be removed in the next major.
|
|
377
|
+
*/
|
|
323
378
|
removeEventListener(
|
|
324
379
|
type: 'toolschanged',
|
|
325
380
|
listener: () => void,
|
|
@@ -333,7 +388,7 @@ export interface ModelContextExtensions {
|
|
|
333
388
|
}
|
|
334
389
|
|
|
335
390
|
/**
|
|
336
|
-
* Public
|
|
391
|
+
* Public document.modelContext type (strict core only).
|
|
337
392
|
*/
|
|
338
393
|
export type ModelContext = ModelContextCore;
|
|
339
394
|
|
package/src/tool.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
/**
|
|
19
19
|
* Annotations providing hints about tool behavior.
|
|
20
20
|
*
|
|
21
|
+
* @see {@link https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations}
|
|
21
22
|
* @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
|
|
22
23
|
*/
|
|
23
24
|
export interface ToolAnnotations {
|
|
@@ -31,6 +32,11 @@ export interface ToolAnnotations {
|
|
|
31
32
|
*/
|
|
32
33
|
readOnlyHint?: boolean | 'true' | 'false';
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Indicates the tool's output may include content from outside the page's trust boundary.
|
|
37
|
+
*/
|
|
38
|
+
untrustedContentHint?: boolean | 'true' | 'false';
|
|
39
|
+
|
|
34
40
|
/**
|
|
35
41
|
* Indicates the tool may perform destructive actions.
|
|
36
42
|
*/
|
|
@@ -113,6 +119,11 @@ export interface ToolDescriptor<
|
|
|
113
119
|
*/
|
|
114
120
|
name: TName;
|
|
115
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Optional user-facing label.
|
|
124
|
+
*/
|
|
125
|
+
title?: string;
|
|
126
|
+
|
|
116
127
|
/**
|
|
117
128
|
* Human-readable summary of what the tool does.
|
|
118
129
|
*/
|
|
@@ -126,7 +137,7 @@ export interface ToolDescriptor<
|
|
|
126
137
|
/**
|
|
127
138
|
* Optional schema describing output payload shape.
|
|
128
139
|
*/
|
|
129
|
-
outputSchema?:
|
|
140
|
+
outputSchema?: JsonSchemaForInference;
|
|
130
141
|
|
|
131
142
|
/**
|
|
132
143
|
* Optional behavior hints for LLM planners.
|
|
@@ -225,7 +236,7 @@ export interface ToolListItem<TName extends string = string> {
|
|
|
225
236
|
/**
|
|
226
237
|
* Optional JSON Schema describing output payload shape.
|
|
227
238
|
*/
|
|
228
|
-
outputSchema?:
|
|
239
|
+
outputSchema?: JsonSchemaForInference;
|
|
229
240
|
|
|
230
241
|
/**
|
|
231
242
|
* Optional behavior hints for LLM planners.
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { StandardJSONSchemaV1 as BaseStandardJSONSchemaV1, StandardSchemaV1 as BaseStandardSchemaV1, StandardTypedV1 } from '@standard-schema/spec';
|
|
2
|
-
import type { InputSchema } from './common.js';
|
|
3
|
-
/**
|
|
4
|
-
* Re-export of the official Standard Schema spec types.
|
|
5
|
-
*/
|
|
6
|
-
export type { BaseStandardJSONSchemaV1 as StandardJSONSchemaV1, BaseStandardSchemaV1 as StandardSchemaV1, StandardTypedV1, };
|
|
7
|
-
/**
|
|
8
|
-
* Standard Schema validator constrained to object-like tool args.
|
|
9
|
-
*/
|
|
10
|
-
export type StandardInputValidatorSchema = BaseStandardSchemaV1<Record<string, unknown>, Record<string, unknown>>;
|
|
11
|
-
/**
|
|
12
|
-
* Standard JSON Schema converter constrained to object-like tool args.
|
|
13
|
-
*/
|
|
14
|
-
export type StandardInputJsonSchema = BaseStandardJSONSchemaV1<Record<string, unknown>, Record<string, unknown>>;
|
|
15
|
-
/**
|
|
16
|
-
* Schema that supports both Standard Schema validation and JSON Schema conversion.
|
|
17
|
-
*/
|
|
18
|
-
export type StandardInputSchemaWithJson = StandardInputValidatorSchema & StandardInputJsonSchema;
|
|
19
|
-
/**
|
|
20
|
-
* Any input schema accepted by tool descriptors.
|
|
21
|
-
*
|
|
22
|
-
* Runtime adapters may normalize all inputs to a Standard Schema validator.
|
|
23
|
-
* When a schema implements both Standard Schema validation and Standard JSON
|
|
24
|
-
* Schema conversion, adapters may prefer JSON conversion to keep validation
|
|
25
|
-
* errors consistent across plain JSON Schema and Standard-compatible inputs.
|
|
26
|
-
*/
|
|
27
|
-
export type ToolInputSchema = InputSchema | StandardInputValidatorSchema | StandardInputJsonSchema;
|
|
28
|
-
/**
|
|
29
|
-
* Any output schema accepted by tool descriptors.
|
|
30
|
-
*/
|
|
31
|
-
export type ToolOutputSchema = InputSchema | StandardInputJsonSchema;
|
|
32
|
-
//# sourceMappingURL=standard-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,IAAI,wBAAwB,EAChD,gBAAgB,IAAI,oBAAoB,EACxC,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,YAAY,EACV,wBAAwB,IAAI,oBAAoB,EAChD,oBAAoB,IAAI,gBAAgB,EACxC,eAAe,GAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,oBAAoB,CAC7D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,CAC5D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,4BAA4B,GAAG,uBAAuB,CAAC;AAEjG;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,4BAA4B,GAAG,uBAAuB,CAAC;AAEnG;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,uBAAuB,CAAC"}
|