1
1
import { z } from "zod" ;
2
2
3
+ export const PROTOCOL_VERSION = "2024-10-07" ;
4
+
5
+
3
6
/* JSON-RPC types */
4
7
export const JSONRPC_VERSION = "2.0" ;
5
8
@@ -8,6 +11,11 @@ export const JSONRPC_VERSION = "2.0";
8
11
*/
9
12
export const ProgressTokenSchema = z . union ( [ z . string ( ) , z . number ( ) . int ( ) ] ) ;
10
13
14
+ /**
15
+ * An opaque token used to represent a cursor for pagination.
16
+ */
17
+ export const CursorSchema = z . string ( ) ;
18
+
11
19
export const RequestSchema = z . object ( {
12
20
method : z . string ( ) ,
13
21
params : z . optional (
@@ -141,8 +149,6 @@ export const JSONRPCMessageSchema = z.union([
141
149
export const EmptyResultSchema = ResultSchema . strict ( ) ;
142
150
143
151
/* Initialization */
144
- export const PROTOCOL_VERSION = 1 ;
145
-
146
152
/**
147
153
* Text provided to or from an LLM.
148
154
*/
@@ -208,7 +214,7 @@ export const InitializeRequestSchema = RequestSchema.extend({
208
214
/**
209
215
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
210
216
*/
211
- protocolVersion : z . number ( ) . int ( ) ,
217
+ protocolVersion : z . string ( ) . or ( z . number ( ) . int ( ) ) ,
212
218
capabilities : ClientCapabilitiesSchema ,
213
219
clientInfo : ImplementationSchema ,
214
220
} ) ,
@@ -229,24 +235,40 @@ export const ServerCapabilitiesSchema = z.object({
229
235
/**
230
236
* Present if the server offers any prompt templates.
231
237
*/
232
- prompts : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
238
+ prompts : z . optional (
239
+ z . object ( {
240
+ /**
241
+ * Whether this server supports notifications for changes to the prompt list.
242
+ */
243
+ listChanged : z . optional ( z . boolean ( ) ) ,
244
+ } ) . passthrough ( ) ,
245
+ ) ,
233
246
/**
234
247
* Present if the server offers any resources to read.
235
248
*/
236
249
resources : z . optional (
237
- z
238
- . object ( {
239
- /**
240
- * Whether this server supports subscribing to resource updates.
241
- */
242
- subscribe : z . optional ( z . boolean ( ) ) ,
243
- } )
244
- . passthrough ( ) ,
250
+ z . object ( {
251
+ /**
252
+ * Whether this server supports subscribing to resource updates.
253
+ */
254
+ subscribe : z . optional ( z . boolean ( ) ) ,
255
+ /**
256
+ * Whether this server supports notifications for changes to the resource list.
257
+ */
258
+ listChanged : z . optional ( z . boolean ( ) ) ,
259
+ } ) . passthrough ( ) ,
245
260
) ,
246
261
/**
247
262
* Present if the server offers any tools to call.
248
263
*/
249
- tools : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
264
+ tools : z . optional (
265
+ z . object ( {
266
+ /**
267
+ * Whether this server supports notifications for changes to the tool list.
268
+ */
269
+ listChanged : z . optional ( z . boolean ( ) ) ,
270
+ } ) . passthrough ( ) ,
271
+ ) ,
250
272
} ) ;
251
273
252
274
/**
@@ -256,7 +278,7 @@ export const InitializeResultSchema = ResultSchema.extend({
256
278
/**
257
279
* 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.
258
280
*/
259
- protocolVersion : z . number ( ) . int ( ) ,
281
+ protocolVersion : z . string ( ) . or ( z . number ( ) . int ( ) ) ,
260
282
capabilities : ServerCapabilitiesSchema ,
261
283
serverInfo : ImplementationSchema ,
262
284
} ) ;
@@ -301,6 +323,27 @@ export const ProgressNotificationSchema = NotificationSchema.extend({
301
323
} ) ,
302
324
} ) ;
303
325
326
+ /* Pagination */
327
+ export const PaginatedRequestSchema = RequestSchema . extend ( {
328
+ params : z . optional (
329
+ z . object ( {
330
+ /**
331
+ * An opaque token representing the current pagination position.
332
+ * If provided, the server should return results starting after this cursor.
333
+ */
334
+ cursor : z . optional ( CursorSchema ) ,
335
+ } ) ,
336
+ ) ,
337
+ } ) ;
338
+
339
+ export const PaginatedResultSchema = ResultSchema . extend ( {
340
+ /**
341
+ * An opaque token representing the pagination position after the last returned result.
342
+ * If present, there may be more results available.
343
+ */
344
+ nextCursor : z . optional ( CursorSchema ) ,
345
+ } ) ;
346
+
304
347
/* Resources */
305
348
/**
306
349
* The contents of a specific resource or sub-resource.
@@ -391,16 +434,29 @@ export const ResourceTemplateSchema = z.object({
391
434
/**
392
435
* Sent from the client to request a list of resources the server has.
393
436
*/
394
- export const ListResourcesRequestSchema = RequestSchema . extend ( {
437
+ export const ListResourcesRequestSchema = PaginatedRequestSchema . extend ( {
395
438
method : z . literal ( "resources/list" ) ,
396
439
} ) ;
397
440
398
441
/**
399
442
* The server's response to a resources/list request from the client.
400
443
*/
401
- export const ListResourcesResultSchema = ResultSchema . extend ( {
402
- resourceTemplates : z . optional ( z . array ( ResourceTemplateSchema ) ) ,
403
- resources : z . optional ( z . array ( ResourceSchema ) ) ,
444
+ export const ListResourcesResultSchema = PaginatedResultSchema . extend ( {
445
+ resources : z . array ( ResourceSchema ) ,
446
+ } ) ;
447
+
448
+ /**
449
+ * Sent from the client to request a list of resource templates the server has.
450
+ */
451
+ export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema . extend ( {
452
+ method : z . literal ( "resources/templates/list" ) ,
453
+ } ) ;
454
+
455
+ /**
456
+ * The server's response to a resources/templates/list request from the client.
457
+ */
458
+ export const ListResourceTemplatesResultSchema = PaginatedResultSchema . extend ( {
459
+ resourceTemplates : z . array ( ResourceTemplateSchema ) ,
404
460
} ) ;
405
461
406
462
/**
@@ -511,14 +567,14 @@ export const PromptSchema = z.object({
511
567
/**
512
568
* Sent from the client to request a list of prompts and prompt templates the server has.
513
569
*/
514
- export const ListPromptsRequestSchema = RequestSchema . extend ( {
570
+ export const ListPromptsRequestSchema = PaginatedRequestSchema . extend ( {
515
571
method : z . literal ( "prompts/list" ) ,
516
572
} ) ;
517
573
518
574
/**
519
575
* The server's response to a prompts/list request from the client.
520
576
*/
521
- export const ListPromptsResultSchema = ResultSchema . extend ( {
577
+ export const ListPromptsResultSchema = PaginatedResultSchema . extend ( {
522
578
prompts : z . array ( PromptSchema ) ,
523
579
} ) ;
524
580
@@ -550,6 +606,13 @@ export const GetPromptResultSchema = ResultSchema.extend({
550
606
messages : z . array ( SamplingMessageSchema ) ,
551
607
} ) ;
552
608
609
+ /**
610
+ * 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.
611
+ */
612
+ export const PromptListChangedNotificationSchema = NotificationSchema . extend ( {
613
+ method : z . literal ( "notifications/prompts/list_changed" ) ,
614
+ } ) ;
615
+
553
616
/* Tools */
554
617
/**
555
618
* Definition for a tool the client can call.
@@ -575,14 +638,14 @@ export const ToolSchema = z.object({
575
638
/**
576
639
* Sent from the client to request a list of tools the server has.
577
640
*/
578
- export const ListToolsRequestSchema = RequestSchema . extend ( {
641
+ export const ListToolsRequestSchema = PaginatedRequestSchema . extend ( {
579
642
method : z . literal ( "tools/list" ) ,
580
643
} ) ;
581
644
582
645
/**
583
646
* The server's response to a tools/list request from the client.
584
647
*/
585
- export const ListToolsResultSchema = ResultSchema . extend ( {
648
+ export const ListToolsResultSchema = PaginatedResultSchema . extend ( {
586
649
tools : z . array ( ToolSchema ) ,
587
650
} ) ;
588
651
@@ -802,6 +865,7 @@ export const ServerNotificationSchema = z.union([
802
865
ResourceUpdatedNotificationSchema ,
803
866
ResourceListChangedNotificationSchema ,
804
867
ToolListChangedNotificationSchema ,
868
+ PromptListChangedNotificationSchema ,
805
869
] ) ;
806
870
807
871
export const ServerResultSchema = z . union ( [
@@ -828,6 +892,7 @@ export class McpError extends Error {
828
892
829
893
/* JSON-RPC types */
830
894
export type ProgressToken = z . infer < typeof ProgressTokenSchema > ;
895
+ export type Cursor = z . infer < typeof CursorSchema > ;
831
896
export type Request = z . infer < typeof RequestSchema > ;
832
897
export type Notification = z . infer < typeof NotificationSchema > ;
833
898
export type Result = z . infer < typeof ResultSchema > ;
@@ -861,6 +926,10 @@ export type PingRequest = z.infer<typeof PingRequestSchema>;
861
926
export type Progress = z . infer < typeof ProgressSchema > ;
862
927
export type ProgressNotification = z . infer < typeof ProgressNotificationSchema > ;
863
928
929
+ /* Pagination */
930
+ export type PaginatedRequest = z . infer < typeof PaginatedRequestSchema > ;
931
+ export type PaginatedResult = z . infer < typeof PaginatedResultSchema > ;
932
+
864
933
/* Resources */
865
934
export type ResourceContents = z . infer < typeof ResourceContentsSchema > ;
866
935
export type TextResourceContents = z . infer < typeof TextResourceContentsSchema > ;
@@ -869,6 +938,8 @@ export type Resource = z.infer<typeof ResourceSchema>;
869
938
export type ResourceTemplate = z . infer < typeof ResourceTemplateSchema > ;
870
939
export type ListResourcesRequest = z . infer < typeof ListResourcesRequestSchema > ;
871
940
export type ListResourcesResult = z . infer < typeof ListResourcesResultSchema > ;
941
+ export type ListResourceTemplatesRequest = z . infer < typeof ListResourceTemplatesRequestSchema > ;
942
+ export type ListResourceTemplatesResult = z . infer < typeof ListResourceTemplatesResultSchema > ;
872
943
export type ReadResourceRequest = z . infer < typeof ReadResourceRequestSchema > ;
873
944
export type ReadResourceResult = z . infer < typeof ReadResourceResultSchema > ;
874
945
export type ResourceListChangedNotification = z . infer <
@@ -887,6 +958,9 @@ export type ListPromptsRequest = z.infer<typeof ListPromptsRequestSchema>;
887
958
export type ListPromptsResult = z . infer < typeof ListPromptsResultSchema > ;
888
959
export type GetPromptRequest = z . infer < typeof GetPromptRequestSchema > ;
889
960
export type GetPromptResult = z . infer < typeof GetPromptResultSchema > ;
961
+ export type PromptListChangedNotification = z . infer <
962
+ typeof PromptListChangedNotificationSchema
963
+ > ;
890
964
891
965
/* Tools */
892
966
export type Tool = z . infer < typeof ToolSchema > ;
0 commit comments