tmcp 1.4.0 → 1.6.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.
@@ -1,271 +1,1532 @@
1
1
  /* eslint-disable jsdoc/no-undefined-types */
2
2
  import * as v from 'valibot';
3
+ export const LATEST_PROTOCOL_VERSION = '2025-06-18';
4
+ export const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = '2025-03-26';
5
+ export const SUPPORTED_PROTOCOL_VERSIONS = [
6
+ LATEST_PROTOCOL_VERSION,
7
+ '2025-03-26',
8
+ '2024-11-05',
9
+ '2024-10-07',
10
+ ];
11
+ /* JSON-RPC types */
12
+ export const JSONRPC_VERSION = '2.0';
13
+
14
+ export class McpError extends Error {
15
+ /**
16
+ * @param {number} code
17
+ * @param {string} message
18
+ */
19
+ constructor(code, message) {
20
+ super(`MCP error ${code}: ${message}`);
21
+ this.name = 'McpError';
22
+ }
23
+ }
24
+
25
+ /**
26
+ * A progress token, used to associate progress notifications with the original request.
27
+ */
28
+ export const ProgressTokenSchema = v.union([
29
+ v.string(),
30
+ v.pipe(v.number(), v.integer()),
31
+ ]);
32
+
33
+ /**
34
+ * An opaque token used to represent a cursor for pagination.
35
+ */
36
+ export const CursorSchema = v.string();
37
+
38
+ const RequestMetaSchema = v.looseObject({
39
+ /**
40
+ * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
41
+ */
42
+ progressToken: v.optional(ProgressTokenSchema),
43
+ });
44
+
45
+ const BaseRequestParamsSchema = v.looseObject({
46
+ _meta: v.optional(RequestMetaSchema),
47
+ });
48
+
49
+ export const RequestSchema = v.object({
50
+ method: v.string(),
51
+ params: v.optional(BaseRequestParamsSchema),
52
+ });
53
+
54
+ const BaseNotificationParamsSchema = v.looseObject({
55
+ /**
56
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
57
+ * for notes on _meta usage.
58
+ */
59
+ _meta: v.optional(v.looseObject({})),
60
+ });
61
+ export const NotificationSchema = v.object({
62
+ method: v.string(),
63
+ params: v.optional(BaseNotificationParamsSchema),
64
+ });
65
+ export const ResultSchema = v.looseObject({
66
+ /**
67
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
68
+ * for notes on _meta usage.
69
+ */
70
+ _meta: v.optional(v.looseObject({})),
71
+ });
72
+
73
+ /**
74
+ * A uniquely identifying ID for a request in JSON-RPC.
75
+ */
76
+ export const RequestIdSchema = v.union([
77
+ v.string(),
78
+ v.pipe(v.number(), v.integer()),
79
+ ]);
80
+
81
+ /**
82
+ * A request that expects a response.
83
+ */
84
+ export const JSONRPCRequestSchema = v.object({
85
+ jsonrpc: v.literal(JSONRPC_VERSION),
86
+ id: RequestIdSchema,
87
+ ...RequestSchema.entries,
88
+ });
89
+
90
+ /**
91
+ * A notification which does not expect a response.
92
+ */
93
+ export const JSONRPCNotificationSchema = v.object({
94
+ jsonrpc: v.literal(JSONRPC_VERSION),
95
+ ...NotificationSchema.entries,
96
+ });
97
+
98
+ /**
99
+ * A successful (non-error) response to a request.
100
+ */
101
+ export const JSONRPCResponseSchema = v.strictObject({
102
+ jsonrpc: v.literal(JSONRPC_VERSION),
103
+ id: RequestIdSchema,
104
+ result: ResultSchema,
105
+ });
106
+
107
+ /**
108
+ * A response to a request that indicates an error occurred.
109
+ */
110
+ export const JSONRPCErrorSchema = v.strictObject({
111
+ jsonrpc: v.literal(JSONRPC_VERSION),
112
+ id: RequestIdSchema,
113
+ error: v.object({
114
+ /**
115
+ * The error type that occurred.
116
+ */
117
+ code: v.pipe(v.number(), v.integer()),
118
+
119
+ /**
120
+ * A short description of the error. The message SHOULD be limited to a concise single sentence.
121
+ */
122
+ message: v.string(),
123
+
124
+ /**
125
+ * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
126
+ */
127
+ data: v.optional(v.unknown()),
128
+ }),
129
+ });
130
+ export const JSONRPCMessageSchema = v.union([
131
+ JSONRPCRequestSchema,
132
+ JSONRPCNotificationSchema,
133
+ JSONRPCResponseSchema,
134
+ JSONRPCErrorSchema,
135
+ ]);
136
+ /* Empty result */
137
+
138
+ /**
139
+ * A response that indicates success but carries no data.
140
+ */
141
+ export const EmptyResultSchema = v.strictObject({ ...ResultSchema.entries });
142
+ /* Cancellation */
143
+
144
+ /**
145
+ * This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
146
+ *
147
+ * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.
148
+ *
149
+ * This notification indicates that the result will be unused, so any associated processing SHOULD cease.
150
+ *
151
+ * A client MUST NOT attempt to cancel its `initialize` request.
152
+ */
153
+ export const CancelledNotificationSchema = v.looseObject({
154
+ ...NotificationSchema.entries,
155
+ method: v.literal('notifications/cancelled'),
156
+ params: v.looseObject({
157
+ ...BaseNotificationParamsSchema.entries,
158
+
159
+ /**
160
+ * The ID of the request to cancel.
161
+ *
162
+ * This MUST correspond to the ID of a request previously issued in the same direction.
163
+ */
164
+ requestId: RequestIdSchema,
165
+
166
+ /**
167
+ * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
168
+ */
169
+ reason: v.optional(v.string()),
170
+ }),
171
+ });
172
+ /* Base Metadata */
173
+
174
+ /**
175
+ * Base metadata interface for common properties across resources, tools, prompts, and implementations.
176
+ */
177
+ export const BaseMetadataSchema = v.looseObject({
178
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
179
+ name: v.string(),
180
+
181
+ /**
182
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
183
+ * even by those unfamiliar with domain-specific terminology.
184
+ *
185
+ * If not provided, the name should be used for display (except for Tool,
186
+ * where `annotations.title` should be given precedence over using `name`,
187
+ * if present).
188
+ */
189
+ title: v.optional(v.string()),
190
+ });
191
+ /* Initialization */
192
+
193
+ /**
194
+ * Describes the name and version of an MCP implementation.
195
+ */
196
+ export const ImplementationSchema = v.looseObject({
197
+ ...BaseMetadataSchema.entries,
198
+ version: v.string(),
199
+ });
200
+
201
+ /**
202
+ * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
203
+ */
204
+ export const ClientCapabilitiesSchema = v.looseObject({
205
+ /**
206
+ * Experimental, non-standard capabilities that the client supports.
207
+ */
208
+ experimental: v.optional(v.looseObject({})),
209
+
210
+ /**
211
+ * Present if the client supports sampling from an LLM.
212
+ */
213
+ sampling: v.optional(v.looseObject({})),
214
+
215
+ /**
216
+ * Present if the client supports eliciting user input.
217
+ */
218
+ elicitation: v.optional(v.looseObject({})),
219
+
220
+ /**
221
+ * Present if the client supports listing roots.
222
+ */
223
+ roots: v.optional(
224
+ v.looseObject({
225
+ /**
226
+ * Whether the client supports issuing notifications for changes to the roots list.
227
+ */
228
+ listChanged: v.optional(v.boolean()),
229
+ }),
230
+ ),
231
+ });
232
+
233
+ export const InitializeRequestParamsSchema = v.looseObject({
234
+ ...BaseRequestParamsSchema.entries,
235
+
236
+ /**
237
+ * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
238
+ */
239
+ protocolVersion: v.string(),
240
+ capabilities: ClientCapabilitiesSchema,
241
+ clientInfo: ImplementationSchema,
242
+ });
243
+
244
+ /**
245
+ * This request is sent from the client to the server when it first connects, asking it to begin initialization.
246
+ */
247
+ export const InitializeRequestSchema = v.looseObject({
248
+ ...RequestSchema.entries,
249
+ method: v.literal('initialize'),
250
+ params: InitializeRequestParamsSchema,
251
+ });
252
+
253
+ /**
254
+ * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
255
+ */
256
+ export const ServerCapabilitiesSchema = v.looseObject({
257
+ /**
258
+ * Experimental, non-standard capabilities that the server supports.
259
+ */
260
+ experimental: v.optional(v.looseObject({})),
261
+
262
+ /**
263
+ * Present if the server supports sending log messages to the client.
264
+ */
265
+ logging: v.optional(v.looseObject({})),
266
+
267
+ /**
268
+ * Present if the server supports sending completions to the client.
269
+ */
270
+ completions: v.optional(v.looseObject({})),
271
+
272
+ /**
273
+ * Present if the server offers any prompt templates.
274
+ */
275
+ prompts: v.optional(
276
+ v.looseObject({
277
+ /**
278
+ * Whether this server supports issuing notifications for changes to the prompt list.
279
+ */
280
+ listChanged: v.optional(v.boolean()),
281
+ }),
282
+ ),
283
+
284
+ /**
285
+ * Present if the server offers any resources to read.
286
+ */
287
+ resources: v.optional(
288
+ v.looseObject({
289
+ /**
290
+ * Whether this server supports clients subscribing to resource updates.
291
+ */
292
+ subscribe: v.optional(v.boolean()),
293
+
294
+ /**
295
+ * Whether this server supports issuing notifications for changes to the resource list.
296
+ */
297
+ listChanged: v.optional(v.boolean()),
298
+ }),
299
+ ),
300
+
301
+ /**
302
+ * Present if the server offers any tools to call.
303
+ */
304
+ tools: v.optional(
305
+ v.looseObject({
306
+ /**
307
+ * Whether this server supports issuing notifications for changes to the tool list.
308
+ */
309
+ listChanged: v.optional(v.boolean()),
310
+ }),
311
+ ),
312
+ });
313
+
314
+ /**
315
+ * After receiving an initialize request from the client, the server sends this response.
316
+ */
317
+ export const InitializeResultSchema = v.looseObject({
318
+ ...ResultSchema.entries,
319
+
320
+ /**
321
+ * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
322
+ */
323
+ protocolVersion: v.string(),
324
+ capabilities: ServerCapabilitiesSchema,
325
+ serverInfo: ImplementationSchema,
326
+
327
+ /**
328
+ * Instructions describing how to use the server and its features.
329
+ *
330
+ * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
331
+ */
332
+ instructions: v.optional(v.string()),
333
+ });
334
+
335
+ /**
336
+ * This notification is sent from the client to the server after initialization has finished.
337
+ */
338
+ export const InitializedNotificationSchema = v.looseObject({
339
+ ...NotificationSchema.entries,
340
+ method: v.literal('notifications/initialized'),
341
+ });
342
+ /* Ping */
343
+
344
+ /**
345
+ * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
346
+ */
347
+ export const PingRequestSchema = v.looseObject({
348
+ ...RequestSchema.entries,
349
+ method: v.literal('ping'),
350
+ });
351
+ /* Progress notifications */
352
+ export const ProgressSchema = v.looseObject({
353
+ /**
354
+ * The progress thus far. This should increase every time progress is made, even if the total is unknown.
355
+ */
356
+ progress: v.number(),
357
+
358
+ /**
359
+ * Total number of items to process (or total progress required), if known.
360
+ */
361
+ total: v.optional(v.number()),
362
+
363
+ /**
364
+ * An optional message describing the current progress.
365
+ */
366
+ message: v.optional(v.string()),
367
+ });
368
+
369
+ /**
370
+ * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
371
+ */
372
+ export const ProgressNotificationSchema = v.looseObject({
373
+ ...NotificationSchema.entries,
374
+ method: v.literal('notifications/progress'),
375
+ params: v.object({
376
+ ...BaseNotificationParamsSchema.entries,
377
+ ...ProgressSchema.entries,
378
+
379
+ /**
380
+ * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
381
+ */
382
+ progressToken: ProgressTokenSchema,
383
+ }),
384
+ });
385
+ /* Pagination */
386
+ export const PaginatedRequestSchema = v.looseObject({
387
+ ...RequestSchema.entries,
388
+ params: v.optional(
389
+ v.looseObject({
390
+ ...BaseRequestParamsSchema.entries,
391
+
392
+ /**
393
+ * An opaque token representing the current pagination position.
394
+ * If provided, the server should return results starting after this cursor.
395
+ */
396
+ cursor: v.optional(CursorSchema),
397
+ }),
398
+ ),
399
+ });
400
+ export const PaginatedResultSchema = v.looseObject({
401
+ ...ResultSchema.entries,
402
+
403
+ /**
404
+ * An opaque token representing the pagination position after the last returned result.
405
+ * If present, there may be more results available.
406
+ */
407
+ nextCursor: v.optional(CursorSchema),
408
+ });
409
+ /* Resources */
410
+
411
+ /**
412
+ * The contents of a specific resource or sub-resource.
413
+ */
414
+ export const ResourceContentsSchema = v.looseObject({
415
+ /**
416
+ * The URI of this resource.
417
+ */
418
+ uri: v.string(),
419
+
420
+ /**
421
+ * The MIME type of this resource, if known.
422
+ */
423
+ mimeType: v.optional(v.string()),
424
+
425
+ /**
426
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
427
+ * for notes on _meta usage.
428
+ */
429
+ _meta: v.optional(v.looseObject({})),
430
+ });
431
+ export const TextResourceContentsSchema = v.looseObject({
432
+ ...ResourceContentsSchema.entries,
433
+
434
+ /**
435
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
436
+ */
437
+ text: v.string(),
438
+ });
439
+ export const BlobResourceContentsSchema = v.looseObject({
440
+ ...ResourceContentsSchema.entries,
441
+
442
+ /**
443
+ * A base64-encoded string representing the binary data of the item.
444
+ */
445
+ blob: v.pipe(v.string(), v.base64()),
446
+ });
447
+
448
+ /**
449
+ * A known resource that the server is capable of reading.
450
+ */
451
+ export const ResourceSchema = v.looseObject({
452
+ ...BaseMetadataSchema.entries,
453
+
454
+ /**
455
+ * The URI of this resource.
456
+ */
457
+ uri: v.string(),
458
+
459
+ /**
460
+ * A description of what this resource represents.
461
+ *
462
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
463
+ */
464
+ description: v.optional(v.string()),
465
+
466
+ /**
467
+ * The MIME type of this resource, if known.
468
+ */
469
+ mimeType: v.optional(v.string()),
470
+
471
+ /**
472
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
473
+ * for notes on _meta usage.
474
+ */
475
+ _meta: v.optional(v.looseObject({})),
476
+ });
477
+
478
+ /**
479
+ * A template description for resources available on the server.
480
+ */
481
+ export const ResourceTemplateSchema = v.looseObject({
482
+ ...BaseMetadataSchema.entries,
483
+
484
+ /**
485
+ * A URI template (according to RFC 6570) that can be used to construct resource URIs.
486
+ */
487
+ uriTemplate: v.string(),
488
+
489
+ /**
490
+ * A description of what this template is for.
491
+ *
492
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
493
+ */
494
+ description: v.optional(v.string()),
495
+
496
+ /**
497
+ * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
498
+ */
499
+ mimeType: v.optional(v.string()),
500
+
501
+ /**
502
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
503
+ * for notes on _meta usage.
504
+ */
505
+ _meta: v.optional(v.looseObject({})),
506
+ });
507
+
508
+ /**
509
+ * Sent from the client to request a list of resources the server has.
510
+ */
511
+ export const ListResourcesRequestSchema = v.looseObject({
512
+ ...PaginatedRequestSchema.entries,
513
+ method: v.literal('resources/list'),
514
+ });
515
+
516
+ /**
517
+ * The server's response to a resources/list request from the client.
518
+ */
519
+ export const ListResourcesResultSchema = v.looseObject({
520
+ ...PaginatedResultSchema.entries,
521
+ resources: v.array(ResourceSchema),
522
+ });
523
+
524
+ /**
525
+ * Sent from the client to request a list of resource templates the server has.
526
+ */
527
+ export const ListResourceTemplatesRequestSchema = v.looseObject({
528
+ ...PaginatedRequestSchema.entries,
529
+ method: v.literal('resources/templates/list'),
530
+ });
531
+
532
+ /**
533
+ * The server's response to a resources/templates/list request from the client.
534
+ */
535
+ export const ListResourceTemplatesResultSchema = v.looseObject({
536
+ ...PaginatedResultSchema.entries,
537
+ resourceTemplates: v.array(ResourceTemplateSchema),
538
+ });
539
+
540
+ /**
541
+ * Sent from the client to the server, to read a specific resource URI.
542
+ */
543
+ export const ReadResourceRequestSchema = v.looseObject({
544
+ ...RequestSchema.entries,
545
+ method: v.literal('resources/read'),
546
+ params: v.looseObject({
547
+ ...BaseRequestParamsSchema.entries,
548
+
549
+ /**
550
+ * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
551
+ */
552
+ uri: v.string(),
553
+ }),
554
+ });
555
+
556
+ /**
557
+ * The server's response to a resources/read request from the client.
558
+ */
559
+ export const ReadResourceResultSchema = v.looseObject({
560
+ ...ResultSchema.entries,
561
+ contents: v.array(
562
+ v.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
563
+ ),
564
+ });
565
+
566
+ /**
567
+ * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.
568
+ */
569
+ export const ResourceListChangedNotificationSchema = v.looseObject({
570
+ ...NotificationSchema.entries,
571
+ method: v.literal('notifications/resources/list_changed'),
572
+ });
573
+
574
+ /**
575
+ * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
576
+ */
577
+ export const SubscribeRequestSchema = v.looseObject({
578
+ ...RequestSchema.entries,
579
+ method: v.literal('resources/subscribe'),
580
+ params: v.looseObject({
581
+ ...BaseRequestParamsSchema.entries,
582
+
583
+ /**
584
+ * The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
585
+ */
586
+ uri: v.string(),
587
+ }),
588
+ });
589
+
590
+ /**
591
+ * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
592
+ */
593
+ export const UnsubscribeRequestSchema = v.looseObject({
594
+ ...RequestSchema.entries,
595
+ method: v.literal('resources/unsubscribe'),
596
+ params: v.looseObject({
597
+ ...BaseRequestParamsSchema.entries,
598
+
599
+ /**
600
+ * The URI of the resource to unsubscribe from.
601
+ */
602
+ uri: v.string(),
603
+ }),
604
+ });
605
+
606
+ /**
607
+ * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
608
+ */
609
+ export const ResourceUpdatedNotificationSchema = v.looseObject({
610
+ ...NotificationSchema.entries,
611
+ method: v.literal('notifications/resources/updated'),
612
+ params: v.looseObject({
613
+ ...BaseNotificationParamsSchema.entries,
614
+
615
+ /**
616
+ * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
617
+ */
618
+ uri: v.string(),
619
+ }),
620
+ });
621
+ /* Prompts */
622
+
623
+ /**
624
+ * Describes an argument that a prompt can accept.
625
+ */
626
+ export const PromptArgumentSchema = v.looseObject({
627
+ /**
628
+ * The name of the argument.
629
+ */
630
+ name: v.string(),
631
+
632
+ /**
633
+ * A human-readable description of the argument.
634
+ */
635
+ description: v.optional(v.string()),
636
+
637
+ /**
638
+ * Whether this argument must be provided.
639
+ */
640
+ required: v.optional(v.boolean()),
641
+ });
642
+
643
+ /**
644
+ * A prompt or prompt template that the server offers.
645
+ */
646
+ export const PromptSchema = v.looseObject({
647
+ ...BaseMetadataSchema.entries,
648
+
649
+ /**
650
+ * An optional description of what this prompt provides
651
+ */
652
+ description: v.optional(v.string()),
653
+
654
+ /**
655
+ * A list of arguments to use for templating the prompt.
656
+ */
657
+ arguments: v.optional(v.array(PromptArgumentSchema)),
658
+
659
+ /**
660
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
661
+ * for notes on _meta usage.
662
+ */
663
+ _meta: v.optional(v.looseObject({})),
664
+ });
665
+
666
+ /**
667
+ * Sent from the client to request a list of prompts and prompt templates the server has.
668
+ */
669
+ export const ListPromptsRequestSchema = v.looseObject({
670
+ ...PaginatedRequestSchema.entries,
671
+ method: v.literal('prompts/list'),
672
+ });
673
+
674
+ /**
675
+ * The server's response to a prompts/list request from the client.
676
+ */
677
+ export const ListPromptsResultSchema = v.looseObject({
678
+ ...PaginatedResultSchema.entries,
679
+ prompts: v.array(PromptSchema),
680
+ });
681
+
682
+ /**
683
+ * Used by the client to get a prompt provided by the server.
684
+ */
685
+ export const GetPromptRequestSchema = v.looseObject({
686
+ ...RequestSchema.entries,
687
+ method: v.literal('prompts/get'),
688
+ params: v.looseObject({
689
+ ...BaseRequestParamsSchema.entries,
690
+
691
+ /**
692
+ * The name of the prompt or prompt template.
693
+ */
694
+ name: v.string(),
695
+
696
+ /**
697
+ * Arguments to use for templating the prompt.
698
+ */
699
+ arguments: v.optional(v.record(v.string(), v.string())),
700
+ }),
701
+ });
3
702
 
