11import { z } from "zod" ;
22
3- export const PROTOCOL_VERSION = "2024-10-07 " ;
3+ export const PROTOCOL_VERSION = "2024-11-05 " ;
44
55/* JSON-RPC types */
66export const JSONRPC_VERSION = "2.0" ;
@@ -148,46 +148,6 @@ export const JSONRPCMessageSchema = z.union([
148148export const EmptyResultSchema = ResultSchema . strict ( ) ;
149149
150150/* 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-
191151/**
192152 * Describes the name and version of an MCP implementation.
193153 */
@@ -211,6 +171,17 @@ export const ClientCapabilitiesSchema = z
211171 * Present if the client supports sampling from an LLM.
212172 */
213173 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+ ) ,
214185 } )
215186 . passthrough ( ) ;
216187
@@ -626,6 +597,56 @@ export const GetPromptRequestSchema = RequestSchema.extend({
626597 } ) ,
627598} ) ;
628599
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+
629650/**
630651 * The server's response to a prompts/get request from the client.
631652 */
@@ -634,7 +655,7 @@ export const GetPromptResultSchema = ResultSchema.extend({
634655 * An optional description for the prompt.
635656 */
636657 description : z . optional ( z . string ( ) ) ,
637- messages : z . array ( SamplingMessageSchema ) ,
658+ messages : z . array ( PromptMessageSchema ) ,
638659} ) ;
639660
640661/**
@@ -688,7 +709,8 @@ export const ListToolsResultSchema = PaginatedResultSchema.extend({
688709 * The server's response to a tool call.
689710 */
690711export const CallToolResultSchema = ResultSchema . extend ( {
691- toolResult : z . unknown ( ) ,
712+ content : z . array ( z . union ( [ TextContentSchema , ImageContentSchema , EmbeddedResourceSchema ] ) ) ,
713+ isError : z . boolean ( ) ,
692714} ) ;
693715
694716/**
@@ -713,7 +735,16 @@ export const ToolListChangedNotificationSchema = NotificationSchema.extend({
713735/**
714736 * The severity of a log message.
715737 */
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+ ] ) ;
717748
718749/**
719750 * A request from the client to the server, to enable or adjust logging.
@@ -752,6 +783,40 @@ export const LoggingMessageNotificationSchema = NotificationSchema.extend({
752783} ) ;
753784
754785/* 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+
755820/**
756821 * 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.
757822 */
@@ -777,6 +842,10 @@ export const CreateMessageRequestSchema = RequestSchema.extend({
777842 * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
778843 */
779844 metadata : z . optional ( z . object ( { } ) . passthrough ( ) ) ,
845+ /**
846+ * The server's preferences for which model to select.
847+ */
848+ modelPreferences : z . optional ( ModelPreferencesSchema ) ,
780849 } ) ,
781850} ) ;
782851
@@ -791,7 +860,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({
791860 /**
792861 * The reason why sampling stopped.
793862 */
794- stopReason : z . enum ( [ "endTurn" , "stopSequence" , "maxTokens" ] ) ,
863+ stopReason : z . optional ( z . string ( ) ) ,
795864 role : z . enum ( [ "user" , "assistant" ] ) ,
796865 content : z . discriminatedUnion ( "type" , [
797866 TextContentSchema ,
@@ -873,6 +942,44 @@ export const CompleteResultSchema = ResultSchema.extend({
873942 . passthrough ( ) ,
874943} ) ;
875944
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+
876983/* Client messages */
877984export const ClientRequestSchema = z . union ( [
878985 PingRequestSchema ,
@@ -887,21 +994,26 @@ export const ClientRequestSchema = z.union([
887994 UnsubscribeRequestSchema ,
888995 CallToolRequestSchema ,
889996 ListToolsRequestSchema ,
997+ ListRootsRequestSchema ,
890998] ) ;
891999
8921000export const ClientNotificationSchema = z . union ( [
8931001 ProgressNotificationSchema ,
8941002 InitializedNotificationSchema ,
1003+ RootsListChangedNotificationSchema ,
8951004] ) ;
1005+
8961006export const ClientResultSchema = z . union ( [
8971007 EmptyResultSchema ,
8981008 CreateMessageResultSchema ,
1009+ ListRootsResultSchema ,
8991010] ) ;
9001011
9011012/* Server messages */
9021013export const ServerRequestSchema = z . union ( [
9031014 PingRequestSchema ,
9041015 CreateMessageRequestSchema ,
1016+ ListRootsRequestSchema ,
9051017] ) ;
9061018
9071019export const ServerNotificationSchema = z . union ( [
0 commit comments