@mcp-b/global 1.1.2 → 1.1.3-beta.2

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/dist/index.d.ts CHANGED
@@ -1,55 +1,124 @@
1
1
  import { IframeChildTransportOptions, TabServerTransportOptions } from "@mcp-b/transports";
2
- import { CallToolResult, Server, ToolAnnotations, Transport } from "@mcp-b/webmcp-ts-sdk";
2
+ import { CallToolResult, CreateMessageRequest, CreateMessageResult, ElicitRequest, ElicitResult, Prompt, PromptMessage, Resource, ResourceContents, ResourceTemplate, Server, ToolAnnotations, Transport } from "@mcp-b/webmcp-ts-sdk";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region src/types.d.ts
6
6
 
7
7
  /**
8
- * JSON Schema definition for tool input parameters
8
+ * JSON Schema definition for tool/prompt input parameters.
9
+ *
10
+ * This interface represents a JSON Schema object as defined by the JSON Schema
11
+ * specification. It's used for defining tool input schemas and prompt argument
12
+ * schemas when not using Zod.
13
+ *
14
+ * @see {@link https://json-schema.org/}
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const schema: InputSchema = {
19
+ * type: 'object',
20
+ * properties: {
21
+ * query: { type: 'string', description: 'Search query' },
22
+ * limit: { type: 'number', description: 'Max results' }
23
+ * },
24
+ * required: ['query']
25
+ * };
26
+ * ```
9
27
  */
10
28
  interface InputSchema {
29
+ /** The JSON Schema type (typically "object" for tool inputs) */
11
30
  type: string;
31
+ /** Property definitions for object schemas */
12
32
  properties?: Record<string, {
33
+ /** The property type */
13
34
  type: string;
35
+ /** Human-readable description of the property */
14
36
  description?: string;
37
+ /** Additional JSON Schema keywords */
15
38
  [key: string]: unknown;
16
39
  }>;
40
+ /** Array of required property names */
17
41
  required?: string[];
42
+ /** Additional JSON Schema keywords */
18
43
  [key: string]: unknown;
19
44
  }
20
45
  /**
21
- * Zod schema object type (Record<string, ZodType>)
22
- * Used for type-safe tool definitions
46
+ * Zod schema object type for type-safe tool and prompt definitions.
47
+ *
48
+ * When using Zod schemas instead of JSON Schema, define your schema as an object
49
+ * where keys are parameter names and values are Zod type definitions.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { z } from 'zod';
54
+ *
55
+ * const mySchema: ZodSchemaObject = {
56
+ * query: z.string().describe('Search query'),
57
+ * limit: z.number().optional().describe('Max results')
58
+ * };
59
+ * ```
23
60
  */
24
61
  type ZodSchemaObject = Record<string, z.ZodTypeAny>;
25
62
  /**
26
- * Tool response format (Web API version)
27
- * This is compatible with MCP SDK's CallToolResult
63
+ * Tool response format for the Web Model Context API.
64
+ * This is an alias for MCP SDK's CallToolResult for API consistency.
65
+ * @see {@link CallToolResult}
28
66
  */
29
67
  type ToolResponse = CallToolResult;
30
68
  /**
31
69
  * Transport configuration for initializing the Web Model Context polyfill.
70
+ *
71
+ * The polyfill supports multiple transport modes:
72
+ * - **Custom transport**: Provide your own MCP transport implementation
73
+ * - **Tab server**: Same-window communication via postMessage
74
+ * - **Iframe server**: Parent-child iframe communication
75
+ *
76
+ * @example Custom transport
77
+ * ```typescript
78
+ * const config: TransportConfiguration = {
79
+ * create: () => new MyCustomTransport()
80
+ * };
81
+ * ```
82
+ *
83
+ * @example Configure allowed origins
84
+ * ```typescript
85
+ * const config: TransportConfiguration = {
86
+ * tabServer: { allowedOrigins: ['https://example.com'] },
87
+ * iframeServer: false // disable iframe server
88
+ * };
89
+ * ```
32
90
  */
