UNPKG

@modelcontextprotocol/sdk

Version:

Model Context Protocol implementation for TypeScript

1,031 lines 38.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImageContentSchema = exports.TextContentSchema = exports.GetPromptRequestSchema = exports.ListPromptsResultSchema = exports.ListPromptsRequestSchema = exports.PromptSchema = exports.PromptArgumentSchema = exports.ResourceUpdatedNotificationSchema = exports.UnsubscribeRequestSchema = exports.SubscribeRequestSchema = exports.ResourceListChangedNotificationSchema = exports.ReadResourceResultSchema = exports.ReadResourceRequestSchema = exports.ListResourceTemplatesResultSchema = exports.ListResourceTemplatesRequestSchema = exports.ListResourcesResultSchema = exports.ListResourcesRequestSchema = exports.ResourceTemplateSchema = exports.ResourceSchema = exports.BlobResourceContentsSchema = exports.TextResourceContentsSchema = exports.ResourceContentsSchema = exports.PaginatedResultSchema = exports.PaginatedRequestSchema = exports.ProgressNotificationSchema = exports.ProgressSchema = exports.PingRequestSchema = exports.InitializedNotificationSchema = exports.InitializeResultSchema = exports.ServerCapabilitiesSchema = exports.InitializeRequestSchema = exports.ClientCapabilitiesSchema = exports.ImplementationSchema = exports.CancelledNotificationSchema = exports.EmptyResultSchema = exports.JSONRPCMessageSchema = exports.JSONRPCErrorSchema = exports.ErrorCode = exports.JSONRPCResponseSchema = exports.JSONRPCNotificationSchema = exports.JSONRPCRequestSchema = exports.RequestIdSchema = exports.ResultSchema = exports.NotificationSchema = exports.RequestSchema = exports.CursorSchema = exports.ProgressTokenSchema = exports.JSONRPC_VERSION = exports.SUPPORTED_PROTOCOL_VERSIONS = exports.LATEST_PROTOCOL_VERSION = void 0; exports.McpError = exports.ServerResultSchema = exports.ServerNotificationSchema = exports.ServerRequestSchema = exports.ClientResultSchema = exports.ClientNotificationSchema = exports.ClientRequestSchema = exports.RootsListChangedNotificationSchema = exports.ListRootsResultSchema = exports.ListRootsRequestSchema = exports.RootSchema = exports.CompleteResultSchema = exports.CompleteRequestSchema = exports.PromptReferenceSchema = exports.ResourceReferenceSchema = exports.CreateMessageResultSchema = exports.CreateMessageRequestSchema = exports.SamplingMessageSchema = exports.ModelPreferencesSchema = exports.ModelHintSchema = exports.LoggingMessageNotificationSchema = exports.SetLevelRequestSchema = exports.LoggingLevelSchema = exports.ToolListChangedNotificationSchema = exports.CallToolRequestSchema = exports.CompatibilityCallToolResultSchema = exports.CallToolResultSchema = exports.ListToolsResultSchema = exports.ListToolsRequestSchema = exports.ToolSchema = exports.PromptListChangedNotificationSchema = exports.GetPromptResultSchema = exports.PromptMessageSchema = exports.EmbeddedResourceSchema = exports.AudioContentSchema = void 0; const zod_1 = require("zod"); exports.LATEST_PROTOCOL_VERSION = "2024-11-05"; exports.SUPPORTED_PROTOCOL_VERSIONS = [ exports.LATEST_PROTOCOL_VERSION, "2024-10-07", ]; /* JSON-RPC types */ exports.JSONRPC_VERSION = "2.0"; /** * A progress token, used to associate progress notifications with the original request. */ exports.ProgressTokenSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number().int()]); /** * An opaque token used to represent a cursor for pagination. */ exports.CursorSchema = zod_1.z.string(); const BaseRequestParamsSchema = zod_1.z .object({ _meta: zod_1.z.optional(zod_1.z .object({ /** * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. */ progressToken: zod_1.z.optional(exports.ProgressTokenSchema), }) .passthrough()), }) .passthrough(); exports.RequestSchema = zod_1.z.object({ method: zod_1.z.string(), params: zod_1.z.optional(BaseRequestParamsSchema), }); const BaseNotificationParamsSchema = zod_1.z .object({ /** * This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications. */ _meta: zod_1.z.optional(zod_1.z.object({}).passthrough()), }) .passthrough(); exports.NotificationSchema = zod_1.z.object({ method: zod_1.z.string(), params: zod_1.z.optional(BaseNotificationParamsSchema), }); exports.ResultSchema = zod_1.z .object({ /** * This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses. */ _meta: zod_1.z.optional(zod_1.z.object({}).passthrough()), }) .passthrough(); /** * A uniquely identifying ID for a request in JSON-RPC. */ exports.RequestIdSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number().int()]); /** * A request that expects a response. */ exports.JSONRPCRequestSchema = zod_1.z .object({ jsonrpc: zod_1.z.literal(exports.JSONRPC_VERSION), id: exports.RequestIdSchema, }) .merge(exports.RequestSchema) .strict(); /** * A notification which does not expect a response. */ exports.JSONRPCNotificationSchema = zod_1.z .object({ jsonrpc: zod_1.z.literal(exports.JSONRPC_VERSION), }) .merge(exports.NotificationSchema) .strict(); /** * A successful (non-error) response to a request. */ exports.JSONRPCResponseSchema = zod_1.z .object({ jsonrpc: zod_1.z.literal(exports.JSONRPC_VERSION), id: exports.RequestIdSchema, result: exports.ResultSchema, }) .strict(); /** * Error codes defined by the JSON-RPC specification. */ var ErrorCode; (function (ErrorCode) { // SDK error codes ErrorCode[ErrorCode["ConnectionClosed"] = -32000] = "ConnectionClosed"; ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout"; // Standard JSON-RPC error codes ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError"; ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest"; ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound"; ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams"; ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError"; })(ErrorCode || (exports.ErrorCode = ErrorCode = {})); /** * A response to a request that indicates an error occurred. */ exports.JSONRPCErrorSchema = zod_1.z .object({ jsonrpc: zod_1.z.literal(exports.JSONRPC_VERSION), id: exports.RequestIdSchema, error: zod_1.z.object({ /** * The error type that occurred. */ code: zod_1.z.number().int(), /** * A short description of the error. The message SHOULD be limited to a concise single sentence. */ message: zod_1.z.string(), /** * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.). */ data: zod_1.z.optional(zod_1.z.unknown()), }), }) .strict(); exports.JSONRPCMessageSchema = zod_1.z.union([ exports.JSONRPCRequestSchema, exports.JSONRPCNotificationSchema, exports.JSONRPCResponseSchema, exports.JSONRPCErrorSchema, ]); /* Empty result */ /** * A response that indicates success but carries no data. */ exports.EmptyResultSchema = exports.ResultSchema.strict(); /* Cancellation */ /** * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. * * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. * * This notification indicates that the result will be unused, so any associated processing SHOULD cease. * * A client MUST NOT attempt to cancel its `initialize` request. */ exports.CancelledNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/cancelled"), params: BaseNotificationParamsSchema.extend({ /** * The ID of the request to cancel. * * This MUST correspond to the ID of a request previously issued in the same direction. */ requestId: exports.RequestIdSchema, /** * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. */ reason: zod_1.z.string().optional(), }), }); /* Initialization */ /** * Describes the name and version of an MCP implementation. */ exports.ImplementationSchema = zod_1.z .object({ name: zod_1.z.string(), version: zod_1.z.string(), }) .passthrough(); /** * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. */ exports.ClientCapabilitiesSchema = zod_1.z .object({ /** * Experimental, non-standard capabilities that the client supports. */ experimental: zod_1.z.optional(zod_1.z.object({}).passthrough()), /** * Present if the client supports sampling from an LLM. */ sampling: zod_1.z.optional(zod_1.z.object({}).passthrough()), /** * Present if the client supports listing roots. */ roots: zod_1.z.optional(zod_1.z .object({ /** * Whether the client supports issuing notifications for changes to the roots list. */ listChanged: zod_1.z.optional(zod_1.z.boolean()), }) .passthrough()), }) .passthrough(); /** * This request is sent from the client to the server when it first connects, asking it to begin initialization. */ exports.InitializeRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("initialize"), params: BaseRequestParamsSchema.extend({ /** * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. */ protocolVersion: zod_1.z.string(), capabilities: exports.ClientCapabilitiesSchema, clientInfo: exports.ImplementationSchema, }), }); /** * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. */ exports.ServerCapabilitiesSchema = zod_1.z .object({ /** * Experimental, non-standard capabilities that the server supports. */ experimental: zod_1.z.optional(zod_1.z.object({}).passthrough()), /** * Present if the server supports sending log messages to the client. */ logging: zod_1.z.optional(zod_1.z.object({}).passthrough()), /** * Present if the server supports sending completions to the client. */ completions: zod_1.z.optional(zod_1.z.object({}).passthrough()), /** * Present if the server offers any prompt templates. */ prompts: zod_1.z.optional(zod_1.z .object({ /** * Whether this server supports issuing notifications for changes to the prompt list. */ listChanged: zod_1.z.optional(zod_1.z.boolean()), }) .passthrough()), /** * Present if the server offers any resources to read. */ resources: zod_1.z.optional(zod_1.z .object({ /** * Whether this server supports clients subscribing to resource updates. */ subscribe: zod_1.z.optional(zod_1.z.boolean()), /** * Whether this server supports issuing notifications for changes to the resource list. */ listChanged: zod_1.z.optional(zod_1.z.boolean()), }) .passthrough()), /** * Present if the server offers any tools to call. */ tools: zod_1.z.optional(zod_1.z .object({ /** * Whether this server supports issuing notifications for changes to the tool list. */ listChanged: zod_1.z.optional(zod_1.z.boolean()), }) .passthrough()), }) .passthrough(); /** * After receiving an initialize request from the client, the server sends this response. */ exports.InitializeResultSchema = exports.ResultSchema.extend({ /** * 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. */ protocolVersion: zod_1.z.string(), capabilities: exports.ServerCapabilitiesSchema, serverInfo: exports.ImplementationSchema, /** * Instructions describing how to use the server and its features. * * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. */ instructions: zod_1.z.optional(zod_1.z.string()), }); /** * This notification is sent from the client to the server after initialization has finished. */ exports.InitializedNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/initialized"), }); /* Ping */ /** * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. */ exports.PingRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("ping"), }); /* Progress notifications */ exports.ProgressSchema = zod_1.z .object({ /** * The progress thus far. This should increase every time progress is made, even if the total is unknown. */ progress: zod_1.z.number(), /** * Total number of items to process (or total progress required), if known. */ total: zod_1.z.optional(zod_1.z.number()), }) .passthrough(); /** * An out-of-band notification used to inform the receiver of a progress update for a long-running request. */ exports.ProgressNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/progress"), params: BaseNotificationParamsSchema.merge(exports.ProgressSchema).extend({ /** * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding. */ progressToken: exports.ProgressTokenSchema, }), }); /* Pagination */ exports.PaginatedRequestSchema = exports.RequestSchema.extend({ params: BaseRequestParamsSchema.extend({ /** * An opaque token representing the current pagination position. * If provided, the server should return results starting after this cursor. */ cursor: zod_1.z.optional(exports.CursorSchema), }).optional(), }); exports.PaginatedResultSchema = exports.ResultSchema.extend({ /** * An opaque token representing the pagination position after the last returned result. * If present, there may be more results available. */ nextCursor: zod_1.z.optional(exports.CursorSchema), }); /* Resources */ /** * The contents of a specific resource or sub-resource. */ exports.ResourceContentsSchema = zod_1.z .object({ /** * The URI of this resource. */ uri: zod_1.z.string(), /** * The MIME type of this resource, if known. */ mimeType: zod_1.z.optional(zod_1.z.string()), }) .passthrough(); exports.TextResourceContentsSchema = exports.ResourceContentsSchema.extend({ /** * The text of the item. This must only be set if the item can actually be represented as text (not binary data). */ text: zod_1.z.string(), }); exports.BlobResourceContentsSchema = exports.ResourceContentsSchema.extend({ /** * A base64-encoded string representing the binary data of the item. */ blob: zod_1.z.string().base64(), }); /** * A known resource that the server is capable of reading. */ exports.ResourceSchema = zod_1.z .object({ /** * The URI of this resource. */ uri: zod_1.z.string(), /** * A human-readable name for this resource. * * This can be used by clients to populate UI elements. */ name: zod_1.z.string(), /** * A description of what this resource represents. * * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. */ description: zod_1.z.optional(zod_1.z.string()), /** * The MIME type of this resource, if known. */ mimeType: zod_1.z.optional(zod_1.z.string()), }) .passthrough(); /** * A template description for resources available on the server. */ exports.ResourceTemplateSchema = zod_1.z .object({ /** * A URI template (according to RFC 6570) that can be used to construct resource URIs. */ uriTemplate: zod_1.z.string(), /** * A human-readable name for the type of resource this template refers to. * * This can be used by clients to populate UI elements. */ name: zod_1.z.string(), /** * A description of what this template is for. * * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. */ description: zod_1.z.optional(zod_1.z.string()), /** * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type. */ mimeType: zod_1.z.optional(zod_1.z.string()), }) .passthrough(); /** * Sent from the client to request a list of resources the server has. */ exports.ListResourcesRequestSchema = exports.PaginatedRequestSchema.extend({ method: zod_1.z.literal("resources/list"), }); /** * The server's response to a resources/list request from the client. */ exports.ListResourcesResultSchema = exports.PaginatedResultSchema.extend({ resources: zod_1.z.array(exports.ResourceSchema), }); /** * Sent from the client to request a list of resource templates the server has. */ exports.ListResourceTemplatesRequestSchema = exports.PaginatedRequestSchema.extend({ method: zod_1.z.literal("resources/templates/list"), }); /** * The server's response to a resources/templates/list request from the client. */ exports.ListResourceTemplatesResultSchema = exports.PaginatedResultSchema.extend({ resourceTemplates: zod_1.z.array(exports.ResourceTemplateSchema), }); /** * Sent from the client to the server, to read a specific resource URI. */ exports.ReadResourceRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("resources/read"), params: BaseRequestParamsSchema.extend({ /** * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it. */ uri: zod_1.z.string(), }), }); /** * The server's response to a resources/read request from the client. */ exports.ReadResourceResultSchema = exports.ResultSchema.extend({ contents: zod_1.z.array(zod_1.z.union([exports.TextResourceContentsSchema, exports.BlobResourceContentsSchema])), }); /** * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. */ exports.ResourceListChangedNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/resources/list_changed"), }); /** * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. */ exports.SubscribeRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("resources/subscribe"), params: BaseRequestParamsSchema.extend({ /** * The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it. */ uri: zod_1.z.string(), }), }); /** * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. */ exports.UnsubscribeRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("resources/unsubscribe"), params: BaseRequestParamsSchema.extend({ /** * The URI of the resource to unsubscribe from. */ uri: zod_1.z.string(), }), }); /** * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. */ exports.ResourceUpdatedNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/resources/updated"), params: BaseNotificationParamsSchema.extend({ /** * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. */ uri: zod_1.z.string(), }), }); /* Prompts */ /** * Describes an argument that a prompt can accept. */ exports.PromptArgumentSchema = zod_1.z .object({ /** * The name of the argument. */ name: zod_1.z.string(), /** * A human-readable description of the argument. */ description: zod_1.z.optional(zod_1.z.string()), /** * Whether this argument must be provided. */ required: zod_1.z.optional(zod_1.z.boolean()), }) .passthrough(); /** * A prompt or prompt template that the server offers. */ exports.PromptSchema = zod_1.z .object({ /** * The name of the prompt or prompt template. */ name: zod_1.z.string(), /** * An optional description of what this prompt provides */ description: zod_1.z.optional(zod_1.z.string()), /** * A list of arguments to use for templating the prompt. */ arguments: zod_1.z.optional(zod_1.z.array(exports.PromptArgumentSchema)), }) .passthrough(); /** * Sent from the client to request a list of prompts and prompt templates the server has. */ exports.ListPromptsRequestSchema = exports.PaginatedRequestSchema.extend({ method: zod_1.z.literal("prompts/list"), }); /** * The server's response to a prompts/list request from the client. */ exports.ListPromptsResultSchema = exports.PaginatedResultSchema.extend({ prompts: zod_1.z.array(exports.PromptSchema), }); /** * Used by the client to get a prompt provided by the server. */ exports.GetPromptRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("prompts/get"), params: BaseRequestParamsSchema.extend({ /** * The name of the prompt or prompt template. */ name: zod_1.z.string(), /** * Arguments to use for templating the prompt. */ arguments: zod_1.z.optional(zod_1.z.record(zod_1.z.string())), }), }); /** * Text provided to or from an LLM. */ exports.TextContentSchema = zod_1.z .object({ type: zod_1.z.literal("text"), /** * The text content of the message. */ text: zod_1.z.string(), }) .passthrough(); /** * An image provided to or from an LLM. */ exports.ImageContentSchema = zod_1.z .object({ type: zod_1.z.literal("image"), /** * The base64-encoded image data. */ data: zod_1.z.string().base64(), /** * The MIME type of the image. Different providers may support different image types. */ mimeType: zod_1.z.string(), }) .passthrough(); /** * An Audio provided to or from an LLM. */ exports.AudioContentSchema = zod_1.z .object({ type: zod_1.z.literal("audio"), /** * The base64-encoded audio data. */ data: zod_1.z.string().base64(), /** * The MIME type of the audio. Different providers may support different audio types. */ mimeType: zod_1.z.string(), }) .passthrough(); /** * The contents of a resource, embedded into a prompt or tool call result. */ exports.EmbeddedResourceSchema = zod_1.z .object({ type: zod_1.z.literal("resource"), resource: zod_1.z.union([exports.TextResourceContentsSchema, exports.BlobResourceContentsSchema]), }) .passthrough(); /** * Describes a message returned as part of a prompt. */ exports.PromptMessageSchema = zod_1.z .object({ role: zod_1.z.enum(["user", "assistant"]), content: zod_1.z.union([ exports.TextContentSchema, exports.ImageContentSchema, exports.AudioContentSchema, exports.EmbeddedResourceSchema, ]), }) .passthrough(); /** * The server's response to a prompts/get request from the client. */ exports.GetPromptResultSchema = exports.ResultSchema.extend({ /** * An optional description for the prompt. */ description: zod_1.z.optional(zod_1.z.string()), messages: zod_1.z.array(exports.PromptMessageSchema), }); /** * 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. */ exports.PromptListChangedNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/prompts/list_changed"), }); /* Tools */ /** * Definition for a tool the client can call. */ exports.ToolSchema = zod_1.z .object({ /** * The name of the tool. */ name: zod_1.z.string(), /** * A human-readable description of the tool. */ description: zod_1.z.optional(zod_1.z.string()), /** * A JSON Schema object defining the expected parameters for the tool. */ inputSchema: zod_1.z .object({ type: zod_1.z.literal("object"), properties: zod_1.z.optional(zod_1.z.object({}).passthrough()), }) .passthrough(), }) .passthrough(); /** * Sent from the client to request a list of tools the server has. */ exports.ListToolsRequestSchema = exports.PaginatedRequestSchema.extend({ method: zod_1.z.literal("tools/list"), }); /** * The server's response to a tools/list request from the client. */ exports.ListToolsResultSchema = exports.PaginatedResultSchema.extend({ tools: zod_1.z.array(exports.ToolSchema), }); /** * The server's response to a tool call. */ exports.CallToolResultSchema = exports.ResultSchema.extend({ content: zod_1.z.array(zod_1.z.union([exports.TextContentSchema, exports.ImageContentSchema, exports.AudioContentSchema, exports.EmbeddedResourceSchema])), isError: zod_1.z.boolean().default(false).optional(), }); /** * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07. */ exports.CompatibilityCallToolResultSchema = exports.CallToolResultSchema.or(exports.ResultSchema.extend({ toolResult: zod_1.z.unknown(), })); /** * Used by the client to invoke a tool provided by the server. */ exports.CallToolRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("tools/call"), params: BaseRequestParamsSchema.extend({ name: zod_1.z.string(), arguments: zod_1.z.optional(zod_1.z.record(zod_1.z.unknown())), }), }); /** * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. */ exports.ToolListChangedNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/tools/list_changed"), }); /* Logging */ /** * The severity of a log message. */ exports.LoggingLevelSchema = zod_1.z.enum([ "debug", "info", "notice", "warning", "error", "critical", "alert", "emergency", ]); /** * A request from the client to the server, to enable or adjust logging. */ exports.SetLevelRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("logging/setLevel"), params: BaseRequestParamsSchema.extend({ /** * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message. */ level: exports.LoggingLevelSchema, }), }); /** * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. */ exports.LoggingMessageNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/message"), params: BaseNotificationParamsSchema.extend({ /** * The severity of this log message. */ level: exports.LoggingLevelSchema, /** * An optional name of the logger issuing this message. */ logger: zod_1.z.optional(zod_1.z.string()), /** * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. */ data: zod_1.z.unknown(), }), }); /* Sampling */ /** * Hints to use for model selection. */ exports.ModelHintSchema = zod_1.z .object({ /** * A hint for a model name. */ name: zod_1.z.string().optional(), }) .passthrough(); /** * The server's preferences for model selection, requested of the client during sampling. */ exports.ModelPreferencesSchema = zod_1.z .object({ /** * Optional hints to use for model selection. */ hints: zod_1.z.optional(zod_1.z.array(exports.ModelHintSchema)), /** * How much to prioritize cost when selecting a model. */ costPriority: zod_1.z.optional(zod_1.z.number().min(0).max(1)), /** * How much to prioritize sampling speed (latency) when selecting a model. */ speedPriority: zod_1.z.optional(zod_1.z.number().min(0).max(1)), /** * How much to prioritize intelligence and capabilities when selecting a model. */ intelligencePriority: zod_1.z.optional(zod_1.z.number().min(0).max(1)), }) .passthrough(); /** * Describes a message issued to or received from an LLM API. */ exports.SamplingMessageSchema = zod_1.z .object({ role: zod_1.z.enum(["user", "assistant"]), content: zod_1.z.union([exports.TextContentSchema, exports.ImageContentSchema, exports.AudioContentSchema]), }) .passthrough(); /** * 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. */ exports.CreateMessageRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("sampling/createMessage"), params: BaseRequestParamsSchema.extend({ messages: zod_1.z.array(exports.SamplingMessageSchema), /** * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt. */ systemPrompt: zod_1.z.optional(zod_1.z.string()), /** * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request. */ includeContext: zod_1.z.optional(zod_1.z.enum(["none", "thisServer", "allServers"])), temperature: zod_1.z.optional(zod_1.z.number()), /** * The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested. */ maxTokens: zod_1.z.number().int(), stopSequences: zod_1.z.optional(zod_1.z.array(zod_1.z.string())), /** * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific. */ metadata: zod_1.z.optional(zod_1.z.object({}).passthrough()), /** * The server's preferences for which model to select. */ modelPreferences: zod_1.z.optional(exports.ModelPreferencesSchema), }), }); /** * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. */ exports.CreateMessageResultSchema = exports.ResultSchema.extend({ /** * The name of the model that generated the message. */ model: zod_1.z.string(), /** * The reason why sampling stopped. */ stopReason: zod_1.z.optional(zod_1.z.enum(["endTurn", "stopSequence", "maxTokens"]).or(zod_1.z.string())), role: zod_1.z.enum(["user", "assistant"]), content: zod_1.z.discriminatedUnion("type", [ exports.TextContentSchema, exports.ImageContentSchema, exports.AudioContentSchema ]), }); /* Autocomplete */ /** * A reference to a resource or resource template definition. */ exports.ResourceReferenceSchema = zod_1.z .object({ type: zod_1.z.literal("ref/resource"), /** * The URI or URI template of the resource. */ uri: zod_1.z.string(), }) .passthrough(); /** * Identifies a prompt. */ exports.PromptReferenceSchema = zod_1.z .object({ type: zod_1.z.literal("ref/prompt"), /** * The name of the prompt or prompt template */ name: zod_1.z.string(), }) .passthrough(); /** * A request from the client to the server, to ask for completion options. */ exports.CompleteRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("completion/complete"), params: BaseRequestParamsSchema.extend({ ref: zod_1.z.union([exports.PromptReferenceSchema, exports.ResourceReferenceSchema]), /** * The argument's information */ argument: zod_1.z .object({ /** * The name of the argument */ name: zod_1.z.string(), /** * The value of the argument to use for completion matching. */ value: zod_1.z.string(), }) .passthrough(), }), }); /** * The server's response to a completion/complete request */ exports.CompleteResultSchema = exports.ResultSchema.extend({ completion: zod_1.z .object({ /** * An array of completion values. Must not exceed 100 items. */ values: zod_1.z.array(zod_1.z.string()).max(100), /** * The total number of completion options available. This can exceed the number of values actually sent in the response. */ total: zod_1.z.optional(zod_1.z.number().int()), /** * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. */ hasMore: zod_1.z.optional(zod_1.z.boolean()), }) .passthrough(), }); /* Roots */ /** * Represents a root directory or file that the server can operate on. */ exports.RootSchema = zod_1.z .object({ /** * The URI identifying the root. This *must* start with file:// for now. */ uri: zod_1.z.string().startsWith("file://"), /** * An optional name for the root. */ name: zod_1.z.optional(zod_1.z.string()), }) .passthrough(); /** * Sent from the server to request a list of root URIs from the client. */ exports.ListRootsRequestSchema = exports.RequestSchema.extend({ method: zod_1.z.literal("roots/list"), }); /** * The client's response to a roots/list request from the server. */ exports.ListRootsResultSchema = exports.ResultSchema.extend({ roots: zod_1.z.array(exports.RootSchema), }); /** * A notification from the client to the server, informing it that the list of roots has changed. */ exports.RootsListChangedNotificationSchema = exports.NotificationSchema.extend({ method: zod_1.z.literal("notifications/roots/list_changed"), }); /* Client messages */ exports.ClientRequestSchema = zod_1.z.union([ exports.PingRequestSchema, exports.InitializeRequestSchema, exports.CompleteRequestSchema, exports.SetLevelRequestSchema, exports.GetPromptRequestSchema, exports.ListPromptsRequestSchema, exports.ListResourcesRequestSchema, exports.ListResourceTemplatesRequestSchema, exports.ReadResourceRequestSchema, exports.SubscribeRequestSchema, exports.UnsubscribeRequestSchema, exports.CallToolRequestSchema, exports.ListToolsRequestSchema, ]); exports.ClientNotificationSchema = zod_1.z.union([ exports.CancelledNotificationSchema, exports.ProgressNotificationSchema, exports.InitializedNotificationSchema, exports.RootsListChangedNotificationSchema, ]); exports.ClientResultSchema = zod_1.z.union([ exports.EmptyResultSchema, exports.CreateMessageResultSchema, exports.ListRootsResultSchema, ]); /* Server messages */ exports.ServerRequestSchema = zod_1.z.union([ exports.PingRequestSchema, exports.CreateMessageRequestSchema, exports.ListRootsRequestSchema, ]); exports.ServerNotificationSchema = zod_1.z.union([ exports.CancelledNotificationSchema, exports.ProgressNotificationSchema, exports.LoggingMessageNotificationSchema, exports.ResourceUpdatedNotificationSchema, exports.ResourceListChangedNotificationSchema, exports.ToolListChangedNotificationSchema, exports.PromptListChangedNotificationSchema, ]); exports.ServerResultSchema = zod_1.z.union([ exports.EmptyResultSchema, exports.InitializeResultSchema, exports.CompleteResultSchema, exports.GetPromptResultSchema, exports.ListPromptsResultSchema, exports.ListResourcesResultSchema, exports.ListResourceTemplatesResultSchema, exports.ReadResourceResultSchema, exports.CallToolResultSchema, exports.ListToolsResultSchema, ]); class McpError extends Error { constructor(code, message, data) { super(`MCP error ${code}: ${message}`); this.code = code; this.data = data; this.name = "McpError"; } } exports.McpError = McpError; //# sourceMappingURL=types.js.map