@mcp-b/webmcp-types 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-b/webmcp-types",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Strict TypeScript type definitions for the WebMCP core API (document.modelContext)",
5
5
  "keywords": [
6
6
  "document-modelcontext",
@@ -32,7 +32,6 @@
32
32
  ],
33
33
  "type": "module",
34
34
  "sideEffects": false,
35
- "main": "",
36
35
  "types": "./dist/index.d.ts",
37
36
  "exports": {
38
37
  ".": {
@@ -43,25 +42,26 @@
43
42
  "access": "public",
44
43
  "registry": "https://registry.npmjs.org/"
45
44
  },
45
+ "dependencies": {
46
+ "@modelcontextprotocol/server": "2.0.0"
47
+ },
46
48
  "devDependencies": {
47
- "@vitest/coverage-v8": "^4.1.7",
48
- "playwright": "^1.60.0",
49
49
  "typescript": "^5.8.3",
50
50
  "vite-plus": "^0.1.22",
51
51
  "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
52
52
  },
53
+ "engines": {
54
+ "node": ">=20"
55
+ },
53
56
  "scripts": {
54
- "build": "tsc -p tsconfig.build.json",
57
+ "build": "pnpm run clean && tsc -p tsconfig.build.json",
55
58
  "check": "vp check --fix",
56
59
  "clean": "rm -rf dist",
57
60
  "format": "vp fmt --write",
58
61
  "lint": "vp lint --fix",
59
62
  "publish:dry": "pnpm publish --access public --dry-run",
60
63
  "publish:npm": "pnpm publish --access public",
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"
64
+ "test": "vp test run",
65
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.strict-null-checks-false.json && vp test run --typecheck --silent"
66
66
  }
67
67
  }