4
703
  /**
5
704
  * Text provided to or from an LLM.
6
705
  */
7
706
  export const TextContentSchema = v.looseObject({
8
707
  type: v.literal('text'),
708
+
9
709
  /**
10
710
  * The text content of the message.
11
711
  */
12
712
  text: v.string(),
713
+
714
+ /**
715
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
716
+ * for notes on _meta usage.
717
+ */
718
+ _meta: v.optional(v.looseObject({})),
719
+ });
720
+
721
+ /**
722
+ * An image provided to or from an LLM.
723
+ */
724
+ export const ImageContentSchema = v.looseObject({
725
+ type: v.literal('image'),
726
+
727
+ /**
728
+ * The base64-encoded image data.
729
+ */
730
+ data: v.pipe(v.string(), v.base64()),
731
+
732
+ /**
733
+ * The MIME type of the image. Different providers may support different image types.
734
+ */
735
+ mimeType: v.string(),
736
+
737
+ /**
738
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
739
+ * for notes on _meta usage.
740
+ */
741
+ _meta: v.optional(v.looseObject({})),
742
+ });
743
+
744
+ /**
745
+ * An Audio provided to or from an LLM.
746
+ */
747
+ export const AudioContentSchema = v.looseObject({
748
+ type: v.literal('audio'),
749
+
750
+ /**
751
+ * The base64-encoded audio data.
752
+ */
753
+ data: v.pipe(v.string(), v.base64()),
754
+
755
+ /**
756
+ * The MIME type of the audio. Different providers may support different audio types.
757
+ */
758
+ mimeType: v.string(),
759
+
760
+ /**
761
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
762
+ * for notes on _meta usage.
763
+ */
764
+ _meta: v.optional(v.looseObject({})),
765
+ });
766
+
767
+ /**
768
+ * The contents of a resource, embedded into a prompt or tool call result.
769
+ */
770
+ export const EmbeddedResourceSchema = v.looseObject({
771
+ type: v.literal('resource'),
772
+ resource: v.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
773
+
774
+ /**
775
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
776
+ * for notes on _meta usage.
777
+ */
778
+ _meta: v.optional(v.looseObject({})),
779
+ });
780
+
781
+ /**
782
+ * A resource that the server is capable of reading, included in a prompt or tool call result.
783
+ *
784
+ * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
785
+ */
786
+ export const ResourceLinkSchema = v.looseObject({
787
+ ...ResourceSchema.entries,
788
+ type: v.literal('resource_link'),
789
+ });
790
+
791
+ /**
792
+ * A content block that can be used in prompts and tool results.
793
+ */
794
+ export const ContentBlockSchema = v.union([
795
+ TextContentSchema,
796
+ ImageContentSchema,
797
+ AudioContentSchema,
798
+ ResourceLinkSchema,
799
+ EmbeddedResourceSchema,
800
+ ]);
801
+
802
+ /**
803
+ * Describes a message returned as part of a prompt.
804
+ */
805
+ export const PromptMessageSchema = v.looseObject({
806
+ role: v.picklist(['user', 'assistant']),
807
+ content: ContentBlockSchema,
808
+ });
809
+
810
+ /**
811
+ * The server's response to a prompts/get request from the client.
812
+ */
813
+ export const GetPromptResultSchema = v.looseObject({
814
+ ...ResultSchema.entries,
815
+
816
+ /**
817
+ * An optional description for the prompt.
818
+ */
819
+ description: v.optional(v.string()),
820
+ messages: v.array(PromptMessageSchema),
821
+ });
822
+
823
+ /**
824
+ * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
825
+ */
826
+ export const PromptListChangedNotificationSchema = v.looseObject({
827
+ ...NotificationSchema.entries,
828
+ method: v.literal('notifications/prompts/list_changed'),
829
+ });
830
+ /* Tools */
831
+
832
+ /**
833
+ * Additional properties describing a Tool to clients.
834
+ *
835
+ * NOTE: all properties in ToolAnnotations are **hints**.
836
+ * They are not guaranteed to provide a faithful description of
837
+ * tool behavior (including descriptive properties like `title`).
838
+ *
839
+ * Clients should never make tool use decisions based on ToolAnnotations
840
+ * received from untrusted servers.
841
+ */
842
+ export const ToolAnnotationsSchema = v.looseObject({
843
+ /**
844
+ * A human-readable title for the tool.
845
+ */
846
+ title: v.optional(v.string()),
847
+
848
+ /**
849
+ * If true, the tool does not modify its environment.
850
+ *
851
+ * Default: false
852
+ */
853
+ readOnlyHint: v.optional(v.boolean()),
854
+
855
+ /**
856
+ * If true, the tool may perform destructive updates to its environment.
857
+ * If false, the tool performs only additive updates.
858
+ *
859
+ * (This property is meaningful only when `readOnlyHint == false`)
860
+ *
861
+ * Default: true
862
+ */
863
+ destructiveHint: v.optional(v.boolean()),
864
+
865
+ /**
866
+ * If true, calling the tool repeatedly with the same arguments
867
+ * will have no additional effect on the its environment.
868
+ *
869
+ * (This property is meaningful only when `readOnlyHint == false`)
870
+ *
871
+ * Default: false
872
+ */
873
+ idempotentHint: v.optional(v.boolean()),
874
+
875
+ /**
876
+ * If true, this tool may interact with an "open world" of external
877
+ * entities. If false, the tool's domain of interaction is closed.
878
+ * For example, the world of a web search tool is open, whereas that
879
+ * of a memory tool is not.
880
+ *
881
+ * Default: true
882
+ */
883
+ openWorldHint: v.optional(v.boolean()),
884
+ });
885
+
886
+ /**
887
+ * Definition for a tool the client can call.
888
+ */
889
+ export const ToolSchema = v.looseObject({
890
+ ...BaseMetadataSchema.entries,
891
+
892
+ /**
893
+ * A human-readable description of the tool.
894
+ */
895
+ description: v.optional(v.string()),
896
+
897
+ /**
898
+ * A JSON Schema object defining the expected parameters for the tool.
899
+ */
900
+ inputSchema: v.looseObject({
901
+ type: v.literal('object'),
902
+ properties: v.optional(v.looseObject({})),
903
+ required: v.optional(v.array(v.string())),
904
+ }),
905
+
906
+ /**
907
+ * An optional JSON Schema object defining the structure of the tool's output returned in
908
+ * the structuredContent field of a CallToolResult.
909
+ */
910
+ outputSchema: v.optional(
911
+ v.looseObject({
912
+ type: v.literal('object'),
913
+ properties: v.optional(v.looseObject({})),
914
+ required: v.optional(v.array(v.string())),
915
+ }),
916
+ ),
917
+
13
918
  /**
14
- * See [MCP specification] for notes on _meta usage.
919
+ * Optional additional tool information.
920
+ */
921
+ annotations: v.optional(ToolAnnotationsSchema),
922
+
923
+ /**
924
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
925
+ * for notes on _meta usage.
15
926
  */
16
927
  _meta: v.optional(v.looseObject({})),
17
928
  });
