UNPKG

tmcp

Version:
1,022 lines (1,002 loc) 166 kB
const created_tool: unique symbol; const created_prompt: unique symbol; const created_resource: unique symbol; const created_template: unique symbol; declare module 'tmcp' { import type { StandardSchemaV1 } from '@standard-schema/spec'; import type { JSONRPCServer, JSONRPCClient, JSONRPCParams, JSONRPCRequest } from 'json-rpc-2.0'; import type { JSONSchema7 } from 'json-schema'; import * as v from 'valibot'; export class McpServer<StandardSchema extends StandardSchemaV1 | undefined = undefined, CustomContext extends Record<string, unknown> | undefined = undefined> { constructor(server_info: ServerInfo, options: ServerOptions<StandardSchema>); roots: Array<{ uri: string; name?: string; }>; /** * Utility method to specify the type of the custom context for this server instance without the need to specify the standard schema type. * @example * const server = new McpServer({ ... }, { ... }).withContext<{ name: string }>(); * */ withContext<TCustom extends Record<string, unknown>>(): McpServer<StandardSchema, TCustom>; /** * The context of the current request, include the session ID, any auth information, and custom data. * */ get ctx(): Context<CustomContext>; /** * Get the client information (name, version, etc.) of the client that initiated the current request...useful if you want to do something different based on the client. * @deprecated Use `server.ctx.sessionInfo.clientInfo` instead. */ currentClientInfo(): { icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; version: string; websiteUrl?: string | undefined; name: string; title?: string | undefined; } | undefined; /** * Get the client capabilities of the client that initiated the current request, you can use this to verify the client support something before invoking the respective method. * @deprecated Use `server.ctx.sessionInfo.clientCapabilities` instead. */ currentClientCapabilities(): ({ experimental?: {} | undefined; sampling?: {} | undefined; elicitation?: {} | undefined; roots?: { listChanged?: boolean | undefined; } | undefined; } & { [key: string]: unknown; }) | undefined; on<TEvent extends keyof McpEvents>(event: TEvent, callback: McpEvents[TEvent], options?: AddEventListenerOptions): () => void; /** * Use the `defineTool` utility to create a reusable tool and pass it to this method to add it to the server. * */ tools<T extends Array<CreatedTool<any, any>>, U extends T extends Array<CreatedTool<infer TSchema, infer TOutputSchema>> ? AllSame<TSchema, StandardSchema | undefined> extends true ? AllSame<TOutputSchema, StandardSchema | undefined> extends true ? T : never : never : never>(tools: T & NoInfer<U>): void; /** * Use the `definePrompt` utility to create a reusable tool and pass it to this method to add it to the server. * */ prompts<T extends Array<CreatedPrompt<any>>, U extends T extends Array<CreatedPrompt<infer TSchema>> ? AllSame<TSchema, StandardSchema | undefined> extends true ? T : never : never>(prompts: T & NoInfer<U>): void; /** * Use the `defineResource` utility to create a reusable resource and pass it to this method to add it to the server. * * */ resources(resources: CreatedResource[]): void; /** * Use the `defineTemplate` utility to create a reusable template and pass it to this method to add it to the server. * * */ templates(templates: CreatedTemplate<any>[]): void; /** * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need, * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema. * * Tools will be invoked by the LLM when it thinks it needs to use them, you can use the annotations to provide additional information about the tool, like what it does, how to use it, etc. * */ tool<TSchema extends StandardSchema | undefined = undefined, TOutputSchema extends StandardSchema | undefined = undefined>(tool_or_options: CreatedTool<TSchema, TOutputSchema>): void; /** * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need, * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema. * * Tools will be invoked by the LLM when it thinks it needs to use them, you can use the annotations to provide additional information about the tool, like what it does, how to use it, etc. * */ tool<TSchema extends StandardSchema | undefined = undefined, TOutputSchema extends StandardSchema | undefined = undefined>(tool_or_options: ToolOptions<TSchema, TOutputSchema>, execute: TSchema extends undefined ? (() => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>)): void; /** * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM. * Use the description and title to help the user to understand what the prompt does and when to use it. * * A prompt can also have a schema that defines the input it expects, the user will be prompted to enter the inputs you request. It can also have a complete function * for each input that will be used to provide completions for the user. * */ prompt<TSchema extends StandardSchema | undefined = undefined>(prompt_or_options: CreatedPrompt<TSchema>): void; /** * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM. * Use the description and title to help the user to understand what the prompt does and when to use it. * * A prompt can also have a schema that defines the input it expects, the user will be prompted to enter the inputs you request. It can also have a complete function * for each input that will be used to provide completions for the user. * */ prompt<TSchema extends StandardSchema | undefined = undefined>(prompt_or_options: PromptOptions<TSchema>, execute: TSchema extends undefined ? (() => Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult): void; /** * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context. * Use the description and title to help the user to understand what the resource is. * */ resource(resource_or_options: CreatedResource): void; /** * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context. * Use the description and title to help the user to understand what the resource is. * */ resource(resource_or_options: ResourceOptions, execute: (uri: string) => Promise<ReadResourceResult> | ReadResourceResult): void; /** * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context. * Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570. * Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will * be invoked to provide completions for the template variables to the user. * Use the description and title to help the user to understand what the resource is. * */ template<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>(template_or_options: CreatedTemplate<TUri>): void; /** * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context. * Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570. * Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will * be invoked to provide completions for the template variables to the user. * Use the description and title to help the user to understand what the resource is. * */ template<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>(template_or_options: TemplateOptions<TUri>, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): void; /** * The main function that receive a JSONRpc message and either dispatch a `send` event or process the request. * * */ receive(message: JSONRPCMessage, ctx?: Context<CustomContext>): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>; /** * Lower level api to send a request to the client, mostly useful to call client methods that not yet supported by the server or * if you want to send requests with json schema that is not expressible with your validation library. * */ request({ method, params }: { method: string; params?: JSONRPCParams; }): Promise<unknown>; /** * Send a notification for subscriptions * */ changed<TWhat extends keyof ChangedArgs>(what: TWhat, ...args: ChangedArgs[TWhat]): void; /** * Refresh roots list from client */ refreshRoots(): Promise<void>; /** * Emit an elicitation request to the client. Elicitations are used to ask the user for input in a structured way, the client will show a UI to the user to fill the input. * The schema should be a valid Standard Schema V1 schema and should be an Object with the properties you need. * The client will return the validated input as a JSON object that matches the schema. * * If the client doesn't support elicitation, it will throw an error. * * */ elicitation<TSchema extends StandardSchema extends undefined ? never : StandardSchema>(message: string, schema: TSchema): Promise<ElicitResult & { content?: StandardSchemaV1.InferOutput<TSchema>; }>; /** * Request language model sampling from the client * */ message(request: CreateMessageRequestParams): Promise<CreateMessageResult>; /** * Send a progress notification to the client. This is useful for long-running operations where you want to inform the user about the progress. * * @param progress The current progress value, it should be between 0 and total and should always increase * @param total The total value, defaults to 1 * @param message An optional message to accompany the progress update */ progress(progress: number, total?: number, message?: string): void; /** * Log a message to the client if logging is enabled and the level is appropriate * * */ log(level: LoggingLevel, data: unknown, logger?: string): void; #private; } /** * Information about a validated access token, provided to request handlers. */ export type AuthInfo = { /** * - The access token. */ token: string; /** * - The client ID associated with this token. */ clientId: string; /** * - Scopes associated with this token. */ scopes: string[]; /** * - When the token expires (in seconds since epoch). */ expiresAt?: number | undefined; /** * - The RFC 8707 resource server identifier for which this token is valid. * If set, this MUST match the MCP server's resource identifier (minus hash fragment). */ resource?: URL | undefined; /** * - Additional data associated with the token. * This field should be used for any additional data that needs to be attached to the auth info. */ extra?: Record<string, unknown> | undefined; }; export type Context<TCustom extends Record<string, unknown> | undefined = undefined> = { sessionId?: string | undefined; sessionInfo?: { clientCapabilities?: ClientCapabilities_1; clientInfo?: ClientInfo_1; logLevel?: LoggingLevel; } | undefined; auth?: AuthInfo | undefined; custom?: TCustom | undefined; }; export type Icons = Icons_1; export type Subscriptions = Record<SubscriptionsKeys, string[]>; export type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = CallToolResult_1<TStructuredContent>; export type ReadResourceResult = ReadResourceResult_1; export type GetPromptResult = GetPromptResult_1; export type ClientCapabilities = ClientCapabilities_1; export type ServerInfo = ServerInfo_1; export type CreateMessageRequestParams = CreateMessageRequestParams_1; export type CreateMessageResult = CreateMessageResult_1; export type Resource = Resource_1; export type LoggingLevel = LoggingLevel_1; export type ClientInfo = ClientInfo_1; export type ElicitResult = ElicitResult_1; export type InitializeResult = InitializeResult_1; export type ListToolsResult = ListToolsResult_1; export type ListPromptsResult = ListPromptsResult_1; export type ListResourceTemplatesResult = ListResourceTemplatesResult_1; export type ListResourcesResult = ListResourcesResult_1; export type CompleteResult = CompleteResult_1; type AllSame<T, U> = [T] extends [U] ? true : false; type PromptOptions<TSchema extends StandardSchemaV1 | undefined = undefined> = { name: string; description: string; title?: string; enabled?: ()=>boolean | Promise<boolean>; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never; complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>> } & Icons_1 type ToolOptions<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = { name: string; _meta?: Record<string, any>; description: string; title?: string; enabled?: () => boolean | Promise<boolean>; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never; outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never; annotations?: ToolAnnotations; } & Icons_1; type ResourceOptions = { name: string; description: string; title?: string; uri: string; mimeType?: string; enabled?: ()=>boolean | Promise<boolean>; } & Icons_1 type TemplateOptions<TUri extends string = string, TVariables extends ExtractURITemplateVariables<TUri> = ExtractURITemplateVariables<TUri>> = { name: string; description: string; title?: string; mimeType?: string; enabled?: ()=>boolean | Promise<boolean>; uri: TUri; complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>; list?: () => Promise<Array<Resource_1>> | Array<Resource_1> } & Icons_1 type CreatedTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool }; type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefined> = PromptOptions<TSchema> & { [created_prompt]: created_prompt }; type CreatedResource = ResourceOptions & { [created_resource]: created_resource }; type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template }; type Completion = ( query: string, context: { arguments: Record<string, string> }, ) => CompleteResult_1 | Promise<CompleteResult_1>; type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = { capabilities?: ServerCapabilities; instructions?: string; adapter: JsonSchemaAdapter<TSchema> | undefined; pagination?: { tools?: { size?: number }; resources?: { size?: number }; prompts?: { size?: number }; }; logging?: { default: LoggingLevel_1; } }; type ChangedArgs = { 'resource': [id: string]; 'tools': []; 'prompts': []; 'resources': []; } type SubscriptionsKeysObj = { [K in keyof ChangedArgs as ChangedArgs[K]["length"] extends 0 ? "without_args" : "with_args"]: K }; type SubscriptionsKeys = SubscriptionsKeysObj["with_args"]; type McpEvents = { send: (message: { request: JSONRPCRequest; }) => void; broadcast: (message: { request: JSONRPCRequest; }) => void; initialize: (initialize_request: InitializeRequestParams) => void; subscription: (subscriptions_request: { uri: string, action?: "add" | "remove" }) => void; loglevelchange: (change: { level: LoggingLevel_1 }) => void; }; // Helper type to remove whitespace type Trim<S extends string> = S extends ` ${infer R}` ? Trim<R> : S extends `${infer L} ` ? Trim<L> : S; // Helper type to extract variable name, removing modifiers type ExtractVarName<S extends string> = S extends `${infer Name}:${string}` ? Trim<Name> // Remove prefix modifier : S extends `${infer Name}*` ? Trim<Name> // Remove explode modifier : Trim<S>; // Helper type to split comma-separated variables type SplitVariables<S extends string> = S extends `${infer First},${infer Rest}` ? ExtractVarName<First> | SplitVariables<Rest> : ExtractVarName<S>; // Helper type to extract content from braces and handle operators type ExtractFromExpression<S extends string> = S extends `+${infer Vars}` ? SplitVariables<Vars> // Reserved {+var} : S extends `#${infer Vars}` ? SplitVariables<Vars> // Fragment {#var} : S extends `.${infer Vars}` ? SplitVariables<Vars> // Label {.var} : S extends `/${infer Vars}` ? SplitVariables<Vars> // Path {/var} : S extends `;${infer Vars}` ? SplitVariables<Vars> // Path-style {;var} : S extends `?${infer Vars}` ? SplitVariables<Vars> // Query {?var} : S extends `&${infer Vars}` ? SplitVariables<Vars> // Query continuation {&var} : SplitVariables<S>; // Simple {var} // Main recursive type to extract all variables from URI template type ExtractVariablesFromTemplate<S extends string> = S extends `${string}{${infer Expression}}${infer Rest}` ? ExtractFromExpression<Expression> | ExtractVariablesFromTemplate<Rest> : never; // Main exported type type ExtractURITemplateVariables<T extends string> = ExtractVariablesFromTemplate<T>; const JSONRPCMessageSchema: v.UnionSchema<[v.ObjectSchema<{ readonly method: v.StringSchema<undefined>; readonly params: v.OptionalSchema<v.LooseObjectSchema<{ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{ /** * 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. */ readonly progressToken: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>, undefined>; }, undefined>, undefined>; }, undefined>, undefined>; readonly jsonrpc: v.LiteralSchema<"2.0", undefined>; readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>; }, undefined>, v.ObjectSchema<{ readonly method: v.StringSchema<undefined>; readonly params: v.OptionalSchema<v.LooseObjectSchema<{ /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>, undefined>; readonly jsonrpc: v.LiteralSchema<"2.0", undefined>; }, undefined>, v.StrictObjectSchema<{ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>; readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>; readonly result: v.LooseObjectSchema<{ /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>; }, undefined>, v.StrictObjectSchema<{ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>; readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>; readonly error: v.ObjectSchema<{ /** * The error type that occurred. */ readonly code: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>; /** * A short description of the error. The message SHOULD be limited to a concise single sentence. */ readonly message: v.StringSchema<undefined>; /** * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.). */ readonly data: v.OptionalSchema<v.UnknownSchema, undefined>; }, undefined>; }, undefined>], undefined>; const IconsSchema: v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; }, undefined>; /** * Describes the name and version of an MCP implementation. */ const ImplementationSchema: v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; readonly version: v.StringSchema<undefined>; readonly websiteUrl: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ readonly name: v.StringSchema<undefined>; /** * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, * even by those unfamiliar with domain-specific terminology. * * If not provided, the name should be used for display (except for Tool, * where `annotations.title` should be given precedence over using `name`, * if present). */ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>; }, undefined>; /** * 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. */ const ClientCapabilitiesSchema: v.LooseObjectSchema<{ /** * Experimental, non-standard capabilities that the client supports. */ readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the client supports sampling from an LLM. */ readonly sampling: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the client supports eliciting user input. */ readonly elicitation: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the client supports listing roots. */ readonly roots: v.OptionalSchema<v.ObjectSchema<{ /** * Whether the client supports issuing notifications for changes to the roots list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; }, undefined>; const InitializeRequestParamsSchema: v.ObjectSchema<{ /** * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. */ readonly protocolVersion: v.StringSchema<undefined>; readonly capabilities: v.LooseObjectSchema<{ /** * Experimental, non-standard capabilities that the client supports. */ readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the client supports sampling from an LLM. */ readonly sampling: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the client supports eliciting user input. */ readonly elicitation: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the client supports listing roots. */ readonly roots: v.OptionalSchema<v.ObjectSchema<{ /** * Whether the client supports issuing notifications for changes to the roots list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; }, undefined>; readonly clientInfo: v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; readonly version: v.StringSchema<undefined>; readonly websiteUrl: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ readonly name: v.StringSchema<undefined>; /** * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, * even by those unfamiliar with domain-specific terminology. * * If not provided, the name should be used for display (except for Tool, * where `annotations.title` should be given precedence over using `name`, * if present). */ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>; }, undefined>; readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{ /** * 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. */ readonly progressToken: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>, undefined>; }, undefined>, undefined>; }, undefined>; /** * 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. */ const ServerCapabilitiesSchema: v.ObjectSchema<{ /** * Experimental, non-standard capabilities that the server supports. */ readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the server supports sending log messages to the client. */ readonly logging: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the server supports sending completions to the client. */ readonly completions: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the server offers any prompt templates. */ readonly prompts: v.OptionalSchema<v.ObjectSchema<{ /** * Whether this server supports issuing notifications for changes to the prompt list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; /** * Present if the server offers any resources to read. */ readonly resources: v.OptionalSchema<v.ObjectSchema<{ /** * Whether this server supports clients subscribing to resource updates. */ readonly subscribe: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; /** * Whether this server supports issuing notifications for changes to the resource list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; /** * Present if the server offers any tools to call. */ readonly tools: v.OptionalSchema<v.ObjectSchema<{ /** * Whether this server supports issuing notifications for changes to the tool list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; }, undefined>; /** * After receiving an initialize request from the client, the server sends this response. */ const InitializeResultSchema: v.ObjectSchema<{ /** * 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. */ readonly protocolVersion: v.StringSchema<undefined>; readonly capabilities: v.ObjectSchema<{ /** * Experimental, non-standard capabilities that the server supports. */ readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the server supports sending log messages to the client. */ readonly logging: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the server supports sending completions to the client. */ readonly completions: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>; /** * Present if the server offers any prompt templates. */ readonly prompts: v.OptionalSchema<v.ObjectSchema<{ /** * Whether this server supports issuing notifications for changes to the prompt list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; /** * Present if the server offers any resources to read. */ readonly resources: v.OptionalSchema<v.ObjectSchema<{ /** * Whether this server supports clients subscribing to resource updates. */ readonly subscribe: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; /** * Whether this server supports issuing notifications for changes to the resource list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; /** * Present if the server offers any tools to call. */ readonly tools: v.OptionalSchema<v.ObjectSchema<{ /** * Whether this server supports issuing notifications for changes to the tool list. */ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>; }, undefined>, undefined>; }, undefined>; readonly serverInfo: v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; readonly version: v.StringSchema<undefined>; readonly websiteUrl: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ readonly name: v.StringSchema<undefined>; /** * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, * even by those unfamiliar with domain-specific terminology. * * If not provided, the name should be used for display (except for Tool, * where `annotations.title` should be given precedence over using `name`, * if present). */ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>; }, undefined>; /** * 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. */ readonly instructions: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>; /** * A known resource that the server is capable of reading. */ const ResourceSchema: v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; /** * The URI of this resource. */ readonly uri: v.StringSchema<undefined>; /** * 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. */ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * The MIME type of this resource, if known. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ readonly name: v.StringSchema<undefined>; /** * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, * even by those unfamiliar with domain-specific terminology. * * If not provided, the name should be used for display (except for Tool, * where `annotations.title` should be given precedence over using `name`, * if present). */ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>; }, undefined>; /** * The server's response to a resources/list request from the client. */ const ListResourcesResultSchema: v.ObjectSchema<{ readonly resources: v.ArraySchema<v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; /** * The URI of this resource. */ readonly uri: v.StringSchema<undefined>; /** * 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. */ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * The MIME type of this resource, if known. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ readonly name: v.StringSchema<undefined>; /** * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, * even by those unfamiliar with domain-specific terminology. * * If not provided, the name should be used for display (except for Tool, * where `annotations.title` should be given precedence over using `name`, * if present). */ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>; }, undefined>, undefined>; /** * An opaque token representing the pagination position after the last returned result. * If present, there may be more results available. */ readonly nextCursor: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>; /** * The server's response to a resources/templates/list request from the client. */ const ListResourceTemplatesResultSchema: v.ObjectSchema<{ readonly resourceTemplates: v.ArraySchema<v.ObjectSchema<{ /** * Optional set of sized icons that the client can display in a user interface. * * Clients that support rendering icons MUST support at least the following MIME types: * - `image/png` - PNG images (safe, universal compatibility) * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) * * Clients that support rendering icons SHOULD also support: * - `image/svg+xml` - SVG images (scalable but requires security precautions) * - `image/webp` - WebP images (modern, efficient format) */ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{ /** * URL or data URI for the icon. */ readonly src: v.StringSchema<undefined>; /** * Optional MIME type for the icon. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * Optional array of strings that specify sizes at which the icon can be used. * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. * * If not provided, the client should assume that the icon can be used at any size. */ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>; }, undefined>, undefined>, undefined>; /** * A URI template (according to RFC 6570) that can be used to construct resource URIs. */ readonly uriTemplate: v.StringSchema<undefined>; /** * 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. */ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * 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. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ readonly name: v.StringSchema<undefined>; /** * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, * even by those unfamiliar with domain-specific terminology. * * If not provided, the name should be used for display (except for Tool, * where `annotations.title` should be given precedence over using `name`, * if present). */ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>; }, undefined>, undefined>; /** * An opaque token representing the pagination position after the last returned result. * If present, there may be more results available. */ readonly nextCursor: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>; /** * The server's response to a resources/read request from the client. */ const ReadResourceResultSchema: v.ObjectSchema<{ readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{ /** * The text of the item. This must only be set if the item can actually be represented as text (not binary data). */ readonly text: v.StringSchema<undefined>; /** * The URI of this resource. */ readonly uri: v.StringSchema<undefined>; /** * The MIME type of this resource, if known. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>, v.ObjectSchema<{ /** * A base64-encoded string representing the binary data of the item. */ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>; /** * The URI of this resource. */ readonly uri: v.StringSchema<undefined>; /** * The MIME type of this resource, if known. */ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) * for notes on _meta usage. */ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>; }, undefined>], undefined>, undefined>; /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe6663