package/src/common.ts CHANGED
@@ -1,368 +1,23 @@
1
- // ============================================================================
2
- // Common Types for the Web Model Context API
3
- // ============================================================================
4
-
5
- /**
6
- * Primitive JSON value.
7
- */
8
- export type JsonPrimitive = string | number | boolean | null;
9
-
10
- /**
11
- * Object-shaped JSON value.
12
- */
13
- export interface JsonObject {
14
- [key: string]: JsonValue;
15
- }
16
-
17
- /**
18
- * Any valid JSON value.
19
- */
20
- export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
21
-
22
- /**
23
- * JSON Schema property definition.
24
- *
25
- * @see {@link https://json-schema.org/}
26
- */
27
- export interface InputSchemaProperty {
28
- /**
29
- * JSON Schema type for this property.
30
- */
31
- type?: string;
32
-
33
- /**
34
- * Human-readable description of the property.
35
- */
36
- description?: string;
37
-
38
- /**
39
- * Additional JSON Schema keywords.
40
- */
41
- [key: string]: unknown;
42
- }
43
-
44
- /**
45
- * JSON Schema definition for tool input parameters.
46
- *
47
- * @see {@link https://json-schema.org/}
48
- */
1
+ export type {
2
+ CallToolResult,
3
+ ContentBlock,
4
+ JSONObject as JsonObject,
5
+ JSONValue as JsonValue,
6
+ TextContent,
7
+ } from '@modelcontextprotocol/server';
8
+
9
+ /** JSON Schema object accepted at the WebMCP boundary. */
49
10
  export interface InputSchema {
50
- /**
51
- * JSON Schema type for the root value (usually `'object'` for tool args).
52
- */
53
- type?: string;
54
-
55
- /**
56
- * Property definitions for object schemas.
57
- */
58
- properties?: Record<string, InputSchemaProperty>;
59
-
60
- /**
61
- * List of required property names.
62
- */
63
- required?: readonly string[];
64
-
65
- /**
66
- * Additional JSON Schema keywords.
67
- */
68
- [key: string]: unknown;
69
- }
70
-
71
- // ============================================================================
72
- // Content Types (MCP spec shapes, defined inline)
73
- // ============================================================================
74
-
75
- /**
76
- * Plain text content.
77
- */
78
- export interface TextContent {
79
- /**
80
- * Discriminator for text content.
81
- */
82
- type: 'text';
83
-
84
- /**
85
- * UTF-8 text value.
86
- */
87
- text: string;
88
- }
89
-
90
- /**
91
- * Base64-encoded image content.
92
- */
93
- export interface ImageContent {
94
- /**
95
- * Discriminator for image content.
96
- */
97
- type: 'image';
98
-
99
- /**
100
- * Base64 payload.
101
- */
102
- data: string;
103
-
104
- /**
105
- * MIME type for the encoded image.
106
- */
107
- mimeType: string;
108
- }
109
-
110
- /**
111
- * Base64-encoded audio content.
112
- */
113
- export interface AudioContent {
114
- /**
115
- * Discriminator for audio content.
116
- */
117
- type: 'audio';
118
-
119
- /**
120
- * Base64 payload.
121
- */
122
- data: string;
123
-
124
- /**
125
- * MIME type for the encoded audio.
126
- */
127
- mimeType: string;
128
- }
129
-
130
- /**
131
- * Text resource contents.
132
- */
133
- export interface TextResourceContents {
134
- /**
135
- * Canonical resource URI.
136
- */
137
- uri: string;
138
-
139
- /**
140
- * Optional MIME type.
141
- */
142
- mimeType?: string;
143
-
144
- /**
145
- * UTF-8 resource payload.
146
- */
147
- text: string;
148
- }
149
-
150
- /**
151
- * Binary resource contents encoded as base64.
152
- */
153
- export interface BlobResourceContents {
154
- /**
155
- * Canonical resource URI.
156
- */
157
- uri: string;
158
-
159
- /**
160
- * Optional MIME type.
161
- */
162
- mimeType?: string;
163
-
164
- /**
165
- * Base64-encoded binary payload.
166
- */
167
- blob: string;
168
- }
169
-
170
- /**
171
- * Resource contents returned by resource reads.
172
- */
173
- export type ResourceContents = TextResourceContents | BlobResourceContents;
174
-
175
- /**
176
- * Embedded resource content block.
177
- */
178
- export interface EmbeddedResource {
179
- /**
180
- * Discriminator for embedded resources.
181
- */
182
- type: 'resource';
183
-
184
- /**
185
- * Inlined resource contents.
186
- */
187
- resource: ResourceContents;
188
- }
189
-
190
- /**
191
- * Link to an externally retrievable resource.
192
- */
193
- export interface ResourceLink {
194
- /**
195
- * Discriminator for resource links.
196
- */
197
- type: 'resource_link';
198
-
199
- /**
200
- * Resource URI.
201
- */
202
- uri: string;
203
-
204
- /**
205
- * Optional display name.
206
- */
207
- name?: string;
208
-
209
- /**
210
- * Optional human-readable description.
211
- */
212
- description?: string;
213
-
214
- /**
215
- * Optional MIME type hint.
216
- */
217
- mimeType?: string;
11
+ type?: unknown;
12
+ properties?: Readonly<Record<string, unknown>> | undefined;
13
+ required?: readonly string[] | undefined;
14
+ [keyword: string]: unknown;
218
15
  }
219
16
 