18
929
 
19
930
  /**
20
- * An image provided to or from an LLM.
931
+ * Sent from the client to request a list of tools the server has.
932
+ */
933
+ export const ListToolsRequestSchema = v.looseObject({
934
+ ...PaginatedRequestSchema.entries,
935
+ method: v.literal('tools/list'),
936
+ });
937
+
938
+ /**
939
+ * The server's response to a tools/list request from the client.
940
+ */
941
+ export const ListToolsResultSchema = v.looseObject({
942
+ ...PaginatedResultSchema.entries,
943
+ tools: v.array(ToolSchema),
944
+ });
945
+
946
+ /**
947
+ * The server's response to a tool call.
948
+ */
949
+ export const CallToolResultSchema = v.looseObject({
950
+ ...ResultSchema.entries,
951
+
952
+ /**
953
+ * A list of content objects that represent the result of the tool call.
954
+ *
955
+ * If the Tool does not define an outputSchema, this field MUST be present in the result.
956
+ * For backwards compatibility, this field is always present, but it may be empty.
957
+ */
958
+ content: v.optional(v.array(ContentBlockSchema), []),
959
+
960
+ /**
961
+ * An object containing structured tool output.
962
+ *
963
+ * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
964
+ */
965
+ structuredContent: v.optional(v.looseObject({})),
966
+
967
+ /**
968
+ * Whether the tool call ended in an error.
969
+ *
970
+ * If not set, this is assumed to be false (the call was successful).
971
+ *
972
+ * Any errors that originate from the tool SHOULD be reported inside the result
973
+ * object, with `isError` set to true, _not_ as an MCP protocol-level error
974
+ * response. Otherwise, the LLM would not be able to see that an error occurred
975
+ * and self-correct.
976
+ *
977
+ * However, any errors in _finding_ the tool, an error indicating that the
978
+ * server does not support tool calls, or any other exceptional conditions,
979
+ * should be reported as an MCP error response.
980
+ */
981
+ isError: v.optional(v.boolean()),
982
+ });
983
+
984
+ /**
985
+ * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07.
986
+ */
987
+ export const CompatibilityCallToolResultSchema = v.union([
988
+ CallToolResultSchema,
989
+ v.looseObject({ ...ResultSchema.entries, toolResult: v.unknown() }),
990
+ ]);
991
+
992
+ /**
993
+ * Used by the client to invoke a tool provided by the server.
994
+ */
995
+ export const CallToolRequestSchema = v.looseObject({
996
+ ...RequestSchema.entries,
997
+ method: v.literal('tools/call'),
998
+ params: v.looseObject({
999
+ ...BaseRequestParamsSchema.entries,
1000
+ name: v.string(),
1001
+ arguments: v.optional(v.record(v.string(), v.unknown())),
1002
+ }),
1003
+ });
1004
+
1005
+ /**
1006
+ * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
1007
+ */
1008
+ export const ToolListChangedNotificationSchema = v.looseObject({
1009
+ ...NotificationSchema.entries,
1010
+ method: v.literal('notifications/tools/list_changed'),
1011
+ });
1012
+ /* Logging */
1013
+
1014
+ /**
1015
+ * The severity of a log message.
1016
+ */
1017
+ export const LoggingLevelSchema = v.picklist([
1018
+ 'debug',
1019
+ 'info',
1020
+ 'notice',
1021
+ 'warning',
1022
+ 'error',
1023
+ 'critical',
1024
+ 'alert',
1025
+ 'emergency',
1026
+ ]);
1027
+
1028
+ /**
1029
+ * A request from the client to the server, to enable or adjust logging.
1030
+ */
1031
+ export const SetLevelRequestSchema = v.looseObject({
1032
+ ...RequestSchema.entries,
1033
+ method: v.literal('logging/setLevel'),
1034
+ params: v.looseObject({
1035
+ ...BaseRequestParamsSchema.entries,
1036
+
1037
+ /**
1038
+ * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
1039
+ */
1040
+ level: LoggingLevelSchema,
1041
+ }),
1042
+ });
1043
+
1044
+ /**
1045
+ * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
21
1046
  */