33
91
  interface TransportConfiguration {
34
92
  /**
35
- * Provide a custom transport factory. When set, tabServer and iframeServer options are ignored.
93
+ * Provide a custom transport factory.
94
+ * When set, tabServer and iframeServer options are ignored.
36
95
  */
37
96
  create?: () => Transport;
38
97
  /**
39
98
  * Options passed to the built-in TabServerTransport when no custom factory is provided.
40
- * Set to false to disable the tab server.
41
- * Default: enabled with allowedOrigins: ['*']
99
+ * Set to `false` to disable the tab server.
100
+ * @default { allowedOrigins: ['*'] }
42
101
  */
43
102
  tabServer?: Partial<TabServerTransportOptions> | false;
44
103
  /**
45
104
  * Options passed to the built-in IframeChildTransport when no custom factory is provided.
46
- * Set to false to disable the iframe server.
47
- * Default: auto-enabled when running in an iframe (window.parent !== window)
105
+ * Set to `false` to disable the iframe server.
106
+ * @default Auto-enabled when `window.parent !== window`
48
107
  */
49
108
  iframeServer?: Partial<IframeChildTransportOptions> | false;
50
109
  }
51
110
  /**
52
111
  * Initialization options for the Web Model Context polyfill.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * initializeWebModelContext({
116
+ * autoInitialize: true,
117
+ * transport: {
118
+ * tabServer: { allowedOrigins: ['https://trusted.com'] }
119
+ * }
120
+ * });
121
+ * ```
53
122
  */
54
123
  interface WebModelContextInitOptions {
55
124
  /**
@@ -57,18 +126,51 @@ interface WebModelContextInitOptions {
57
126
  */
58
127
  transport?: TransportConfiguration;
59
128
  /**
60
- * When set to false, automatic initialization on module load is skipped.
129
+ * When set to `false`, automatic initialization on module load is skipped.
130
+ * Useful when you need to configure options before initialization.
131
+ * @default true
61
132
  */
62
133
  autoInitialize?: boolean;
63
134
  }
64
135
  /**
65
- * Tool descriptor for Web Model Context API
66
- * Extended with full MCP protocol support
136
+ * Tool descriptor for the Web Model Context API.
67
137
  *
68
- * Supports both JSON Schema (Web standard) and Zod schemas (type-safe)
138
+ * Tools are functions that AI models can call to perform actions or retrieve
139
+ * information. This interface supports both JSON Schema (Web standard) and
140
+ * Zod schemas (type-safe) for input/output validation.
141
+ *
142
+ * @template TInputSchema - Zod schema object type for input type inference
143
+ * @template TOutputSchema - Zod schema object type for output type inference
144
+ *
145
+ * @see {@link https://spec.modelcontextprotocol.io/specification/server/tools/}
146
+ *
147
+ * @example JSON Schema
148
+ * ```typescript
149
+ * const tool: ToolDescriptor = {
150
+ * name: 'search',
151
+ * description: 'Search the web',
152
+ * inputSchema: {
153
+ * type: 'object',
154
+ * properties: { query: { type: 'string' } },
155
+ * required: ['query']
156
+ * },
157
+ * execute: async ({ query }) => ({
158
+ * content: [{ type: 'text', text: `Results for: ${query}` }]
159
+ * })
160
+ * };
161
+ * ```
69
162
  *
70
- * @template TInputSchema - If using Zod, the schema object type for type inference
71
- * @template TOutputSchema - If using Zod, the output schema object type
163
+ * @example Zod Schema (type-safe)
164
+ * ```typescript
165
+ * const tool: ToolDescriptor<{ query: z.ZodString }> = {
166
+ * name: 'search',
167
+ * description: 'Search the web',
168
+ * inputSchema: { query: z.string() },
169
+ * execute: async ({ query }) => ({ // query is typed as string
170
+ * content: [{ type: 'text', text: `Results for: ${query}` }]
171
+ * })
172
+ * };
173
+ * ```
72
174
  */