220
- /**
221
- * Any content block allowed in tool responses.
222
- */
223
- export type ContentBlock =
224
- | TextContent
225
- | ImageContent
226
- | AudioContent
227
- | ResourceLink
228
- | EmbeddedResource;
229
-
230
- /**
231
- * Looser content block shape accepted by many MCP tool implementations.
232
- *
233
- * This keeps tool return typing practical while preserving strict content
234
- * unions via {@link ContentBlock} for consumers that want discriminated checks.
235
- */
236
- export type LooseContentBlock = Record<string, unknown> & {
237
- type?: string;
238
- };
239
-
240
- // ============================================================================
241
- // Result Types
242
- // ============================================================================
243
-
244
- /**
245
- * The result returned from tool execution.
246
- *
247
- * @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
248
- */
249
- export interface CallToolResult {
250
- /**
251
- * Ordered content blocks to return to the model.
252
- */
253
- content: Array<ContentBlock | LooseContentBlock>;
254
-
255
- /**
256
- * Optional machine-readable payload.
257
- */
258
- structuredContent?: JsonValue;
259
-
260
- /**
261
- * Marks the result as an error response.
262
- */
263
- isError?: boolean;
264
- }
265
-
266
- /**
267
- * Alias for {@link CallToolResult} for API consistency.
268
- */
269
- export type ToolResponse = CallToolResult;
270
-
271
- // ============================================================================
272
- // Elicitation Types
273
- // ============================================================================
274
-
275
- /**
276
- * Form-based elicitation request parameters.
277
- */
278
- export interface ElicitationFormParams {
279
- /**
280
- * Elicitation mode. Omit or set to `'form'` for form input.
281
- */
282
- mode?: 'form';
283
-
284
- /**
285
- * User-facing message.
286
- */
287
- message: string;
288
-
289
- /**
290
- * Requested form schema.
291
- */
292
- requestedSchema: {
293
- /**
294
- * Root schema type.
295
- */
296
- type: 'object';
297
-
298
- /**
299
- * Field definitions.
300
- */
301
- properties: Record<string, InputSchema>;
302
-
303
- /**
304
- * Required field names.
305
- */
306
- required?: readonly string[];
307
-
308
- /**
309
- * Additional schema keywords.
310
- */
311
- [key: string]: unknown;
312
- };
313
- }
314
-
315
- /**
316
- * URL-based elicitation request parameters.
317
- */
318
- export interface ElicitationUrlParams {
319
- /**
320
- * Elicitation mode.
321
- */
322
- mode: 'url';
323
-
324
- /**
325
- * User-facing message.
326
- */
327
- message: string;
328
-
329
- /**
330
- * Unique elicitation identifier.
331
- */
332
- elicitationId: string;
333
-
334
- /**
335
- * URL to open.
336
- */
337
- url: string;
338
- }
339
-
340
- /**
341
- * Elicitation request parameters.
342
- */
343
- export type ElicitationParams = ElicitationFormParams | ElicitationUrlParams;
344
-
345
- /**
346
- * Result returned by an elicitation request.
347
- */
348
- export interface ElicitationResult {
349
- /**
350
- * User decision.
351
- */
352
- action: 'accept' | 'decline' | 'cancel';
353
-
354
- /**
355
- * Submitted values when `action` is `'accept'`.
356
- */
357
- content?: Record<string, string | number | boolean | string[]>;
358
- }
17
+ /** Values accepted by WebMCP tool callbacks. */
18
+ export type WebMcpToolInput = Record<string, unknown> | unknown[];
359
19
 
360
- /**
361
- * Registration handle returned by registration methods.
362
- */
20
+ /** Handle returned by MCP-B registration helpers. */
363
21
  export interface RegistrationHandle {
364
- /**
365
- * Unregisters the associated item.
366
- */
367
- unregister: () => void;
22
+ unregister(): void;
368
23
  }
package/src/index.ts CHANGED
@@ -1,116 +1,94 @@
1
1
  import type { ModelContext, ModelContextTesting } from './model-context.js';
2
2
 
3
- // Re-export all public types
4
3
  export type {
5
- AudioContent,
6
- BlobResourceContents,
7
4
  CallToolResult,
8
5
  ContentBlock,
9
- ElicitationFormParams,
10
- ElicitationParams,
11
- ElicitationResult,
12
- ElicitationUrlParams,
13
- EmbeddedResource,
14
- ImageContent,
15
6
  InputSchema,
16
- InputSchemaProperty,
17
7
  JsonObject,
18
- JsonPrimitive,
19
8
  JsonValue,
20
- LooseContentBlock,
21
9
  RegistrationHandle,
22
- ResourceContents,
23
- ResourceLink,
24
10
  TextContent,
25
- TextResourceContents,
26
- ToolResponse,
11
+ WebMcpToolInput,
27
12
  } from './common.js';
28
13
  export type {
29
14
  InferArgsFromInputSchema,
30
15
  InferJsonSchema,
31
- JsonSchemaArray,
32
- JsonSchemaBoolean,
33
- JsonSchemaEnumValue,
34
16
  JsonSchemaForInference,
35
- JsonSchemaMultiType,
36
- JsonSchemaNull,
37
- JsonSchemaNumber,
38
- JsonSchemaObject,
39
- JsonSchemaPrimitiveType,
40
- JsonSchemaString,
41
- JsonSchemaType,
42
- JsonSchemaTypeArray,
43
17
  } from './json-schema.js';
