11import { z } from "zod" ;
22
3+ export const PROTOCOL_VERSION = "2024-10-07" ;
4+
5+
36/* JSON-RPC types */
47export const JSONRPC_VERSION = "2.0" ;
58
@@ -8,6 +11,11 @@ export const JSONRPC_VERSION = "2.0";
811 */
912export const ProgressTokenSchema = z . union ( [ z . string ( ) , z . number ( ) . int ( ) ] ) ;
1013
14+ /**
15+ * An opaque token used to represent a cursor for pagination.
16+ */
17+ export const CursorSchema = z . string ( ) ;
18+
1119export const RequestSchema = z . object ( {
1220 method : z . string ( ) ,
1321 params : z . optional (
@@ -141,8 +149,6 @@ export const JSONRPCMessageSchema = z.union([
141149export const EmptyResultSchema = ResultSchema . strict ( ) ;
142150
143151/* Initialization */
144- export const PROTOCOL_VERSION = 1 ;
145-
146152/**
147153 * Text provided to or from an LLM.
148154 */
@@ -208,7 +214,7 @@ export const InitializeRequestSchema = RequestSchema.extend({
208214 /**
209215 * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
210216 */
211- protocolVersion : z . number ( ) . int ( ) ,
217+ protocolVersion : z . string ( ) . or ( z . number ( ) . int ( ) ) ,
212218 capabilities : ClientCapabilitiesSchema ,
213219 clientInfo : ImplementationSchema ,
214220 } ) ,
@@ -229,24 +235,40 @@ export const ServerCapabilitiesSchema = z.object({
229235 /**
230236 * Present if the server offers any prompt templates.
231237 */
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+ ) ,
233246 /**
234247 * Present if the server offers any resources to read.
235248 */
236249 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 ( ) ,
245260 ) ,
246261 /**
247262 * Present if the server offers any tools to call.
248263 */
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+ ) ,
250272} ) ;
251273
252274/**
@@ -256,7 +278,7 @@ export const InitializeResultSchema = ResultSchema.extend({
256278 /**
257279 * 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.
258280 */
259- protocolVersion : z . number ( ) . int ( ) ,
281+ protocolVersion : z . string ( ) . or ( z . number ( ) . int ( ) ) ,
260282 capabilities : ServerCapabilitiesSchema ,
261283 serverInfo : ImplementationSchema ,
262284} ) ;
@@ -301,6 +323,27 @@ export const ProgressNotificationSchema = NotificationSchema.extend({
301323 } ) ,
302324} ) ;
303325
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+
304347/* Resources */
305348/**
306349 * The contents of a specific resource or sub-resource.
@@ -391,16 +434,29 @@ export const ResourceTemplateSchema = z.object({
391434/**
392435 * Sent from the client to request a list of resources the server has.
393436 */
394- export const ListResourcesRequestSchema = RequestSchema . extend ( {
437+ export const ListResourcesRequestSchema = PaginatedRequestSchema . extend ( {
395438 method : z . literal ( "resources/list" ) ,
396439} ) ;
397440
398441/**
399442 * The server's response to a resources/list request from the client.
400443 */
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 ) ,
404460} ) ;
405461
406462/**
@@ -511,14 +567,14 @@ export const PromptSchema = z.object({
511567/**
512568 * Sent from the client to request a list of prompts and prompt templates the server has.
513569 */
514- export const ListPromptsRequestSchema = RequestSchema . extend ( {
570+ export const ListPromptsRequestSchema = PaginatedRequestSchema . extend ( {
515571 method : z . literal ( "prompts/list" ) ,
516572} ) ;
517573
518574/**
519575 * The server's response to a prompts/list request from the client.
520576 */
521- export const ListPromptsResultSchema = ResultSchema . extend ( {
577+ export const ListPromptsResultSchema = PaginatedResultSchema . extend ( {
522578 prompts : z . array ( PromptSchema ) ,
523579} ) ;
524580
@@ -550,6 +606,13 @@ export const GetPromptResultSchema = ResultSchema.extend({
550606 messages : z . array ( SamplingMessageSchema ) ,
551607} ) ;
552608
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+
553616/* Tools */
554617/**
555618 * Definition for a tool the client can call.
@@ -575,14 +638,14 @@ export const ToolSchema = z.object({
575638/**
576639 * Sent from the client to request a list of tools the server has.
577640 */
578- export const ListToolsRequestSchema = RequestSchema . extend ( {
641+ export const ListToolsRequestSchema = PaginatedRequestSchema . extend ( {
579642 method : z . literal ( "tools/list" ) ,
580643} ) ;
581644
582645/**
583646 * The server's response to a tools/list request from the client.
584647 */
585- export const ListToolsResultSchema = ResultSchema . extend ( {
648+ export const ListToolsResultSchema = PaginatedResultSchema . extend ( {
586649 tools : z . array ( ToolSchema ) ,
587650} ) ;
588651
@@ -802,6 +865,7 @@ export const ServerNotificationSchema = z.union([
802865 ResourceUpdatedNotificationSchema ,
803866 ResourceListChangedNotificationSchema ,
804867 ToolListChangedNotificationSchema ,
868+ PromptListChangedNotificationSchema ,
805869] ) ;
806870
807871export const ServerResultSchema = z . union ( [
@@ -828,6 +892,7 @@ export class McpError extends Error {
828892
829893/* JSON-RPC types */
830894export type ProgressToken = z . infer < typeof ProgressTokenSchema > ;
895+ export type Cursor = z . infer < typeof CursorSchema > ;
831896export type Request = z . infer < typeof RequestSchema > ;
832897export type Notification = z . infer < typeof NotificationSchema > ;
833898export type Result = z . infer < typeof ResultSchema > ;
@@ -861,6 +926,10 @@ export type PingRequest = z.infer<typeof PingRequestSchema>;
861926export type Progress = z . infer < typeof ProgressSchema > ;
862927export type ProgressNotification = z . infer < typeof ProgressNotificationSchema > ;
863928
929+ /* Pagination */
930+ export type PaginatedRequest = z . infer < typeof PaginatedRequestSchema > ;
931+ export type PaginatedResult = z . infer < typeof PaginatedResultSchema > ;
932+
864933/* Resources */
865934export type ResourceContents = z . infer < typeof ResourceContentsSchema > ;
866935export type TextResourceContents = z . infer < typeof TextResourceContentsSchema > ;
@@ -869,6 +938,8 @@ export type Resource = z.infer<typeof ResourceSchema>;
869938export type ResourceTemplate = z . infer < typeof ResourceTemplateSchema > ;
870939export type ListResourcesRequest = z . infer < typeof ListResourcesRequestSchema > ;
871940export type ListResourcesResult = z . infer < typeof ListResourcesResultSchema > ;
941+ export type ListResourceTemplatesRequest = z . infer < typeof ListResourceTemplatesRequestSchema > ;
942+ export type ListResourceTemplatesResult = z . infer < typeof ListResourceTemplatesResultSchema > ;
872943export type ReadResourceRequest = z . infer < typeof ReadResourceRequestSchema > ;
873944export type ReadResourceResult = z . infer < typeof ReadResourceResultSchema > ;
874945export type ResourceListChangedNotification = z . infer <
@@ -887,6 +958,9 @@ export type ListPromptsRequest = z.infer<typeof ListPromptsRequestSchema>;
887958export type ListPromptsResult = z . infer < typeof ListPromptsResultSchema > ;
888959export type GetPromptRequest = z . infer < typeof GetPromptRequestSchema > ;
889960export type GetPromptResult = z . infer < typeof GetPromptResultSchema > ;
961+ export type PromptListChangedNotification = z . infer <
962+ typeof PromptListChangedNotificationSchema
963+ > ;
890964
891965/* Tools */
892966export type Tool = z . infer < typeof ToolSchema > ;
0 commit comments