21
21
not separate types in the schema.
22
22
"""
23
23
24
+ LATEST_PROTOCOL_VERSION = "2024-10-07"
24
25
25
26
ProgressToken = str | int
27
+ Cursor = str
26
28
27
29
28
30
class RequestParams (BaseModel ):
@@ -64,6 +66,14 @@ class Request(BaseModel, Generic[RequestParamsT, MethodT]):
64
66
model_config = ConfigDict (extra = "allow" )
65
67
66
68
69
+ class PaginatedRequest (Request [RequestParamsT , MethodT ]):
70
+ cursor : Cursor | None = None
71
+ """
72
+ An opaque token representing the current pagination position.
73
+ If provided, the server should return results starting after this cursor.
74
+ """
75
+
76
+
67
77
class Notification (BaseModel , Generic [NotificationParamsT , MethodT ]):
68
78
"""Base class for JSON-RPC notifications."""
69
79
@@ -83,6 +93,14 @@ class Result(BaseModel):
83
93
"""
84
94
85
95
96
+ class PaginatedResult (Result ):
97
+ nextCursor : Cursor | None = None
98
+ """
99
+ An opaque token representing the pagination position after the last returned result.
100
+ If present, there may be more results available.
101
+ """
102
+
103
+
86
104
RequestId = str | int
87
105
88
106
@@ -115,6 +133,7 @@ class JSONRPCResponse(BaseModel):
115
133
INVALID_REQUEST = - 32600
116
134
METHOD_NOT_FOUND = - 32601
117
135
INVALID_PARAMS = - 32602
136
+ INTERNAL_ERROR = - 32603
118
137
119
138
120
139
class ErrorData (BaseModel ):
@@ -191,7 +210,7 @@ class ServerCapabilities(BaseModel):
191
210
class InitializeRequestParams (RequestParams ):
192
211
"""Parameters for the initialize request."""
193
212
194
- protocolVersion : Literal [ 1 ]
213
+ protocolVersion : str | int
195
214
"""The latest version of the Model Context Protocol that the client supports."""
196
215
capabilities : ClientCapabilities
197
216
clientInfo : Implementation
@@ -211,7 +230,7 @@ class InitializeRequest(Request):
211
230
class InitializeResult (Result ):
212
231
"""After receiving an initialize request from the client, the server sends this."""
213
232
214
- protocolVersion : Literal [ 1 ]
233
+ protocolVersion : str | int
215
234
"""The version of the Model Context Protocol that the server wants to use."""
216
235
capabilities : ServerCapabilities
217
236
serverInfo : Implementation
@@ -265,7 +284,7 @@ class ProgressNotification(Notification):
265
284
params : ProgressNotificationParams
266
285
267
286
268
- class ListResourcesRequest (Request ):
287
+ class ListResourcesRequest (PaginatedRequest ):
269
288
"""Sent from the client to request a list of resources the server has."""
270
289
271
290
method : Literal ["resources/list" ]
@@ -277,6 +296,10 @@ class Resource(BaseModel):
277
296
278
297
uri : AnyUrl
279
298
"""The URI of this resource."""
299
+ name : str
300
+ """A human-readable name for this resource."""
301
+ description : str | None = None
302
+ """A description of what this resource represents."""
280
303
mimeType : str | None = None
281
304
"""The MIME type of this resource, if known."""
282
305
model_config = ConfigDict (extra = "allow" )
@@ -290,7 +313,7 @@ class ResourceTemplate(BaseModel):
290
313
A URI template (according to RFC 6570) that can be used to construct resource
291
314
URIs.
292
315
"""
293
- name : str | None = None
316
+ name : str
294
317
"""A human-readable name for the type of resource this template refers to."""
295
318
description : str | None = None
296
319
"""A human-readable description of what this template is for."""
@@ -302,11 +325,23 @@ class ResourceTemplate(BaseModel):
302
325
model_config = ConfigDict (extra = "allow" )
303
326
304
327
305
- class ListResourcesResult (Result ):
328
+ class ListResourcesResult (PaginatedResult ):
306
329
"""The server's response to a resources/list request from the client."""
307
330
308
- resourceTemplates : list [ResourceTemplate ] | None = None
309
- resources : list [Resource ] | None = None
331
+ resources : list [Resource ]
332
+
333
+
334
+ class ListResourceTemplatesRequest (PaginatedRequest ):
335
+ """Sent from the client to request a list of resource templates the server has."""
336
+
337
+ method : Literal ["resources/templates/list" ]
338
+ params : RequestParams | None = None
339
+
340
+
341
+ class ListResourceTemplatesResult (PaginatedResult ):
342
+ """The server's response to a resources/templates/list request from the client."""
343
+
344
+ resourceTemplates : list [ResourceTemplate ]
310
345
311
346
312
347
class ReadResourceRequestParams (RequestParams ):
@@ -430,7 +465,7 @@ class ResourceUpdatedNotification(Notification):
430
465
params : ResourceUpdatedNotificationParams
431
466
432
467
433
- class ListPromptsRequest (Request ):
468
+ class ListPromptsRequest (PaginatedRequest ):
434
469
"""Sent from the client to request a list of prompts and prompt templates."""
435
470
436
471
method : Literal ["prompts/list" ]
@@ -461,7 +496,7 @@ class Prompt(BaseModel):
461
496
model_config = ConfigDict (extra = "allow" )
462
497
463
498
464
- class ListPromptsResult (Result ):
499
+ class ListPromptsResult (PaginatedResult ):
465
500
"""The server's response to a prompts/list request from the client."""
466
501
467
502
prompts : list [Prompt ]
@@ -526,7 +561,17 @@ class GetPromptResult(Result):
526
561
messages : list [SamplingMessage ]
527
562
528
563
529
- class ListToolsRequest (Request ):
564
+ class PromptListChangedNotification (Notification ):
565
+ """
566
+ An optional notification from the server to the client, informing it that the list
567
+ of prompts it offers has changed.
568
+ """
569
+
570
+ method : Literal ["notifications/prompts/list_changed" ]
571
+ params : NotificationParams | None = None
572
+
573
+
574
+ class ListToolsRequest (PaginatedRequest ):
530
575
"""Sent from the client to request a list of tools the server has."""
531
576
532
577
method : Literal ["tools/list" ]
@@ -545,7 +590,7 @@ class Tool(BaseModel):
545
590
model_config = ConfigDict (extra = "allow" )
546
591
547
592
548
- class ListToolsResult (Result ):
593
+ class ListToolsResult (PaginatedResult ):
549
594
"""The server's response to a tools/list request from the client."""
550
595
551
596
tools : list [Tool ]
@@ -742,6 +787,7 @@ class ClientRequest(
742
787
| GetPromptRequest
743
788
| ListPromptsRequest
744
789
| ListResourcesRequest
790
+ | ListResourceTemplatesRequest
745
791
| ReadResourceRequest
746
792
| SubscribeRequest
747
793
| UnsubscribeRequest
@@ -771,6 +817,7 @@ class ServerNotification(
771
817
| ResourceUpdatedNotification
772
818
| ResourceListChangedNotification
773
819
| ToolListChangedNotification
820
+ | PromptListChangedNotification
774
821
]
775
822
):
776
823
pass
@@ -784,6 +831,7 @@ class ServerResult(
784
831
| GetPromptResult
785
832
| ListPromptsResult
786
833
| ListResourcesResult
834
+ | ListResourceTemplatesResult
787
835
| ReadResourceResult
788
836
| CallToolResult
789
837
| ListToolsResult
0 commit comments