@mcp-b/webmcp-types 0.0.0-beta-20260216200013

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 ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@mcp-b/webmcp-types",
3
+ "version": "0.0.0-beta-20260216200013",
4
+ "description": "Strict TypeScript type definitions for the WebMCP core API (navigator.modelContext)",
5
+ "keywords": [
6
+ "webmcp",
7
+ "model-context",
8
+ "navigator-modelcontext",
9
+ "types",
10
+ "typescript",
11
+ "web-standard"
12
+ ],
13
+ "homepage": "https://docs.mcp-b.ai/packages/webmcp-types",
14
+ "bugs": {
15
+ "url": "https://github.com/WebMCP-org/npm-packages/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/WebMCP-org/npm-packages.git",
20
+ "directory": "packages/webmcp-types"
21
+ },
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
+ "files": [
34
+ "dist",
35
+ "src/common.ts",
36
+ "src/index.ts",
37
+ "src/json-schema.ts",
38
+ "src/model-context.ts",
39
+ "src/tool.ts"
40
+ ],
41
+ "devDependencies": {
42
+ "@vitest/browser": "^4.0.18",
43
+ "@vitest/browser-playwright": "^4.0.18",
44
+ "@vitest/coverage-v8": "^4.0.18",
45
+ "playwright": "^1.58.0",
46
+ "typescript": "^5.8.3",
47
+ "vitest": "^4.0.18"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.build.json",
55
+ "check": "biome check --write .",
56
+ "clean": "rm -rf dist .turbo",
57
+ "format": "biome format --write .",
58
+ "lint": "biome lint --write .",
59
+ "publish:dry": "pnpm publish --access public --dry-run",
60
+ "publish:npm": "pnpm publish --access public",
61
+ "test": "vitest run && pnpm run test:conformance",
62
+ "test:browser": "vitest run --config vitest.browser.config.ts --browser.headless",
63
+ "test:browser:ui": "vitest --config vitest.browser.config.ts --browser",
64
+ "test:conformance": "vitest run --config vitest.conformance.config.ts",
65
+ "typecheck": "tsc --noEmit && vitest run --typecheck --silent"
66
+ }
67
+ }
package/src/common.ts ADDED
@@ -0,0 +1,368 @@
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
+ */
49
+ 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;
218
+ }
219
+
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?: JsonObject;
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
+ }
359
+
360
+ /**
361
+ * Registration handle returned by registration methods.
362
+ */
363
+ export interface RegistrationHandle {
364
+ /**
365
+ * Unregisters the associated item.
366
+ */
367
+ unregister: () => void;
368
+ }
package/src/index.ts ADDED
@@ -0,0 +1,95 @@
1
+ import type { ModelContext, ModelContextTesting } from './model-context.js';
2
+
3
+ // Re-export all public types
4
+ export type {
5
+ AudioContent,
6
+ BlobResourceContents,
7
+ CallToolResult,
8
+ ContentBlock,
9
+ ElicitationFormParams,
10
+ ElicitationParams,
11
+ ElicitationResult,
12
+ ElicitationUrlParams,
13
+ EmbeddedResource,
14
+ ImageContent,
15
+ InputSchema,
16
+ InputSchemaProperty,
17
+ JsonObject,
18
+ JsonPrimitive,
19
+ JsonValue,
20
+ LooseContentBlock,
21
+ RegistrationHandle,
22
+ ResourceContents,
23
+ ResourceLink,
24
+ TextContent,
25
+ TextResourceContents,
26
+ ToolResponse,
27
+ } from './common.js';
28
+ export type {
29
+ InferArgsFromInputSchema,
30
+ InferJsonSchema,
31
+ JsonSchemaArray,
32
+ JsonSchemaBoolean,
33
+ JsonSchemaEnumValue,
34
+ JsonSchemaForInference,
35
+ JsonSchemaMultiType,
36
+ JsonSchemaNull,
37
+ JsonSchemaNumber,
38
+ JsonSchemaObject,
39
+ JsonSchemaPrimitiveType,
40
+ JsonSchemaString,
41
+ JsonSchemaType,
42
+ JsonSchemaTypeArray,
43
+ } from './json-schema.js';
44
+ export type {
45
+ AnyToolDescriptor,
46
+ InferToolArgs,
47
+ InferToolResult,
48
+ ModelContext,
49
+ ModelContextCore,
50
+ ModelContextExtensions,
51
+ ModelContextInput,
52
+ ModelContextOptions,
53
+ ModelContextTesting,
54
+ ModelContextTestingExecuteToolOptions,
55
+ ModelContextTestingPolyfillExtensions,
56
+ ModelContextTestingToolInfo,
57
+ ModelContextWithExtensions,
58
+ ToolArgsByName,
59
+ ToolByName,
60
+ ToolCallEvent,
61
+ ToolCallParams,
62
+ ToolName,
63
+ ToolResultByName,
64
+ TypedModelContext,
65
+ } from './model-context.js';
66
+ export type {
67
+ MaybePromise,
68
+ ModelContextClient,
69
+ ToolAnnotations,
70
+ ToolDescriptor,
71
+ ToolDescriptorFromSchema,
72
+ ToolExecutionContext,
73
+ ToolListItem,
74
+ ToolResultFromOutputSchema,
75
+ } from './tool.js';
76
+
77
+ // ============================================================================
78
+ // Global Augmentation
79
+ // ============================================================================
80
+
81
+ declare global {
82
+ interface Navigator {
83
+ /**
84
+ * Web Model Context API strict core surface.
85
+ */
86
+ modelContext: ModelContext;
87
+
88
+ /**
89
+ * Web Model Context testing API surface (Chromium early preview).
90
+ * @deprecated Prefer navigator.modelContext.callTool(...) and toolschanged events
91
+ * for in-page consumers. Chromium still exposes this API for testing flows.
92
+ */
93
+ modelContextTesting?: ModelContextTesting;
94
+ }
95
+ }