@@ -64,8 +64,10 @@ class Meta(BaseModel):
64
64
"""
65
65
66
66
67
- RequestParamsT = TypeVar ("RequestParamsT" , bound = RequestParams )
68
- NotificationParamsT = TypeVar ("NotificationParamsT" , bound = NotificationParams )
67
+ RequestParamsT = TypeVar ("RequestParamsT" , bound = RequestParams | dict [str , Any ] | None )
68
+ NotificationParamsT = TypeVar (
69
+ "NotificationParamsT" , bound = NotificationParams | dict [str , Any ] | None
70
+ )
69
71
MethodT = TypeVar ("MethodT" , bound = str )
70
72
71
73
@@ -113,15 +115,16 @@ class PaginatedResult(Result):
113
115
"""
114
116
115
117
116
- class JSONRPCRequest (Request ):
118
+ class JSONRPCRequest (Request [ dict [ str , Any ] | None , str ] ):
117
119
"""A request that expects a response."""
118
120
119
121
jsonrpc : Literal ["2.0" ]
120
122
id : RequestId
123
+ method : str
121
124
params : dict [str , Any ] | None = None
122
125
123
126
124
- class JSONRPCNotification (Notification ):
127
+ class JSONRPCNotification (Notification [ dict [ str , Any ] | None , str ] ):
125
128
"""A notification which does not expect a response."""
126
129
127
130
jsonrpc : Literal ["2.0" ]
@@ -277,7 +280,7 @@ class InitializeRequestParams(RequestParams):
277
280
model_config = ConfigDict (extra = "allow" )
278
281
279
282
280
- class InitializeRequest (Request ):
283
+ class InitializeRequest (Request [ InitializeRequestParams , Literal [ "initialize" ]] ):
281
284
"""
282
285
This request is sent from the client to the server when it first connects, asking it
283
286
to begin initialization.
@@ -298,7 +301,9 @@ class InitializeResult(Result):
298
301
"""Instructions describing how to use the server and its features."""
299
302
300
303
301
- class InitializedNotification (Notification ):
304
+ class InitializedNotification (
305
+ Notification [NotificationParams | None , Literal ["notifications/initialized" ]]
306
+ ):
302
307
"""
303
308
This notification is sent from the client to the server after initialization has
304
309
finished.
@@ -308,7 +313,7 @@ class InitializedNotification(Notification):
308
313
params : NotificationParams | None = None
309
314
310
315
311
- class PingRequest (Request ):
316
+ class PingRequest (Request [ RequestParams | None , Literal [ "ping" ]] ):
312
317
"""
313
318
A ping, issued by either the server or the client, to check that the other party is
314
319
still alive.
@@ -336,7 +341,9 @@ class ProgressNotificationParams(NotificationParams):
336
341
model_config = ConfigDict (extra = "allow" )
337
342
338
343
339
- class ProgressNotification (Notification ):
344
+ class ProgressNotification (
345
+ Notification [ProgressNotificationParams , Literal ["notifications/progress" ]]
346
+ ):
340
347
"""
341
348
An out-of-band notification used to inform the receiver of a progress update for a
342
349
long-running request.
@@ -346,7 +353,9 @@ class ProgressNotification(Notification):
346
353
params : ProgressNotificationParams
347
354
348
355
349
- class ListResourcesRequest (PaginatedRequest ):
356
+ class ListResourcesRequest (
357
+ PaginatedRequest [RequestParams | None , Literal ["resources/list" ]]
358
+ ):
350
359
"""Sent from the client to request a list of resources the server has."""
351
360
352
361
method : Literal ["resources/list" ]
@@ -408,7 +417,9 @@ class ListResourcesResult(PaginatedResult):
408
417
resources : list [Resource ]
409
418
410
419
411
- class ListResourceTemplatesRequest (PaginatedRequest ):
420
+ class ListResourceTemplatesRequest (
421
+ PaginatedRequest [RequestParams | None , Literal ["resources/templates/list" ]]
422
+ ):
412
423
"""Sent from the client to request a list of resource templates the server has."""
413
424
414
425
method : Literal ["resources/templates/list" ]
@@ -432,7 +443,9 @@ class ReadResourceRequestParams(RequestParams):
432
443
model_config = ConfigDict (extra = "allow" )
433
444
434
445
435
- class ReadResourceRequest (Request ):
446
+ class ReadResourceRequest (
447
+ Request [ReadResourceRequestParams , Literal ["resources/read" ]]
448
+ ):
436
449
"""Sent from the client to the server, to read a specific resource URI."""
437
450
438
451
method : Literal ["resources/read" ]
@@ -472,7 +485,11 @@ class ReadResourceResult(Result):
472
485
contents : list [TextResourceContents | BlobResourceContents ]
473
486
474
487
475
- class ResourceListChangedNotification (Notification ):
488
+ class ResourceListChangedNotification (
489
+ Notification [
490
+ NotificationParams | None , Literal ["notifications/resources/list_changed" ]
491
+ ]
492
+ ):
476
493
"""
477
494
An optional notification from the server to the client, informing it that the list
478
495
of resources it can read from has changed.
@@ -493,7 +510,7 @@ class SubscribeRequestParams(RequestParams):
493
510
model_config = ConfigDict (extra = "allow" )
494
511
495
512
496
- class SubscribeRequest (Request ):
513
+ class SubscribeRequest (Request [ SubscribeRequestParams , Literal [ "resources/subscribe" ]] ):
497
514
"""
498
515
Sent from the client to request resources/updated notifications from the server
499
516
whenever a particular resource changes.
@@ -511,7 +528,9 @@ class UnsubscribeRequestParams(RequestParams):
511
528
model_config = ConfigDict (extra = "allow" )
512
529
513
530
514
- class UnsubscribeRequest (Request ):
531
+ class UnsubscribeRequest (
532
+ Request [UnsubscribeRequestParams , Literal ["resources/unsubscribe" ]]
533
+ ):
515
534
"""
516
535
Sent from the client to request cancellation of resources/updated notifications from
517
536
the server.
@@ -532,7 +551,11 @@ class ResourceUpdatedNotificationParams(NotificationParams):
532
551
model_config = ConfigDict (extra = "allow" )
533
552
534
553
535
- class ResourceUpdatedNotification (Notification ):
554
+ class ResourceUpdatedNotification (
555
+ Notification [
556
+ ResourceUpdatedNotificationParams , Literal ["notifications/resources/updated" ]
557
+ ]
558
+ ):
536
559
"""
537
560
A notification from the server to the client, informing it that a resource has
538
561
changed and may need to be read again.
@@ -542,7 +565,9 @@ class ResourceUpdatedNotification(Notification):
542
565
params : ResourceUpdatedNotificationParams
543
566
544
567
545
- class ListPromptsRequest (PaginatedRequest ):
568
+ class ListPromptsRequest (
569
+ PaginatedRequest [RequestParams | None , Literal ["prompts/list" ]]
570
+ ):
546
571
"""Sent from the client to request a list of prompts and prompt templates."""
547
572
548
573
method : Literal ["prompts/list" ]
@@ -589,7 +614,7 @@ class GetPromptRequestParams(RequestParams):
589
614
model_config = ConfigDict (extra = "allow" )
590
615
591
616
592
- class GetPromptRequest (Request ):
617
+ class GetPromptRequest (Request [ GetPromptRequestParams , Literal [ "prompts/get" ]] ):
593
618
"""Used by the client to get a prompt provided by the server."""
594
619
595
620
method : Literal ["prompts/get" ]
@@ -659,7 +684,11 @@ class GetPromptResult(Result):
659
684
messages : list [PromptMessage ]
660
685
661
686
662
- class PromptListChangedNotification (Notification ):
687
+ class PromptListChangedNotification (
688
+ Notification [
689
+ NotificationParams | None , Literal ["notifications/prompts/list_changed" ]
690
+ ]
691
+ ):
663
692
"""
664
693
An optional notification from the server to the client, informing it that the list
665
694
of prompts it offers has changed.
@@ -669,7 +698,7 @@ class PromptListChangedNotification(Notification):
669
698
params : NotificationParams | None = None
670
699
671
700
672
- class ListToolsRequest (PaginatedRequest ):
701
+ class ListToolsRequest (PaginatedRequest [ RequestParams | None , Literal [ "tools/list" ]] ):
673
702
"""Sent from the client to request a list of tools the server has."""
674
703
675
704
method : Literal ["tools/list" ]
@@ -702,7 +731,7 @@ class CallToolRequestParams(RequestParams):
702
731
model_config = ConfigDict (extra = "allow" )
703
732
704
733
705
- class CallToolRequest (Request ):
734
+ class CallToolRequest (Request [ CallToolRequestParams , Literal [ "tools/call" ]] ):
706
735
"""Used by the client to invoke a tool provided by the server."""
707
736
708
737
method : Literal ["tools/call" ]
@@ -716,7 +745,9 @@ class CallToolResult(Result):
716
745
isError : bool = False
717
746
718
747
719
- class ToolListChangedNotification (Notification ):
748
+ class ToolListChangedNotification (
749
+ Notification [NotificationParams | None , Literal ["notifications/tools/list_changed" ]]
750
+ ):
720
751
"""
721
752
An optional notification from the server to the client, informing it that the list
722
753
of tools it offers has changed.
@@ -739,7 +770,7 @@ class SetLevelRequestParams(RequestParams):
739
770
model_config = ConfigDict (extra = "allow" )
740
771
741
772
742
- class SetLevelRequest (Request ):
773
+ class SetLevelRequest (Request [ SetLevelRequestParams , Literal [ "logging/setLevel" ]] ):
743
774
"""A request from the client to the server, to enable or adjust logging."""
744
775
745
776
method : Literal ["logging/setLevel" ]
@@ -761,7 +792,9 @@ class LoggingMessageNotificationParams(NotificationParams):
761
792
model_config = ConfigDict (extra = "allow" )
762
793
763
794
764
- class LoggingMessageNotification (Notification ):
795
+ class LoggingMessageNotification (
796
+ Notification [LoggingMessageNotificationParams , Literal ["notifications/message" ]]
797
+ ):
765
798
"""Notification of a log message passed from server to client."""
766
799
767
800
method : Literal ["notifications/message" ]
@@ -856,7 +889,9 @@ class CreateMessageRequestParams(RequestParams):
856
889
model_config = ConfigDict (extra = "allow" )
857
890
858
891
859
- class CreateMessageRequest (Request ):
892
+ class CreateMessageRequest (
893
+ Request [CreateMessageRequestParams , Literal ["sampling/createMessage" ]]
894
+ ):
860
895
"""A request from the server to sample an LLM via the client."""
861
896
862
897
method : Literal ["sampling/createMessage" ]
@@ -913,7 +948,7 @@ class CompleteRequestParams(RequestParams):
913
948
model_config = ConfigDict (extra = "allow" )
914
949
915
950
916
- class CompleteRequest (Request ):
951
+ class CompleteRequest (Request [ CompleteRequestParams , Literal [ "completion/complete" ]] ):
917
952
"""A request from the client to the server, to ask for completion options."""
918
953
919
954
method : Literal ["completion/complete" ]
@@ -944,7 +979,7 @@ class CompleteResult(Result):
944
979
completion : Completion
945
980
946
981
947
- class ListRootsRequest (Request ):
982
+ class ListRootsRequest (Request [ RequestParams | None , Literal [ "roots/list" ]] ):
948
983
"""
949
984
Sent from the server to request a list of root URIs from the client. Roots allow
950
985
servers to ask for specific directories or files to operate on. A common example
@@ -987,7 +1022,9 @@ class ListRootsResult(Result):
987
1022
roots : list [Root ]
988
1023
989
1024
990
- class RootsListChangedNotification (Notification ):
1025
+ class RootsListChangedNotification (
1026
+ Notification [NotificationParams | None , Literal ["notifications/roots/list_changed" ]]
1027
+ ):
991
1028
"""
992
1029
A notification from the client to the server, informing it that the list of
993
1030
roots has changed.
0 commit comments