73
175
  interface ToolDescriptor<TInputSchema extends ZodSchemaObject = Record<string, never>, TOutputSchema extends ZodSchemaObject = Record<string, never>> {
74
176
  /**
@@ -106,9 +208,10 @@ interface ToolDescriptor<TInputSchema extends ZodSchemaObject = Record<string, n
106
208
  execute: (args: TInputSchema extends Record<string, never> ? Record<string, unknown> : z.infer<z.ZodObject<TInputSchema>>) => Promise<ToolResponse>;
107
209
  }
108
210
  /**
109
- * Internal validated tool descriptor (used internally by the bridge)
110
- * Always stores JSON Schema format for MCP protocol
111
- * Plus Zod validators for runtime validation
211
+ * Internal validated tool descriptor (used internally by the bridge).
212
+ * Always stores JSON Schema format for MCP protocol compatibility,
213
+ * plus Zod validators for runtime validation.
214
+ * @internal
112
215
  */
113
216
  interface ValidatedToolDescriptor {
114
217
  name: string;
@@ -117,19 +220,349 @@ interface ValidatedToolDescriptor {
117
220
  outputSchema?: InputSchema;
118
221
  annotations?: ToolAnnotations;
119
222
  execute: (args: Record<string, unknown>) => Promise<ToolResponse>;
223
+ /** Zod validator for input arguments (not exposed via MCP) */
120
224
  inputValidator: z.ZodType;
225
+ /** Zod validator for output (not exposed via MCP) */
121
226
  outputValidator?: z.ZodType;
122
227
  }
123
228
  /**
124
- * Context provided to models via provideContext()
125
- * Contains the base set of tools (Bucket A)
229
+ * Resource descriptor for Web Model Context API
230
+ * Defines a resource that can be read by AI models
231
+ *
232
+ * Resources can be:
233
+ * - Static: Fixed URI like "config://app-settings"
234
+ * - Dynamic: URI template like "file://{path}" where {path} is a parameter
235
+ *
236
+ * @example Static resource
237
+ * ```typescript
238
+ * const configResource: ResourceDescriptor = {
239
+ * uri: 'config://app-settings',
240
+ * name: 'App Settings',
241
+ * description: 'Application configuration',
242
+ * mimeType: 'application/json',
243
+ * read: async (uri) => ({
244
+ * contents: [{ uri: uri.href, text: JSON.stringify(config) }]
245
+ * })
246
+ * };
247
+ * ```
248
+ *
249
+ * @example Dynamic resource with URI template
250
+ * ```typescript
251
+ * const fileResource: ResourceDescriptor = {
252
+ * uri: 'file://{path}',
253
+ * name: 'File Reader',
254
+ * description: 'Read files from the virtual filesystem',
255
+ * read: async (uri, params) => ({
256
+ * contents: [{ uri: uri.href, text: await readFile(params?.path ?? '') }]
257
+ * })
258
+ * };
259
+ * ```
260
+ */
261
+ interface ResourceDescriptor {
262
+ /**
263
+ * The resource URI or URI template
264
+ * - Static: "config://app-settings"
265
+ * - Template: "file://{path}" where {path} becomes a parameter
266
+ */
267
+ uri: string;
268
+ /**
269
+ * Human-readable name for the resource
270
+ */
271
+ name: string;
272
+ /**
273
+ * Optional description of what the resource provides
274
+ */
275
+ description?: string;
276
+ /**
277
+ * Optional MIME type of the resource content
278
+ */
279
+ mimeType?: string;
280
+ /**
281
+ * Function that reads and returns the resource content
282
+ *
283
+ * @param uri - The resolved URI being requested
284
+ * @param params - Parameters extracted from URI template (if applicable)
285
+ * @returns Resource contents with the data
286
+ */
287
+ read: (uri: URL, params?: Record<string, string>) => Promise<{
288
+ contents: ResourceContents[];
289
+ }>;
290
+ }
291
+ /**
292
+ * Internal validated resource descriptor (used internally by the bridge).
293
+ * @internal
294
+ */
295
+ interface ValidatedResourceDescriptor {
296
+ uri: string;
297
+ name: string;
298
+ description: string | undefined;
299
+ mimeType: string | undefined;
300
+ read: (uri: URL, params?: Record<string, string>) => Promise<{
301
+ contents: ResourceContents[];
302
+ }>;
303
+ /** Whether this is a URI template (contains {param} placeholders) */
304
+ isTemplate: boolean;
305
+ /** Parameter names extracted from URI template (e.g., ['path'] for 'file://{path}') */
306
+ templateParams: string[];
307
+ }
308
+ /**
309
+ * Prompt descriptor for Web Model Context API
310
+ * Defines a reusable prompt template for AI interactions
311
+ *
312
+ * Prompts help users interact with AI models by providing
313
+ * pre-defined message templates. They can accept arguments
314
+ * to customize the prompt dynamically.
315
+ *
316
+ * @template TArgsSchema - If using Zod, the schema object type for argument inference
317
+ *
318
+ * @example Simple prompt without arguments
319
+ * ```typescript
320
+ * const helpPrompt: PromptDescriptor = {
321
+ * name: 'help',
322
+ * description: 'Get help with using the application',
323
+ * get: async () => ({
324
+ * messages: [{
325
+ * role: 'user',
326
+ * content: { type: 'text', text: 'How do I use this application?' }
327
+ * }]
328
+ * })
329
+ * };
330
+ * ```
331
+ *
332
+ * @example Prompt with typed arguments
333
+ * ```typescript
334
+ * const reviewPrompt: PromptDescriptor<{ code: z.ZodString }> = {
335
+ * name: 'review-code',
336
+ * description: 'Review code for best practices',
337
+ * argsSchema: { code: z.string() },
338
+ * get: async ({ code }) => ({
339
+ * messages: [{
340
+ * role: 'user',
341
+ * content: { type: 'text', text: `Please review this code:\n\n${code}` }
342
+ * }]
343
+ * })
344
+ * };
345
+ * ```
346
+ */
347
+ interface PromptDescriptor<TArgsSchema extends ZodSchemaObject = Record<string, never>> {
348
+ /**
349
+ * Unique identifier for the prompt
350
+ */
351
+ name: string;
352
+ /**
353
+ * Optional description of what the prompt does
354
+ */
355
+ description?: string;
356
+ /**
357
+ * Optional schema for prompt arguments
358
+ * Accepts EITHER:
359
+ * - JSON Schema object: { type: "object", properties: {...} }
360
+ * - Zod schema object: { code: z.string(), language: z.enum([...]) }
361
+ */
362
+ argsSchema?: InputSchema | TArgsSchema;
363
+ /**
364
+ * Function that generates prompt messages
365
+ *
366
+ * @param args - Arguments matching the argsSchema (if defined)
367
+ * @returns Object containing the prompt messages
368
+ */
369
+ get: (args: TArgsSchema extends Record<string, never> ? Record<string, unknown> : z.infer<z.ZodObject<TArgsSchema>>) => Promise<{
370
+ messages: PromptMessage[];
371
+ }>;
372
+ }
373
+ /**
374
+ * Internal validated prompt descriptor (used internally by the bridge).
375
+ * @internal
376
+ */
377
+ interface ValidatedPromptDescriptor {
378
+ name: string;
379
+ description: string | undefined;
380
+ argsSchema: InputSchema | undefined;
381
+ get: (args: Record<string, unknown>) => Promise<{
382
+ messages: PromptMessage[];
383
+ }>;
384
+ /** Zod validator for arguments (not exposed via MCP) */
385
+ argsValidator: z.ZodType | undefined;
386
+ }
387
+ /**
388
+ * Tool information returned by listTools().
389
+ * Provides metadata about a registered tool without exposing the execute function.
390
+ */
391
+ interface ToolListItem {
392
+ /** Unique identifier for the tool */
393
+ name: string;
394
+ /** Natural language description of what the tool does */
395
+ description: string;
396
+ /** JSON Schema for tool input parameters */
397
+ inputSchema: InputSchema;
398
+ /** Optional JSON Schema for tool output */
399
+ outputSchema?: InputSchema;
400
+ /** Optional annotations providing hints about tool behavior */
401
+ annotations?: ToolAnnotations;
402
+ }
403
+ /**
404
+ * Resource template information returned by listResourceTemplates().
405
+ * Describes a dynamic resource with URI template parameters.
406
+ */
407
+ interface ResourceTemplateInfo {
408
+ /** The URI template (e.g., 'file://{path}') */
409
+ uriTemplate: string;
410
+ /** Human-readable name for the resource */
411
+ name: string;
412
+ /** Optional description of what the resource provides */
413
+ description?: string;
414
+ /** Optional MIME type of the resource content */
415
+ mimeType?: string;
416
+ }
417
+ /**
418
+ * Registration handle returned by registerTool, registerResource, registerPrompt.
419
+ * Provides a method to unregister the item.
420
+ */
421
+ interface RegistrationHandle {
422
+ /** Unregister the item, removing it from the context */
423
+ unregister: () => void;
424
+ }
425
+ /**
426
+ * Parameters for a sampling request from the server.
427
+ * Extracted from CreateMessageRequest for handler convenience.
428
+ */
429
+ interface SamplingRequestParams {
430
+ /** Messages to send to the LLM */
431
+ messages: Array<{
432
+ role: 'user' | 'assistant';
433
+ content: {
434
+ type: 'text';
435
+ text: string;
436
+ } | {
437
+ type: 'image';
438
+ data: string;
439
+ mimeType: string;
440
+ } | Array<{
441
+ type: 'text';
442
+ text: string;
443
+ } | {
444
+ type: 'image';
445
+ data: string;
446
+ mimeType: string;
447
+ }>;
448
+ }>;
449
+ /** Optional system prompt */
450
+ systemPrompt?: string | undefined;
451
+ /** Maximum tokens to generate */
452
+ maxTokens: number;
453
+ /** Optional temperature for sampling */
454
+ temperature?: number | undefined;
455
+ /** Optional stop sequences */
456
+ stopSequences?: string[] | undefined;
457
+ /** Optional model preferences */
458
+ modelPreferences?: {
459
+ hints?: Array<{
460
+ name?: string;
461
+ }>;
462
+ costPriority?: number;
463
+ speedPriority?: number;
464
+ intelligencePriority?: number;
465
+ } | undefined;
466
+ /** Optional context inclusion setting */
467
+ includeContext?: 'none' | 'thisServer' | 'allServers' | undefined;
468
+ /** Optional metadata */
469
+ metadata?: Record<string, unknown> | undefined;
470
+ }
471
+ /**
472
+ * Result of a sampling request.
473
+ * Returned by the sampling handler.
474
+ */
475
+ interface SamplingResult {
476
+ /** The model that generated the response */
477
+ model: string;
478
+ /** The generated content */
479
+ content: {
480
+ type: 'text';
481
+ text: string;
482
+ } | {
483
+ type: 'image';
484
+ data: string;
485
+ mimeType: string;
486
+ };
487
+ /** Role of the responder */
488
+ role: 'user' | 'assistant';
489
+ /** Reason for stopping generation */
490
+ stopReason?: 'endTurn' | 'stopSequence' | 'maxTokens' | string;
491
+ }
492
+ /**
493
+ * Parameters for a form elicitation request.
494
+ */
495
+ interface ElicitationFormParams {
496
+ /** Mode of elicitation */
497
+ mode?: 'form';
498
+ /** Message to show to the user */
499
+ message: string;
500
+ /** Schema for the form fields */
501
+ requestedSchema: {
502
+ type: 'object';
503
+ properties: Record<string, {
504
+ type: 'string' | 'number' | 'integer' | 'boolean';
505
+ title?: string;
506
+ description?: string;
507
+ default?: string | number | boolean;
508
+ minLength?: number;
509
+ maxLength?: number;
510
+ minimum?: number;
511
+ maximum?: number;
512
+ enum?: Array<string | number>;
513
+ enumNames?: string[];
514
+ format?: string;
515
+ }>;
516
+ required?: string[];
517
+ };
518
+ }
519
+ /**
520
+ * Parameters for a URL elicitation request.
521
+ */
522
+ interface ElicitationUrlParams {
523
+ /** Mode of elicitation */
524
+ mode: 'url';
525
+ /** Message explaining why the URL needs to be opened */
526
+ message: string;
527
+ /** Unique identifier for this elicitation */
528
+ elicitationId: string;
529
+ /** URL to open */
530
+ url: string;
531
+ }
532
+ /**
533
+ * Parameters for an elicitation request.
534
+ * Can be either form-based or URL-based.
535
+ */
536
+ type ElicitationParams = ElicitationFormParams | ElicitationUrlParams;
537
+ /**
538
+ * Result of an elicitation request.
539
+ */
540
+ interface ElicitationResult {
541
+ /** User action */
542
+ action: 'accept' | 'decline' | 'cancel';
543
+ /** Content returned when action is 'accept' */
544
+ content?: Record<string, string | number | boolean | string[]>;
545
+ }
546
+ /**
547
+ * Context provided to models via provideContext().
548
+ * Contains the base set of tools, resources, and prompts (Bucket A).
126
549
  */
127
550
  interface ModelContextInput {
128
551
  /**
129
552
  * Array of tool descriptors
130
553
  * Supports both JSON Schema and Zod schema formats
131
554
  */
132
- tools: ToolDescriptor[];
555
+ tools?: ToolDescriptor[];
556
+ /**
557
+ * Array of resource descriptors
558
+ * Resources expose data that AI models can read
559
+ */
560
+ resources?: ResourceDescriptor[];
561
+ /**
562
+ * Array of prompt descriptors
563
+ * Prompts provide reusable message templates
564
+ */
565
+ prompts?: PromptDescriptor[];
133
566
  }
134
567
  /**
135
568
  * Tool call event
@@ -154,29 +587,110 @@ interface ToolCallEvent extends Event {
154
587
  */
155
588
  interface ModelContext {
156
589
  /**
157
- * Provide context (tools) to AI models
158
- * Clears base tools (Bucket A) and replaces with the provided array.
159
- * Dynamic tools (Bucket B) registered via registerTool() persist.
590
+ * Provide context (tools, resources, prompts) to AI models
591
+ * Clears base items (Bucket A) and replaces with the provided arrays.
592
+ * Dynamic items (Bucket B) registered via register* methods persist.
160
593
  */
161
594
  provideContext(context: ModelContextInput): void;
162
595
  /**
163
- * Register a single tool dynamically
164
- * Returns an object with an unregister function to remove the tool
165
- * Supports both JSON Schema and Zod schema formats
596
+ * Register a single tool dynamically.
597
+ * Returns a handle to unregister the tool.
598
+ * Supports both JSON Schema and Zod schema formats.
166
599
  */
167
- registerTool<TInputSchema extends ZodSchemaObject = Record<string, never>, TOutputSchema extends ZodSchemaObject = Record<string, never>>(tool: ToolDescriptor<TInputSchema, TOutputSchema>): {
168
- unregister: () => void;
169
- };
600
+ registerTool<TInputSchema extends ZodSchemaObject = Record<string, never>, TOutputSchema extends ZodSchemaObject = Record<string, never>>(tool: ToolDescriptor<TInputSchema, TOutputSchema>): RegistrationHandle;
170
601
  /**
171
602
  * Unregister a tool by name
172
603
  * Available in Chromium's native implementation
173
604
  */
174
605
  unregisterTool(name: string): void;
175
606
  /**
176
- * Clear all registered tools (both buckets)
607
+ * Get the list of all registered tools.
608
+ * Returns tools from both buckets (provideContext and registerTool).
609
+ */
610
+ listTools(): ToolListItem[];
611
+ /**
612
+ * Register a single resource dynamically.
613
+ * Returns a handle to unregister the resource.
614
+ */
615
+ registerResource(resource: ResourceDescriptor): RegistrationHandle;
616
+ /**
617
+ * Unregister a resource by URI
618
+ */
619
+ unregisterResource(uri: string): void;
620
+ /**
621
+ * Get the list of all registered resources
622
+ * Returns resources from both buckets (provideContext and registerResource)
623
+ */
624
+ listResources(): Resource[];
625
+ /**
626
+ * Get the list of all resource templates.
627
+ * Returns only resources with URI templates (dynamic resources).
628
+ */
629
+ listResourceTemplates(): ResourceTemplateInfo[];
630
+ /**
631
+ * Register a single prompt dynamically.
632
+ * Returns a handle to unregister the prompt.
633
+ * Supports both JSON Schema and Zod schema formats for argsSchema.
634
+ */
635
+ registerPrompt<TArgsSchema extends ZodSchemaObject = Record<string, never>>(prompt: PromptDescriptor<TArgsSchema>): RegistrationHandle;
636
+ /**
637
+ * Unregister a prompt by name
638
+ */
639
+ unregisterPrompt(name: string): void;
640
+ /**
641
+ * Get the list of all registered prompts
642
+ * Returns prompts from both buckets (provideContext and registerPrompt)
643
+ */
644
+ listPrompts(): Prompt[];
645
+ /**
646
+ * Clear all registered context (tools, resources, prompts from both buckets)
177
647
  * Available in Chromium's native implementation
178
648
  */
179
649
  clearContext(): void;
650
+ /**
651
+ * Request an LLM completion from the connected client.
652
+ * This allows the server (webpage) to request sampling from the client (AI agent).
653
+ *
654
+ * @param params - Parameters for the sampling request
655
+ * @returns Promise resolving to the LLM completion result
656
+ *
657
+ * @example
658
+ * ```typescript
659
+ * const result = await navigator.modelContext.createMessage({
660
+ * messages: [
661
+ * { role: 'user', content: { type: 'text', text: 'What is 2+2?' } }
662
+ * ],
663
+ * maxTokens: 100,
664
+ * });
665
+ * console.log(result.content); // { type: 'text', text: '4' }
666
+ * ```
667
+ */
668
+ createMessage(params: SamplingRequestParams): Promise<SamplingResult>;
669
+ /**
670
+ * Request user input from the connected client.
671
+ * This allows the server (webpage) to request form data or URL navigation from the client.
672
+ *
673
+ * @param params - Parameters for the elicitation request
674
+ * @returns Promise resolving to the user's response
675
+ *
676
+ * @example Form elicitation:
677
+ * ```typescript
678
+ * const result = await navigator.modelContext.elicitInput({
679
+ * message: 'Please provide your API key',
680
+ * requestedSchema: {
681
+ * type: 'object',
682
+ * properties: {
683
+ * apiKey: { type: 'string', title: 'API Key', description: 'Your API key' }
684
+ * },
685
+ * required: ['apiKey']
686
+ * }
687
+ * });
688
+ * if (result.action === 'accept') {
689
+ * console.log(result.content?.apiKey);
690
+ * }
691
+ * ```
692
+ */
693
+ elicitInput(params: ElicitationParams): Promise<ElicitationResult>;
180
694
  /**
181
695
  * Add event listener for tool calls
182
696
  */
@@ -189,21 +703,11 @@ interface ModelContext {
189
703
  * Dispatch an event
190
704
  */
191
705
  dispatchEvent(event: Event): boolean;
192
- /**
193
- * Get the list of all registered tools
194
- * Returns tools from both buckets (provideContext and registerTool)
195
- */
196
- listTools(): Array<{
197
- name: string;
198
- description: string;
199
- inputSchema: InputSchema;
200
- outputSchema?: InputSchema;
201
- annotations?: ToolAnnotations;
202
- }>;
203
706
  }
204
707
  /**
205
- * Internal ModelContext interface with additional methods for MCP bridge
206
- * Not exposed as part of the public Web Model Context API
708
+ * Internal ModelContext interface with additional methods for MCP bridge.
709
+ * Not exposed as part of the public Web Model Context API.
710
+ * @internal
207
711
  */
208
712
  interface InternalModelContext extends ModelContext {
209
713
  /**
@@ -211,21 +715,47 @@ interface InternalModelContext extends ModelContext {
211
715
  * @internal
212
716
  */
213
717
  executeTool(toolName: string, args: Record<string, unknown>): Promise<ToolResponse>;
718
+ /**
719
+ * Read a resource by URI (internal use only by MCP bridge)
720
+ * @internal
721
+ */
722
+ readResource(uri: string): Promise<{
723
+ contents: ResourceContents[];
724
+ }>;
725
+ /**
726
+ * Get a prompt with arguments (internal use only by MCP bridge)
727
+ * @internal
728
+ */
729
+ getPrompt(name: string, args?: Record<string, unknown>): Promise<{
730
+ messages: PromptMessage[];
731
+ }>;
214
732
  }
215
733
  /**
216
- * Internal MCP Bridge state
734
+ * Internal MCP Bridge state.
735
+ * Contains the MCP servers and registered context items.
736
+ * @internal
217
737
  */
218
738
  interface MCPBridge {
739
+ /** The main tab server transport */
219
740
  tabServer: Server;
741
+ /** Optional iframe server transport */
220
742
  iframeServer?: Server;
743
+ /** Map of tool name -> validated tool descriptor */
221
744
  tools: Map<string, ValidatedToolDescriptor>;
745
+ /** Map of resource URI -> validated resource descriptor */
746
+ resources: Map<string, ValidatedResourceDescriptor>;
747
+ /** Map of prompt name -> validated prompt descriptor */
748
+ prompts: Map<string, ValidatedPromptDescriptor>;
749
+ /** The internal model context instance */
222
750
  modelContext: InternalModelContext;
751
+ /** Optional testing API instance */
223
752
  modelContextTesting?: ModelContextTesting;
753
+ /** Whether the bridge has been initialized */
224
754
  isInitialized: boolean;
225
755
  }
226
756
  /**
227
- * Tool info returned by listTools() in testing API
228
- * Note: inputSchema is a JSON string, not an object (matches Chromium implementation)
757
+ * Tool info returned by listTools() in the testing API.
758
+ * Note: inputSchema is a JSON string, not an object (matches Chromium implementation).
229
759
  */
230
760
  interface ToolInfo {
231
761
  name: string;
@@ -377,5 +907,15 @@ declare function initializeWebModelContext(options?: WebModelContextInitOptions)
377
907
  */
378
908
  declare function cleanupWebModelContext(): void;
379
909
  //#endregion
380
- export { type CallToolResult, InputSchema, InternalModelContext, MCPBridge, ModelContext, ModelContextInput, ModelContextTesting, type ToolAnnotations, ToolCallEvent, ToolDescriptor, ToolInfo, ToolResponse, TransportConfiguration, ValidatedToolDescriptor, WebModelContextInitOptions, ZodSchemaObject, cleanupWebModelContext, initializeWebModelContext };
910
+ //#region src/validation.d.ts
911
+ /**
912
+ * Convert Zod schema object to JSON Schema
913
+ * Uses zod-to-json-schema package for comprehensive conversion
914
+ *
915
+ * @param schema - Record of Zod type definitions (e.g., { name: z.string(), age: z.number() })
916
+ * @returns JSON Schema object compatible with MCP InputSchema
917
+ */
918
+ declare function zodToJsonSchema(schema: Record<string, z.ZodTypeAny>): InputSchema;
919
+ //#endregion
920
+ export { type CallToolResult, type CreateMessageRequest, type CreateMessageResult, type ElicitRequest, type ElicitResult, ElicitationFormParams, ElicitationParams, ElicitationResult, ElicitationUrlParams, InputSchema, InternalModelContext, MCPBridge, ModelContext, ModelContextInput, ModelContextTesting, type Prompt, PromptDescriptor, type PromptMessage, RegistrationHandle, type Resource, type ResourceContents, ResourceDescriptor, type ResourceTemplate, ResourceTemplateInfo, SamplingRequestParams, SamplingResult, type ToolAnnotations, ToolCallEvent, ToolDescriptor, ToolInfo, ToolListItem, ToolResponse, TransportConfiguration, ValidatedPromptDescriptor, ValidatedResourceDescriptor, ValidatedToolDescriptor, WebModelContextInitOptions, ZodSchemaObject, cleanupWebModelContext, initializeWebModelContext, zodToJsonSchema };
381
921
  //# sourceMappingURL=index.d.ts.map