diff --git a/package-lock.json b/package-lock.json index 71b3ec9..5e68c8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@modelcontextprotocol/sdk", - "version": "1.0.3", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@modelcontextprotocol/sdk", - "version": "1.0.3", + "version": "1.1.0", "license": "MIT", "dependencies": { "content-type": "^1.0.5", diff --git a/src/types.ts b/src/types.ts index 59b055a..15acd14 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { z } from "zod"; +import { z, ZodTypeAny } from "zod"; export const LATEST_PROTOCOL_VERSION = "2024-11-05"; export const SUPPORTED_PROTOCOL_VERSIONS = [ @@ -106,7 +106,7 @@ export enum ErrorCode { // SDK error codes ConnectionClosed = -32000, RequestTimeout = -32001, - + // Standard JSON-RPC error codes ParseError = -32700, InvalidRequest = -32600, @@ -1110,131 +1110,126 @@ export class McpError extends Error { } } +type Primitive = string | number | boolean | bigint | null | undefined; +type Flatten = T extends Primitive + ? T + : T extends Array + ? Array> + : T extends Set + ? Set> + : T extends Map + ? Map, Flatten> + : T extends object + ? { [K in keyof T]: Flatten } + : T; + +type Infer = Flatten>; + /* JSON-RPC types */ -export type ProgressToken = z.infer; -export type Cursor = z.infer; -export type Request = z.infer; -export type Notification = z.infer; -export type Result = z.infer; -export type RequestId = z.infer; -export type JSONRPCRequest = z.infer; -export type JSONRPCNotification = z.infer; -export type JSONRPCResponse = z.infer; -export type JSONRPCError = z.infer; -export type JSONRPCMessage = z.infer; +export type ProgressToken = Infer; +export type Cursor = Infer; +export type Request = Infer; +export type Notification = Infer; +export type Result = Infer; +export type RequestId = Infer; +export type JSONRPCRequest = Infer; +export type JSONRPCNotification = Infer; +export type JSONRPCResponse = Infer; +export type JSONRPCError = Infer; +export type JSONRPCMessage = Infer; /* Empty result */ -export type EmptyResult = z.infer; +export type EmptyResult = Infer; /* Cancellation */ -export type CancelledNotification = z.infer; +export type CancelledNotification = Infer; /* Initialization */ -export type Implementation = z.infer; -export type ClientCapabilities = z.infer; -export type InitializeRequest = z.infer; -export type ServerCapabilities = z.infer; -export type InitializeResult = z.infer; -export type InitializedNotification = z.infer< - typeof InitializedNotificationSchema ->; +export type Implementation = Infer; +export type ClientCapabilities = Infer; +export type InitializeRequest = Infer; +export type ServerCapabilities = Infer; +export type InitializeResult = Infer; +export type InitializedNotification = Infer; /* Ping */ -export type PingRequest = z.infer; +export type PingRequest = Infer; /* Progress notifications */ -export type Progress = z.infer; -export type ProgressNotification = z.infer; +export type Progress = Infer; +export type ProgressNotification = Infer; /* Pagination */ -export type PaginatedRequest = z.infer; -export type PaginatedResult = z.infer; +export type PaginatedRequest = Infer; +export type PaginatedResult = Infer; /* Resources */ -export type ResourceContents = z.infer; -export type TextResourceContents = z.infer; -export type BlobResourceContents = z.infer; -export type Resource = z.infer; -export type ResourceTemplate = z.infer; -export type ListResourcesRequest = z.infer; -export type ListResourcesResult = z.infer; -export type ListResourceTemplatesRequest = z.infer< - typeof ListResourceTemplatesRequestSchema ->; -export type ListResourceTemplatesResult = z.infer< - typeof ListResourceTemplatesResultSchema ->; -export type ReadResourceRequest = z.infer; -export type ReadResourceResult = z.infer; -export type ResourceListChangedNotification = z.infer< - typeof ResourceListChangedNotificationSchema ->; -export type SubscribeRequest = z.infer; -export type UnsubscribeRequest = z.infer; -export type ResourceUpdatedNotification = z.infer< - typeof ResourceUpdatedNotificationSchema ->; +export type ResourceContents = Infer; +export type TextResourceContents = Infer; +export type BlobResourceContents = Infer; +export type Resource = Infer; +export type ResourceTemplate = Infer; +export type ListResourcesRequest = Infer; +export type ListResourcesResult = Infer; +export type ListResourceTemplatesRequest = Infer; +export type ListResourceTemplatesResult = Infer; +export type ReadResourceRequest = Infer; +export type ReadResourceResult = Infer; +export type ResourceListChangedNotification = Infer; +export type SubscribeRequest = Infer; +export type UnsubscribeRequest = Infer; +export type ResourceUpdatedNotification = Infer; /* Prompts */ -export type PromptArgument = z.infer; -export type Prompt = z.infer; -export type ListPromptsRequest = z.infer; -export type ListPromptsResult = z.infer; -export type GetPromptRequest = z.infer; -export type TextContent = z.infer; -export type ImageContent = z.infer; -export type EmbeddedResource = z.infer; -export type PromptMessage = z.infer; -export type GetPromptResult = z.infer; -export type PromptListChangedNotification = z.infer< - typeof PromptListChangedNotificationSchema ->; +export type PromptArgument = Infer; +export type Prompt = Infer; +export type ListPromptsRequest = Infer; +export type ListPromptsResult = Infer; +export type GetPromptRequest = Infer; +export type TextContent = Infer; +export type ImageContent = Infer; +export type EmbeddedResource = Infer; +export type PromptMessage = Infer; +export type GetPromptResult = Infer; +export type PromptListChangedNotification = Infer; /* Tools */ -export type Tool = z.infer; -export type ListToolsRequest = z.infer; -export type ListToolsResult = z.infer; -export type CallToolResult = z.infer; -export type CompatibilityCallToolResult = z.infer< - typeof CompatibilityCallToolResultSchema ->; -export type CallToolRequest = z.infer; -export type ToolListChangedNotification = z.infer< - typeof ToolListChangedNotificationSchema ->; +export type Tool = Infer; +export type ListToolsRequest = Infer; +export type ListToolsResult = Infer; +export type CallToolResult = Infer; +export type CompatibilityCallToolResult = Infer; +export type CallToolRequest = Infer; +export type ToolListChangedNotification = Infer; /* Logging */ -export type LoggingLevel = z.infer; -export type SetLevelRequest = z.infer; -export type LoggingMessageNotification = z.infer< - typeof LoggingMessageNotificationSchema ->; +export type LoggingLevel = Infer; +export type SetLevelRequest = Infer; +export type LoggingMessageNotification = Infer; /* Sampling */ -export type SamplingMessage = z.infer; -export type CreateMessageRequest = z.infer; -export type CreateMessageResult = z.infer; +export type SamplingMessage = Infer; +export type CreateMessageRequest = Infer; +export type CreateMessageResult = Infer; /* Autocomplete */ -export type ResourceReference = z.infer; -export type PromptReference = z.infer; -export type CompleteRequest = z.infer; -export type CompleteResult = z.infer; +export type ResourceReference = Infer; +export type PromptReference = Infer; +export type CompleteRequest = Infer; +export type CompleteResult = Infer; /* Roots */ -export type Root = z.infer; -export type ListRootsRequest = z.infer; -export type ListRootsResult = z.infer; -export type RootsListChangedNotification = z.infer< - typeof RootsListChangedNotificationSchema ->; +export type Root = Infer; +export type ListRootsRequest = Infer; +export type ListRootsResult = Infer; +export type RootsListChangedNotification = Infer; /* Client messages */ -export type ClientRequest = z.infer; -export type ClientNotification = z.infer; -export type ClientResult = z.infer; +export type ClientRequest = Infer; +export type ClientNotification = Infer; +export type ClientResult = Infer; /* Server messages */ -export type ServerRequest = z.infer; -export type ServerNotification = z.infer; -export type ServerResult = z.infer; \ No newline at end of file +export type ServerRequest = Infer; +export type ServerNotification = Infer; +export type ServerResult = Infer;