44
18
  export type {
45
- AnyToolDescriptor,
46
- InferToolArgs,
47
- InferToolResult,
19
+ ChromeModelContext,
20
+ ChromeModelContextExecuteToolOptions,
21
+ ChromeModelContextExtensions,
48
22
  ModelContext,
49
- ModelContextCore,
50
23
  ModelContextExtensions,
24
+ ModelContextGetToolOptions,
51
25
  ModelContextRegisterToolOptions,
52
26
  ModelContextTesting,
53
- ModelContextTestingExecuteToolOptions,
54
- ModelContextTestingPolyfillExtensions,
55
27
  ModelContextTestingToolInfo,
56
- ModelContextToolInfo,
57
- ModelContextToolReference,
58
- ModelContextToolRegistrationHandle,
59
28
  ModelContextWithExtensions,
60
- ToolArgsByName,
61
- ToolByName,
62
- ToolCallEvent,
63
- ToolCallParams,
64
- ToolName,
65
- ToolResultByName,
66
- TypedModelContext,
29
+ RegisteredTool,
67
30
  } from './model-context.js';
68
31
  export type {
69
32
  MaybePromise,
70
- ModelContextClient,
33
+ ModelContextTool,
71
34
  ToolAnnotations,
72
35
  ToolDescriptor,
73
36
  ToolDescriptorFromSchema,
74
- ToolExecuteResult,
75
- ToolExecutionContext,
76
37
  ToolListItem,
77
- ToolRawResult,
78
38
  ToolResultFromOutputSchema,
39
+ WebMcpToolAnnotations,
79
40
  } from './tool.js';
80
41
 
81
- // ============================================================================
82
- // Global Augmentation
83
- // ============================================================================
84
-
85
42
  declare global {
43
+ /**
44
+ * Web IDL interface object used for branding and `instanceof`.
45
+ *
46
+ * Absent unless the document's realm implements WebMCP, so guard with
47
+ * `typeof ModelContext !== 'undefined'` before referencing it. A bare
48
+ * reference to an undeclared global throws `ReferenceError`.
49
+ */
50
+ var ModelContext:
51
+ | (Function & {
52
+ readonly prototype: ModelContext;
53
+ [Symbol.hasInstance](value: unknown): value is ModelContext;
54
+ })
55
+ | undefined;
56
+
86
57
  interface Document {
87
58
  /**
88
- * Web Model Context API strict core surface.
59
+ * Canonical WebMCP API for this document.
89
60
  *
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.
61
+ * Optional because no browser ships WebMCP unflagged: Chromium exposes it
62
+ * only under `--enable-features=WebMCP`, and elsewhere the property is
63
+ * genuinely absent (`'modelContext' in document === false`). Feature-detect
64
+ * it, or install `@mcp-b/webmcp-polyfill`.
93
65
  */
94
- readonly modelContext: ModelContext;
66
+ readonly modelContext?: ModelContext;
95
67
  }
96
68
 
97
69
  interface Navigator {
70
+ /** @deprecated Use `document.modelContext`. */
71
+ readonly modelContext?: ModelContext;
72
+
73
+ /** @deprecated Compatibility surface for older Chromium previews. */
74
+ modelContextTesting?: ModelContextTesting;
75
+ }
76
+
77
+ interface SubmitEvent {
98
78
  /**
99
- * Web Model Context API strict core surface.
79
+ * True when a declarative WebMCP tool initiated this submission.
100
80
  *
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.
81
+ * Optional because declarative forms are explainer-only: this attribute is
82
+ * in neither the WebMCP specification nor WPT's `webmcp.idl`, and no
83
+ * browser implements it. `@mcp-b/webmcp-polyfill` installs it.
105
84
  */
106
- readonly modelContext: ModelContext;
85
+ readonly agentInvoked?: boolean;
107
86
 
108
87
  /**
109
- * Web Model Context testing API surface (Chromium early preview).
110
- * @deprecated Chromium still exposes this API for testing flows. Producer
111
- * discovery/execution should prefer document.modelContext.getTools() and
112
- * document.modelContext.executeTool(...).
88
+ * Associates an intercepted form submission result with the invoking agent.
89
+ *
90
+ * Optional for the same reason as {@link SubmitEvent.agentInvoked}.
113
91
  */
114
- modelContextTesting?: ModelContextTesting;
92
+ respondWith?(agentResponse: Promise<unknown>): void;
115
93
  }
116
94
  }