22
- export const ImageContentSchema = v.looseObject({
23
- type: v.literal('image'),
24
- /**
25
- * The base64-encoded image data.
26
- */
27
- data: v.pipe(v.string(), v.base64()),
28
- /**
29
- * The MIME type of the image. Different providers may support different image types.
30
- */
31
- mimeType: v.string(),
32
- /**
33
- * See [MCP specification] for notes on _meta usage.
34
- */
35
- _meta: v.optional(v.looseObject({})),
1047
+ export const LoggingMessageNotificationSchema = v.looseObject({
1048
+ ...NotificationSchema.entries,
1049
+ method: v.literal('notifications/message'),
1050
+ params: v.looseObject({
1051
+ ...BaseNotificationParamsSchema.entries,
1052
+
1053
+ /**
1054
+ * The severity of this log message.
1055
+ */
1056
+ level: LoggingLevelSchema,
1057
+
1058
+ /**
1059
+ * An optional name of the logger issuing this message.
1060
+ */
1061
+ logger: v.optional(v.string()),
1062
+
1063
+ /**
1064
+ * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
1065
+ */
1066
+ data: v.unknown(),
1067
+ }),
36
1068
  });
1069
+ /* Sampling */
37
1070
 
38
1071
  /**
39
- * An Audio provided to or from an LLM.
1072
+ * Hints to use for model selection.
40
1073
  */
41
- export const AudioContentSchema = v.looseObject({
42
- type: v.literal('audio'),
43
- /**
44
- * The base64-encoded audio data.
45
- */
46
- data: v.pipe(v.string(), v.base64()),
1074
+ export const ModelHintSchema = v.looseObject({
47
1075
  /**
48
- * The MIME type of the audio. Different providers may support different audio types.
49
- */
50
- mimeType: v.string(),
51
- /**
52
- * See [MCP specification] for notes on _meta usage.
1076
+ * A hint for a model name.
53
1077
  */
54
- _meta: v.optional(v.looseObject({})),
1078
+ name: v.optional(v.string()),
55
1079
  });
56
1080
 
57
1081
  /**
58
- * The contents of a specific resource or sub-resource.
1082
+ * The server's preferences for model selection, requested of the client during sampling.
59
1083
  */
60
- export const ResourceContentsSchema = v.looseObject({
1084
+ export const ModelPreferencesSchema = v.looseObject({
61
1085
  /**
62
- * The URI of this resource.
1086
+ * Optional hints to use for model selection.
63
1087
  */
64
- uri: v.string(),
1088
+ hints: v.optional(v.array(ModelHintSchema)),
1089
+
65
1090
  /**
66
- * The MIME type of this resource, if known.
1091
+ * How much to prioritize cost when selecting a model.
67
1092
  */
68
- mimeType: v.optional(v.string()),
1093
+ costPriority: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(1))),
1094
+
69
1095
  /**
70
- * See [MCP specification] for notes on _meta usage.
1096
+ * How much to prioritize sampling speed (latency) when selecting a model.
71
1097
  */
72
- _meta: v.optional(v.looseObject({})),
73
- });
1098
+ speedPriority: v.optional(v.pipe(v.number(), v.minValue(0), v.maxValue(1))),
74
1099
 
75
- export const TextResourceContentsSchema = v.looseObject({
76
1100
  /**
77
- * The URI of this resource.
1101
+ * How much to prioritize intelligence and capabilities when selecting a model.
78
1102
  */
79
- uri: v.string(),
1103
+ intelligencePriority: v.optional(
1104
+ v.pipe(v.number(), v.minValue(0), v.maxValue(1)),
1105
+ ),
1106
+ });
1107
+
1108
+ /**
1109
+ * Describes a message issued to or received from an LLM API.
1110
+ */
1111
+ export const SamplingMessageSchema = v.looseObject({
1112
+ role: v.picklist(['user', 'assistant']),
1113
+ content: v.union([
1114
+ TextContentSchema,
1115
+ ImageContentSchema,
1116
+ AudioContentSchema,
1117
+ ]),
1118
+ });
1119
+
1120
+ export const CreateMessageRequestParamsSchema = v.looseObject({
1121
+ ...BaseRequestParamsSchema.entries,
1122
+ messages: v.array(SamplingMessageSchema),
1123
+
80
1124
  /**
81
- * The MIME type of this resource, if known.
1125
+ * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
82
1126
  */
83
- mimeType: v.optional(v.string()),
1127
+ systemPrompt: v.optional(v.string()),
1128
+
84
1129
  /**
85
- * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
1130
+ * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
86
1131
  */
87
- text: v.string(),
1132
+ includeContext: v.optional(
1133
+ v.picklist(['none', 'thisServer', 'allServers']),
1134
+ ),
1135
+ temperature: v.optional(v.number()),
1136
+
88
1137
  /**
89
- * See [MCP specification] for notes on _meta usage.
1138
+ * The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
90
1139
  */
91
- _meta: v.optional(v.looseObject({})),
92
- });
1140
+ maxTokens: v.pipe(v.number(), v.integer()),
1141
+ stopSequences: v.optional(v.array(v.string())),
93
1142
 
94
- export const BlobResourceContentsSchema = v.looseObject({
95
1143
  /**
96
- * The URI of this resource.
1144
+ * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
97
1145
  */
98
- uri: v.string(),
1146
+ metadata: v.optional(v.looseObject({})),
1147
+
99
1148
  /**
100
- * The MIME type of this resource, if known.
1149
+ * The server's preferences for which model to select.
101
1150
  */
102
- mimeType: v.optional(v.string()),
1151
+ modelPreferences: v.optional(ModelPreferencesSchema),
1152
+ });
1153
+
1154
+ /**
1155
+ * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
1156
+ */
1157
+ export const CreateMessageRequestSchema = v.looseObject({
1158
+ ...RequestSchema.entries,
1159
+ method: v.literal('sampling/createMessage'),
1160
+ params: CreateMessageRequestParamsSchema,
1161
+ });
1162
+
1163
+ /**
1164
+ * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
1165
+ */
1166
+ export const CreateMessageResultSchema = v.looseObject({
1167
+ ...ResultSchema.entries,
1168
+
103
1169
  /**
104
- * A base64-encoded string representing the binary data of the item.
1170
+ * The name of the model that generated the message.
105
1171
  */
106
- blob: v.pipe(v.string(), v.base64()),
1172
+ model: v.string(),
1173
+
107
1174
  /**
108
- * See [MCP specification] for notes on _meta usage.
1175
+ * The reason why sampling stopped.
109
1176
  */
110
- _meta: v.optional(v.looseObject({})),
1177
+ stopReason: v.optional(
1178
+ v.union([
1179
+ v.picklist(['endTurn', 'stopSequence', 'maxTokens']),
1180
+ v.string(),
1181
+ ]),
1182
+ ),
1183
+ role: v.picklist(['user', 'assistant']),
1184
+ content: v.variant('type', [
1185
+ TextContentSchema,
1186
+ ImageContentSchema,
1187
+ AudioContentSchema,
1188
+ ]),
111
1189
  });
1190
+ /* Elicitation */
112
1191
 
113
1192
  /**
114
- * The contents of a resource, embedded into a prompt or tool call result.
1193
+ * Primitive schema definition for boolean fields.
115
1194
  */
116
- export const EmbeddedResourceSchema = v.looseObject({
117
- type: v.literal('resource'),
118
- resource: v.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
119
- /**
120
- * See [MCP specification] for notes on _meta usage.
121
- */
122
- _meta: v.optional(v.looseObject({})),
1195
+ export const BooleanSchemaSchema = v.looseObject({
1196
+ type: v.literal('boolean'),
1197
+ title: v.optional(v.string()),
1198
+ description: v.optional(v.string()),
1199
+ default: v.optional(v.boolean()),
123
1200
  });
124
1201
 
125
1202
  /**
126
- * A resource that the server is capable of reading, included in a prompt or tool call result.
1203
+ * Primitive schema definition for string fields.
127
1204
  */
128
- export const ResourceLinkSchema = v.looseObject({
129
- /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
130
- name: v.string(),
1205
+ export const StringSchemaSchema = v.looseObject({
1206
+ type: v.literal('string'),
131
1207
  title: v.optional(v.string()),
132
- /**
133
- * The URI of this resource.
134
- */
135
- uri: v.string(),
136
- /**
137
- * A description of what this resource represents.
138
- */
139
1208
  description: v.optional(v.string()),
140
- /**
141
- * The MIME type of this resource, if known.
142
- */
143
- mimeType: v.optional(v.string()),
144
- type: v.literal('resource_link'),
145
- /**
146
- * See [MCP specification] for notes on _meta usage.
147
- */
148
- _meta: v.optional(v.looseObject({})),
1209
+ minLength: v.optional(v.number()),
1210
+ maxLength: v.optional(v.number()),
1211
+ format: v.optional(v.picklist(['email', 'uri', 'date', 'date-time'])),
149
1212
  });
150
1213
 
151
1214
  /**
152
- * A content block that can be used in prompts and tool results.
1215
+ * Primitive schema definition for number fields.
153
1216
  */
154
- export const ContentBlockSchema = v.union([
155
- TextContentSchema,
156
- ImageContentSchema,
157
- AudioContentSchema,
158
- ResourceLinkSchema,
159
- EmbeddedResourceSchema,
1217
+ export const NumberSchemaSchema = v.looseObject({
1218
+ type: v.picklist(['number', 'integer']),
1219
+ title: v.optional(v.string()),
1220
+ description: v.optional(v.string()),
1221
+ minimum: v.optional(v.number()),
1222
+ maximum: v.optional(v.number()),
1223
+ });
1224
+
1225
+ /**
1226
+ * Primitive schema definition for enum fields.
1227
+ */
1228
+ export const EnumSchemaSchema = v.looseObject({
1229
+ type: v.literal('string'),
1230
+ title: v.optional(v.string()),
1231
+ description: v.optional(v.string()),
1232
+ enum: v.array(v.string()),
1233
+ enumNames: v.optional(v.array(v.string())),
1234
+ });
1235
+
1236
+ /**
1237
+ * Union of all primitive schema definitions.
1238
+ */
1239
+ export const PrimitiveSchemaDefinitionSchema = v.union([
1240
+ BooleanSchemaSchema,
1241
+ StringSchemaSchema,
1242
+ NumberSchemaSchema,
1243
+ EnumSchemaSchema,
160
1244
  ]);
161
1245
 
162
1246
  /**
163
- * Describes a message returned as part of a prompt.
1247
+ * A request from the server to elicit user input via the client.
1248
+ * The client should present the message and form fields to the user.
164
1249
  */
165
- export const PromptMessageSchema = v.looseObject({
166
- role: v.picklist(['user', 'assistant']),
167
- content: ContentBlockSchema,
1250
+ export const ElicitRequestSchema = v.looseObject({
1251
+ ...RequestSchema.entries,
1252
+ method: v.literal('elicitation/create'),
1253
+ params: v.looseObject({
1254
+ ...BaseRequestParamsSchema.entries,
1255
+
1256
+ /**
1257
+ * The message to present to the user.
1258
+ */
1259
+ message: v.string(),
1260
+
1261
+ /**
1262
+ * The schema for the requested user input.
1263
+ */
1264
+ requestedSchema: v.looseObject({
1265
+ type: v.literal('object'),
1266
+ properties: v.record(v.string(), PrimitiveSchemaDefinitionSchema),
1267
+ required: v.optional(v.array(v.string())),
1268
+ }),
1269
+ }),
168
1270
  });
169
1271
 
170
1272
  /**
171
- * The server's response to a tool call.
1273
+ * The client's response to an elicitation/create request from the server.
172
1274
  */
173
- export const CallToolResultSchema = v.looseObject({
1275
+ export const ElicitResultSchema = v.looseObject({
1276
+ ...ResultSchema.entries,
1277
+
174
1278
  /**
175
- * A list of content objects that represent the result of the tool call.
1279
+ * The user's response action.
176
1280
  */
177
- content: v.optional(v.array(ContentBlockSchema), []),
1281
+ action: v.picklist(['accept', 'decline', 'cancel']),
178
1282
 
179
1283
  /**
180
- * An object containing structured tool output.
1284
+ * The collected user input content (only present if action is "accept").
181
1285
  */
182
- structuredContent: v.optional(v.looseObject({})),
1286
+ content: v.optional(v.record(v.string(), v.unknown())),
1287
+ });
1288
+ /* Autocomplete */
1289
+
1290
+ /**
1291
+ * A reference to a resource or resource template definition.
1292
+ */
1293
+ export const ResourceTemplateReferenceSchema = v.looseObject({
1294
+ type: v.literal('ref/resource'),
183
1295
 
184
1296
  /**
185
- * Whether the tool call ended in an error.
1297
+ * The URI or URI template of the resource.
186
1298
  */
187
- isError: v.optional(v.boolean()),
188
- _meta: v.optional(v.looseObject({})),
1299
+ uri: v.string(),
189
1300
  });
190
1301
 
191
1302
  /**
192
- * The server's response to a resources/read request from the client.
1303
+ * @deprecated Use ResourceTemplateReferenceSchema instead
193
1304
  */
194
- export const ReadResourceResultSchema = v.looseObject({
195
- contents: v.array(
196
- v.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
197
- ),
198
- _meta: v.optional(v.looseObject({})),
199
- });
1305
+ export const ResourceReferenceSchema = ResourceTemplateReferenceSchema;
200
1306
 
201
1307
  /**
202
- * The server's response to a prompts/get request from the client.
1308
+ * Identifies a prompt.
203
1309
  */
204
- export const GetPromptResultSchema = v.looseObject({
1310
+ export const PromptReferenceSchema = v.looseObject({
1311
+ type: v.literal('ref/prompt'),
1312
+
205
1313
  /**
206
- * An optional description for the prompt.
1314
+ * The name of the prompt or prompt template
207
1315
  */
208
- description: v.optional(v.string()),
209
- messages: v.array(PromptMessageSchema),
210
- _meta: v.optional(v.looseObject({})),
1316
+ name: v.string(),
1317
+ });
1318
+
1319
+ /**
1320
+ * A request from the client to the server, to ask for completion options.
1321
+ */
1322
+ export const CompleteRequestSchema = v.looseObject({
1323
+ ...RequestSchema.entries,
1324
+ method: v.literal('completion/complete'),
1325
+ params: v.looseObject({
1326
+ ...BaseRequestParamsSchema.entries,
1327
+ ref: v.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
1328
+
1329
+ /**
1330
+ * The argument's information
1331
+ */
1332
+ argument: v.looseObject({
1333
+ /**
1334
+ * The name of the argument
1335
+ */
1336
+ name: v.string(),
1337
+
1338
+ /**
1339
+ * The value of the argument to use for completion matching.
1340
+ */
1341
+ value: v.string(),
1342
+ }),
1343
+ context: v.optional(
1344
+ v.object({
1345
+ /**
1346
+ * Previously-resolved variables in a URI template or prompt.
1347
+ */
1348
+ arguments: v.optional(v.record(v.string(), v.string())),
1349
+ }),
1350
+ ),
1351
+ }),
211
1352
  });
212
1353
 
213
1354
  /**
214
1355
  * The server's response to a completion/complete request
215
1356
  */
216
1357
  export const CompleteResultSchema = v.looseObject({
1358
+ ...ResultSchema.entries,
217
1359
  completion: v.looseObject({
218
1360
  /**
219
1361
  * An array of completion values. Must not exceed 100 items.
220
1362
  */
221
1363
  values: v.pipe(v.array(v.string()), v.maxLength(100)),
1364
+
222
1365
  /**
223
1366
  * The total number of completion options available. This can exceed the number of values actually sent in the response.
224
1367
  */
225
1368
  total: v.optional(v.pipe(v.number(), v.integer())),
1369
+
226
1370
  /**
227
1371
  * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
228
1372
  */
229
1373
  hasMore: v.optional(v.boolean()),
230
1374
  }),
231
- _meta: v.optional(v.looseObject({})),
232
1375
  });
1376
+ /* Roots */
233
1377
 
234
- export const ClientCapabilitiesSchema = v.looseObject({
235
- roots: v.optional(
236
- v.looseObject({
237
- listChanged: v.optional(v.boolean()),
238
- }),
239
- ),
240
- sampling: v.optional(v.looseObject({})),
241
- elicitation: v.optional(v.looseObject({})),
1378
+ /**
1379
+ * Represents a root directory or file that the server can operate on.
1380
+ */
1381
+ export const RootSchema = v.looseObject({
1382
+ /**
1383
+ * The URI identifying the root. This *must* start with file:// for now.
1384
+ */
1385
+ uri: v.pipe(v.string(), v.startsWith('file://')),
1386
+
1387
+ /**
1388
+ * An optional name for the root.
1389
+ */
1390
+ name: v.optional(v.string()),
1391
+
1392
+ /**
1393
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1394
+ * for notes on _meta usage.
1395
+ */
1396
+ _meta: v.optional(v.looseObject({})),
242
1397
  });
243
1398
 
244
- export const InitializeRequestSchema = v.looseObject({
245
- protocolVersion: v.string(),
246
- capabilities: ClientCapabilitiesSchema,
1399
+ /**
1400
+ * Sent from the server to request a list of root URIs from the client.
1401
+ */
1402
+ export const ListRootsRequestSchema = v.looseObject({
1403
+ ...RequestSchema.entries,
1404
+ method: v.literal('roots/list'),
247
1405
  });
248
1406
 
249
1407
  /**
250
- * @typedef {v.InferInput<typeof ClientCapabilitiesSchema>} ClientCapabilities
1408
+ * The client's response to a roots/list request from the server.
251
1409
  */
1410
+ export const ListRootsResultSchema = v.looseObject({
1411
+ ...ResultSchema.entries,
1412
+ roots: v.array(RootSchema),
1413
+ });
252
1414
 
253
1415
  /**
254
- * @typedef {v.InferInput<typeof InitializeRequestSchema>} InitializeRequest
1416
+ * A notification from the client to the server, informing it that the list of roots has changed.
255
1417
  */
1418
+ export const RootsListChangedNotificationSchema = v.looseObject({
1419
+ ...NotificationSchema.entries,
1420
+ method: v.literal('notifications/roots/list_changed'),
1421
+ });
1422
+ /* Client messages */
1423
+ export const ClientRequestSchema = v.union([
1424
+ PingRequestSchema,
1425
+ InitializeRequestSchema,
1426
+ CompleteRequestSchema,
1427
+ SetLevelRequestSchema,
1428
+ GetPromptRequestSchema,
1429
+ ListPromptsRequestSchema,
1430
+ ListResourcesRequestSchema,
1431
+ ListResourceTemplatesRequestSchema,
1432
+ ReadResourceRequestSchema,
1433
+ SubscribeRequestSchema,
1434
+ UnsubscribeRequestSchema,
1435
+ CallToolRequestSchema,
1436
+ ListToolsRequestSchema,
1437
+ ]);
1438
+ export const ClientNotificationSchema = v.union([
1439
+ CancelledNotificationSchema,
1440
+ ProgressNotificationSchema,
1441
+ InitializedNotificationSchema,
1442
+ RootsListChangedNotificationSchema,
1443
+ ]);
1444
+ export const ClientResultSchema = v.union([
1445
+ EmptyResultSchema,
1446
+ CreateMessageResultSchema,
1447
+ ElicitResultSchema,
1448
+ ListRootsResultSchema,
1449
+ ]);
1450
+ /* Server messages */
1451
+ export const ServerRequestSchema = v.union([
1452
+ PingRequestSchema,
1453
+ CreateMessageRequestSchema,
1454
+ ElicitRequestSchema,
1455
+ ListRootsRequestSchema,
1456
+ ]);
1457
+ export const ServerNotificationSchema = v.union([
1458
+ CancelledNotificationSchema,
1459
+ ProgressNotificationSchema,
1460
+ LoggingMessageNotificationSchema,
1461
+ ResourceUpdatedNotificationSchema,
1462
+ ResourceListChangedNotificationSchema,
1463
+ ToolListChangedNotificationSchema,
1464
+ PromptListChangedNotificationSchema,
1465
+ ]);
1466
+ export const ServerResultSchema = v.union([
1467
+ EmptyResultSchema,
1468
+ InitializeResultSchema,
1469
+ CompleteResultSchema,
1470
+ GetPromptResultSchema,
1471
+ ListPromptsResultSchema,
1472
+ ListResourcesResultSchema,
1473
+ ListResourceTemplatesResultSchema,
1474
+ ReadResourceResultSchema,
1475
+ CallToolResultSchema,
1476
+ ListToolsResultSchema,
1477
+ ]);
256
1478
 
1479
+ /**
1480
+ * @typedef {v.InferInput<typeof ClientCapabilitiesSchema>} ClientCapabilities
1481
+ */
1482
+ /**
1483
+ * @typedef {v.InferInput<typeof ServerCapabilitiesSchema>} ServerCapabilities
1484
+ */
1485
+ /**
1486
+ * @typedef {v.InferInput<typeof ImplementationSchema>} ClientInfo
1487
+ */
1488
+ /**
1489
+ * @typedef {v.InferInput<typeof ImplementationSchema>} ServerInfo
1490
+ */
1491
+ /**
1492
+ * @typedef {v.InferInput<typeof InitializeRequestParamsSchema>} InitializeRequestParams
1493
+ */
257
1494
  /**
258
1495
  * @typedef {v.InferInput<typeof CallToolResultSchema>} CallToolResult
259
1496
  */
260
-
261
1497
  /**
262
1498
  * @typedef {v.InferInput<typeof ReadResourceResultSchema>} ReadResourceResult
263
1499
  */
264
-
265
1500
  /**
266
1501
  * @typedef {v.InferInput<typeof GetPromptResultSchema>} GetPromptResult
267
1502
  */
268
-
269
1503
  /**
270
1504
  * @typedef {v.InferInput<typeof CompleteResultSchema>} CompleteResult
271
1505
  */
1506
+ /**
1507
+ * @typedef {v.InferInput<typeof CreateMessageRequestParamsSchema>} CreateMessageRequestParams
1508
+ */
1509
+ /**
1510
+ * @typedef {v.InferInput<typeof CreateMessageResultSchema>} CreateMessageResult
1511
+ */
1512
+ /**
1513
+ * @typedef {v.InferInput<typeof ModelPreferencesSchema>} ModelPreferences
1514
+ */
1515
+ /**
1516
+ * @typedef {v.InferInput<typeof SamplingMessageSchema>} SamplingMessage
1517
+ */
1518
+ /**
1519
+ * @typedef {v.InferInput<typeof ModelHintSchema>} ModelHint
1520
+ */
1521
+ /**
1522
+ * @typedef {v.InferInput<typeof ResourceSchema>} Resource
1523
+ */
1524
+ /**
1525
+ * @typedef {v.InferInput<typeof JSONRPCRequestSchema>} JSONRPCRequest
1526
+ */
1527
+ /**
1528
+ * @typedef {v.InferInput<typeof JSONRPCResponseSchema>} JSONRPCResponse
1529
+ */
1530
+ /**
1531
+ * @typedef {v.InferInput<typeof LoggingLevelSchema>} LoggingLevel
1532
+ */