1
1
import { z } from "zod" ;
2
2
3
- export const PROTOCOL_VERSION = "2024-10-07 " ;
3
+ export const PROTOCOL_VERSION = "2024-11-05 " ;
4
4
5
5
/* JSON-RPC types */
6
6
export const JSONRPC_VERSION = "2.0" ;
@@ -148,46 +148,6 @@ export const JSONRPCMessageSchema = z.union([
148
148
export const EmptyResultSchema = ResultSchema . strict ( ) ;
149
149
150
150
/* Initialization */
151
- /**
152
- * Text provided to or from an LLM.
153
- */
154
- export const TextContentSchema = z
155
- . object ( {
156
- type : z . literal ( "text" ) ,
157
- /**
158
- * The text content of the message.
159
- */
160
- text : z . string ( ) ,
161
- } )
162
- . passthrough ( ) ;
163
-
164
- /**
165
- * An image provided to or from an LLM.
166
- */
167
- export const ImageContentSchema = z
168
- . object ( {
169
- type : z . literal ( "image" ) ,
170
- /**
171
- * The base64-encoded image data.
172
- */
173
- data : z . string ( ) . base64 ( ) ,
174
- /**
175
- * The MIME type of the image. Different providers may support different image types.
176
- */
177
- mimeType : z . string ( ) ,
178
- } )
179
- . passthrough ( ) ;
180
-
181
- /**
182
- * Describes a message issued to or received from an LLM API.
183
- */
184
- export const SamplingMessageSchema = z
185
- . object ( {
186
- role : z . enum ( [ "user" , "assistant" ] ) ,
187
- content : z . union ( [ TextContentSchema , ImageContentSchema ] ) ,
188
- } )
189
- . passthrough ( ) ;
190
-
191
151
/**
192
152
* Describes the name and version of an MCP implementation.
193
153
*/
@@ -211,6 +171,17 @@ export const ClientCapabilitiesSchema = z
211
171
* Present if the client supports sampling from an LLM.
212
172
*/
213
173
sampling : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
174
+ /**
175
+ * Present if the client supports listing roots.
176
+ */
177
+ roots : z . optional (
178
+ z . object ( {
179
+ /**
180
+ * Whether the client supports notifications for changes to the roots list.
181
+ */
182
+ listChanged : z . optional ( z . boolean ( ) ) ,
183
+ } ) . passthrough ( ) ,
184
+ ) ,
214
185
} )
215
186
. passthrough ( ) ;
216
187
@@ -626,6 +597,56 @@ export const GetPromptRequestSchema = RequestSchema.extend({
626
597
} ) ,
627
598
} ) ;
628
599
600
+ /**
601
+ * Text provided to or from an LLM.
602
+ */
603
+ export const TextContentSchema = z
604
+ . object ( {
605
+ type : z . literal ( "text" ) ,
606
+ /**
607
+ * The text content of the message.
608
+ */
609
+ text : z . string ( ) ,
610
+ } )
611
+ . passthrough ( ) ;
612
+
613
+ /**
614
+ * An image provided to or from an LLM.
615
+ */
616
+ export const ImageContentSchema = z
617
+ . object ( {
618
+ type : z . literal ( "image" ) ,
619
+ /**
620
+ * The base64-encoded image data.
621
+ */
622
+ data : z . string ( ) . base64 ( ) ,
623
+ /**
624
+ * The MIME type of the image. Different providers may support different image types.
625
+ */
626
+ mimeType : z . string ( ) ,
627
+ } )
628
+ . passthrough ( ) ;
629
+
630
+ /**
631
+ * The contents of a resource, embedded into a prompt or tool call result.
632
+ */
633
+ export const EmbeddedResourceSchema = z
634
+ . object ( {
635
+ type : z . literal ( "resource" ) ,
636
+ resource : z . union ( [ TextResourceContentsSchema , BlobResourceContentsSchema ] ) ,
637
+ } )
638
+ . passthrough ( ) ;
639
+
640
+ /**
641
+ * Describes a message returned as part of a prompt.
642
+ */
643
+ export const PromptMessageSchema = z
644
+ . object ( {
645
+ role : z . enum ( [ "user" , "assistant" ] ) ,
646
+ content : z . union ( [ TextContentSchema , ImageContentSchema , EmbeddedResourceSchema ] ) ,
647
+ } )
648
+ . passthrough ( ) ;
649
+
629
650
/**
630
651
* The server's response to a prompts/get request from the client.
631
652
*/
@@ -634,7 +655,7 @@ export const GetPromptResultSchema = ResultSchema.extend({
634
655
* An optional description for the prompt.
635
656
*/
636
657
description : z . optional ( z . string ( ) ) ,
637
- messages : z . array ( SamplingMessageSchema ) ,
658
+ messages : z . array ( PromptMessageSchema ) ,
638
659
} ) ;
639
660
640
661
/**
@@ -688,7 +709,8 @@ export const ListToolsResultSchema = PaginatedResultSchema.extend({
688
709
* The server's response to a tool call.
689
710
*/
690
711
export const CallToolResultSchema = ResultSchema . extend ( {
691
- toolResult : z . unknown ( ) ,
712
+ content : z . array ( z . union ( [ TextContentSchema , ImageContentSchema , EmbeddedResourceSchema ] ) ) ,
713
+ isError : z . boolean ( ) ,
692
714
} ) ;
693
715
694
716
/**
@@ -713,7 +735,16 @@ export const ToolListChangedNotificationSchema = NotificationSchema.extend({
713
735
/**
714
736
* The severity of a log message.
715
737
*/
716
- export const LoggingLevelSchema = z . enum ( [ "debug" , "info" , "warning" , "error" ] ) ;
738
+ export const LoggingLevelSchema = z . enum ( [
739
+ "debug" ,
740
+ "info" ,
741
+ "notice" ,
742
+ "warning" ,
743
+ "error" ,
744
+ "critical" ,
745
+ "alert" ,
746
+ "emergency"
747
+ ] ) ;
717
748
718
749
/**
719
750
* A request from the client to the server, to enable or adjust logging.
@@ -752,6 +783,40 @@ export const LoggingMessageNotificationSchema = NotificationSchema.extend({
752
783
} ) ;
753
784
754
785
/* Sampling */
786
+ /**
787
+ * The server's preferences for model selection, requested of the client during sampling.
788
+ */
789
+ export const ModelPreferencesSchema = z
790
+ . object ( {
791
+ /**
792
+ * Optional string hints to use for model selection.
793
+ */
794
+ hints : z . optional ( z . array ( z . record ( z . string ( ) ) ) ) ,
795
+ /**
796
+ * How much to prioritize cost when selecting a model.
797
+ */
798
+ costPriority : z . optional ( z . number ( ) . min ( 0 ) . max ( 1 ) ) ,
799
+ /**
800
+ * How much to prioritize sampling speed (latency) when selecting a model.
801
+ */
802
+ speedPriority : z . optional ( z . number ( ) . min ( 0 ) . max ( 1 ) ) ,
803
+ /**
804
+ * How much to prioritize intelligence and capabilities when selecting a model.
805
+ */
806
+ intelligencePriority : z . optional ( z . number ( ) . min ( 0 ) . max ( 1 ) ) ,
807
+ } )
808
+ . passthrough ( ) ;
809
+
810
+ /**
811
+ * Describes a message issued to or received from an LLM API.
812
+ */
813
+ export const SamplingMessageSchema = z
814
+ . object ( {
815
+ role : z . enum ( [ "user" , "assistant" ] ) ,
816
+ content : z . union ( [ TextContentSchema , ImageContentSchema ] ) ,
817
+ } )
818
+ . passthrough ( ) ;
819
+
755
820
/**
756
821
* 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.
757
822
*/
@@ -777,6 +842,10 @@ export const CreateMessageRequestSchema = RequestSchema.extend({
777
842
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
778
843
*/
779
844
metadata : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
845
+ /**
846
+ * The server's preferences for which model to select.
847
+ */
848
+ modelPreferences : z . optional ( ModelPreferencesSchema ) ,
780
849
} ) ,
781
850
} ) ;
782
851
@@ -791,7 +860,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({
791
860
/**
792
861
* The reason why sampling stopped.
793
862
*/
794
- stopReason : z . enum ( [ "endTurn" , "stopSequence" , "maxTokens" ] ) ,
863
+ stopReason : z . optional ( z . string ( ) ) ,
795
864
role : z . enum ( [ "user" , "assistant" ] ) ,
796
865
content : z . discriminatedUnion ( "type" , [
797
866
TextContentSchema ,
@@ -873,6 +942,44 @@ export const CompleteResultSchema = ResultSchema.extend({
873
942
. passthrough ( ) ,
874
943
} ) ;
875
944
945
+ /* Roots */
946
+ /**
947
+ * Represents a root directory or file that the server can operate on.
948
+ */
949
+ export const RootSchema = z
950
+ . object ( {
951
+ /**
952
+ * The URI identifying the root. This *must* start with file:// for now.
953
+ */
954
+ uri : z . string ( ) . startsWith ( "file://" ) ,
955
+ /**
956
+ * An optional name for the root.
957
+ */
958
+ name : z . optional ( z . string ( ) ) ,
959
+ } )
960
+ . passthrough ( ) ;
961
+
962
+ /**
963
+ * Sent from the server to request a list of root URIs from the client.
964
+ */
965
+ export const ListRootsRequestSchema = RequestSchema . extend ( {
966
+ method : z . literal ( "roots/list" ) ,
967
+ } ) ;
968
+
969
+ /**
970
+ * The client's response to a roots/list request from the server.
971
+ */
972
+ export const ListRootsResultSchema = ResultSchema . extend ( {
973
+ roots : z . array ( RootSchema ) ,
974
+ } ) ;
975
+
976
+ /**
977
+ * A notification from the client to the server, informing it that the list of roots has changed.
978
+ */
979
+ export const RootsListChangedNotificationSchema = NotificationSchema . extend ( {
980
+ method : z . literal ( "notifications/roots/list_changed" ) ,
981
+ } ) ;
982
+
876
983
/* Client messages */
877
984
export const ClientRequestSchema = z . union ( [
878
985
PingRequestSchema ,
@@ -887,21 +994,26 @@ export const ClientRequestSchema = z.union([
887
994
UnsubscribeRequestSchema ,
888
995
CallToolRequestSchema ,
889
996
ListToolsRequestSchema ,
997
+ ListRootsRequestSchema ,
890
998
] ) ;
891
999
892
1000
export const ClientNotificationSchema = z . union ( [
893
1001
ProgressNotificationSchema ,
894
1002
InitializedNotificationSchema ,
1003
+ RootsListChangedNotificationSchema ,
895
1004
] ) ;
1005
+
896
1006
export const ClientResultSchema = z . union ( [
897
1007
EmptyResultSchema ,
898
1008
CreateMessageResultSchema ,
1009
+ ListRootsResultSchema ,
899
1010
] ) ;
900
1011
901
1012
/* Server messages */
902
1013
export const ServerRequestSchema = z . union ( [
903
1014
PingRequestSchema ,
904
1015
CreateMessageRequestSchema ,
1016
+ ListRootsRequestSchema ,
905
1017
] ) ;
906
1018
907
1019
export const ServerNotificationSchema = z . union ( [
0 commit comments