import { Protocol, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js'; import type { Transport } from '../shared/transport.js'; import { type CallToolRequest, CallToolResultSchema, type ClientCapabilities, type ClientNotification, type ClientRequest, type ClientResult, type CompatibilityCallToolResultSchema, type CompleteRequest, type GetPromptRequest, type Implementation, type ListPromptsRequest, type ListResourcesRequest, type ListResourceTemplatesRequest, type ListToolsRequest, type LoggingLevel, type Notification, type ReadResourceRequest, type Request, type Result, type ServerCapabilities, type SubscribeRequest, type UnsubscribeRequest } from '../types.js'; import type { jsonSchemaValidator } from '../validation/types.js'; import { ZodLiteral, ZodObject, z } from 'zod'; import type { RequestHandlerExtra } from '../shared/protocol.js'; export type ClientOptions = ProtocolOptions & { /** * Capabilities to advertise as being supported by this client. */ capabilities?: ClientCapabilities; /** * JSON Schema validator for tool output validation. * * The validator is used to validate structured content returned by tools * against their declared output schemas. * * @default AjvJsonSchemaValidator * * @example * ```typescript * // ajv * const client = new Client( * { name: 'my-client', version: '1.0.0' }, * { * capabilities: {}, * jsonSchemaValidator: new AjvJsonSchemaValidator() * } * ); * * // @cfworker/json-schema * const client = new Client( * { name: 'my-client', version: '1.0.0' }, * { * capabilities: {}, * jsonSchemaValidator: new CfWorkerJsonSchemaValidator() * } * ); * ``` */ jsonSchemaValidator?: jsonSchemaValidator; }; /** * An MCP client on top of a pluggable transport. * * The client will automatically begin the initialization flow with the server when connect() is called. * * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: * * ```typescript * // Custom schemas * const CustomRequestSchema = RequestSchema.extend({...}) * const CustomNotificationSchema = NotificationSchema.extend({...}) * const CustomResultSchema = ResultSchema.extend({...}) * * // Type aliases * type CustomRequest = z.infer * type CustomNotification = z.infer * type CustomResult = z.infer * * // Create typed client * const client = new Client({ * name: "CustomClient", * version: "1.0.0" * }) * ``` */ export declare class Client extends Protocol { private _clientInfo; private _serverCapabilities?; private _serverVersion?; private _capabilities; private _instructions?; private _jsonSchemaValidator; private _cachedToolOutputValidators; /** * Initializes this client with the given name and version information. */ constructor(_clientInfo: Implementation, options?: ClientOptions); /** * Registers new capabilities. This can only be called before connecting to a transport. * * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). */ registerCapabilities(capabilities: ClientCapabilities): void; /** * Override request handler registration to enforce client-side validation for elicitation. */ setRequestHandler; }>>(requestSchema: T, handler: (request: z.infer, extra: RequestHandlerExtra) => ClientResult | ResultT | Promise): void; protected assertCapability(capability: keyof ServerCapabilities, method: string): void; connect(transport: Transport, options?: RequestOptions): Promise; /** * After initialization has completed, this will be populated with the server's reported capabilities. */ getServerCapabilities(): ServerCapabilities | undefined; /** * After initialization has completed, this will be populated with information about the server's name and version. */ getServerVersion(): Implementation | undefined; /** * After initialization has completed, this may be populated with information about the server's instructions. */ getInstructions(): string | undefined; protected assertCapabilityForMethod(method: RequestT['method']): void; protected assertNotificationCapability(method: NotificationT['method']): void; protected assertRequestHandlerCapability(method: string): void; ping(options?: RequestOptions): Promise<{ _meta?: Record | undefined; }>; complete(params: CompleteRequest['params'], options?: RequestOptions): Promise>; }, { completion: ZodObject<{ values: z.ZodArray; total: z.ZodOptional; hasMore: z.ZodOptional; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ values: z.ZodArray; total: z.ZodOptional; hasMore: z.ZodOptional; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ values: z.ZodArray; total: z.ZodOptional; hasMore: z.ZodOptional; }, z.ZodTypeAny, "passthrough">>; }>, z.ZodTypeAny, "passthrough">>; setLoggingLevel(level: LoggingLevel, options?: RequestOptions): Promise<{ _meta?: Record | undefined; }>; getPrompt(params: GetPromptRequest['params'], options?: RequestOptions): Promise>; }, { description: z.ZodOptional; messages: z.ZodArray; content: z.ZodUnion<[ZodObject<{ type: ZodLiteral<"text">; text: z.ZodString; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "text"; text: string; _meta?: Record | undefined; }, { type: "text"; text: string; _meta?: Record | undefined; }>, ZodObject<{ type: ZodLiteral<"image">; data: z.ZodEffects; mimeType: z.ZodString; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "image"; data: string; mimeType: string; _meta?: Record | undefined; }, { type: "image"; data: string; mimeType: string; _meta?: Record | undefined; }>, ZodObject<{ type: ZodLiteral<"audio">; data: z.ZodEffects; mimeType: z.ZodString; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "audio"; data: string; mimeType: string; _meta?: Record | undefined; }, { type: "audio"; data: string; mimeType: string; _meta?: Record | undefined; }>, ZodObject; }, { uri: z.ZodString; description: z.ZodOptional; mimeType: z.ZodOptional; _meta: z.ZodOptional, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }>, { icons: z.ZodOptional; sizes: z.ZodOptional>; }, "strip", z.ZodTypeAny, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }>, "many">>; }>, { type: ZodLiteral<"resource_link">; }>, "strip", z.ZodTypeAny, { type: "resource_link"; name: string; uri: string; _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }, { type: "resource_link"; name: string; uri: string; _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }>, ZodObject<{ type: ZodLiteral<"resource">; resource: z.ZodUnion<[ZodObject; _meta: z.ZodOptional>; }, { text: z.ZodString; }>, "strip", z.ZodTypeAny, { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; }, { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; }>, ZodObject; _meta: z.ZodOptional>; }, { blob: z.ZodEffects; }>, "strip", z.ZodTypeAny, { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }, { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }>]>; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "resource"; resource: { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; } | { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }; _meta?: Record | undefined; }, { type: "resource"; resource: { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; } | { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }; _meta?: Record | undefined; }>]>; }, "strip", z.ZodTypeAny, { role: "user" | "assistant"; content: { type: "text"; text: string; _meta?: Record | undefined; } | { type: "image"; data: string; mimeType: string; _meta?: Record | undefined; } | { type: "audio"; data: string; mimeType: string; _meta?: Record | undefined; } | { type: "resource"; resource: { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; } | { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }; _meta?: Record | undefined; } | { type: "resource_link"; name: string; uri: string; _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }; }, { role: "user" | "assistant"; content: { type: "text"; text: string; _meta?: Record | undefined; } | { type: "image"; data: string; mimeType: string; _meta?: Record | undefined; } | { type: "audio"; data: string; mimeType: string; _meta?: Record | undefined; } | { type: "resource"; resource: { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; } | { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }; _meta?: Record | undefined; } | { type: "resource_link"; name: string; uri: string; _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }; }>, "many">; }>, z.ZodTypeAny, "passthrough">>; listPrompts(params?: ListPromptsRequest['params'], options?: RequestOptions): Promise>; }, { nextCursor: z.ZodOptional; }>, { prompts: z.ZodArray; }, { description: z.ZodOptional; arguments: z.ZodOptional; required: z.ZodOptional; }, "strip", z.ZodTypeAny, { name: string; description?: string | undefined; required?: boolean | undefined; }, { name: string; description?: string | undefined; required?: boolean | undefined; }>, "many">>; _meta: z.ZodOptional, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }>, { icons: z.ZodOptional; sizes: z.ZodOptional>; }, "strip", z.ZodTypeAny, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }>, "many">>; }>, "strip", z.ZodTypeAny, { name: string; _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; arguments?: { name: string; description?: string | undefined; required?: boolean | undefined; }[] | undefined; }, { name: string; _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; arguments?: { name: string; description?: string | undefined; required?: boolean | undefined; }[] | undefined; }>, "many">; }>, z.ZodTypeAny, "passthrough">>; listResources(params?: ListResourcesRequest['params'], options?: RequestOptions): Promise>; }, { nextCursor: z.ZodOptional; }>, { resources: z.ZodArray; }, { uri: z.ZodString; description: z.ZodOptional; mimeType: z.ZodOptional; _meta: z.ZodOptional, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }>, { icons: z.ZodOptional; sizes: z.ZodOptional>; }, "strip", z.ZodTypeAny, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }>, "many">>; }>, "strip", z.ZodTypeAny, { name: string; uri: string; _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }, { name: string; uri: string; _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }>, "many">; }>, z.ZodTypeAny, "passthrough">>; listResourceTemplates(params?: ListResourceTemplatesRequest['params'], options?: RequestOptions): Promise>; }, { nextCursor: z.ZodOptional; }>, { resourceTemplates: z.ZodArray; }, { uriTemplate: z.ZodString; description: z.ZodOptional; mimeType: z.ZodOptional; _meta: z.ZodOptional, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }>, { icons: z.ZodOptional; sizes: z.ZodOptional>; }, "strip", z.ZodTypeAny, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }>, "many">>; }>, "strip", z.ZodTypeAny, { name: string; uriTemplate: string; _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }, { name: string; uriTemplate: string; _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }>, "many">; }>, z.ZodTypeAny, "passthrough">>; readResource(params: ReadResourceRequest['params'], options?: RequestOptions): Promise>; }, { contents: z.ZodArray; _meta: z.ZodOptional>; }, { text: z.ZodString; }>, "strip", z.ZodTypeAny, { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; }, { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; }>, ZodObject; _meta: z.ZodOptional>; }, { blob: z.ZodEffects; }>, "strip", z.ZodTypeAny, { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }, { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }>]>, "many">; }>, z.ZodTypeAny, "passthrough">>; subscribeResource(params: SubscribeRequest['params'], options?: RequestOptions): Promise<{ _meta?: Record | undefined; }>; unsubscribeResource(params: UnsubscribeRequest['params'], options?: RequestOptions): Promise<{ _meta?: Record | undefined; }>; callTool(params: CallToolRequest['params'], resultSchema?: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema, options?: RequestOptions): Promise>; }, { content: z.ZodDefault; text: z.ZodString; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "text"; text: string; _meta?: Record | undefined; }, { type: "text"; text: string; _meta?: Record | undefined; }>, ZodObject<{ type: ZodLiteral<"image">; data: z.ZodEffects; mimeType: z.ZodString; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "image"; data: string; mimeType: string; _meta?: Record | undefined; }, { type: "image"; data: string; mimeType: string; _meta?: Record | undefined; }>, ZodObject<{ type: ZodLiteral<"audio">; data: z.ZodEffects; mimeType: z.ZodString; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "audio"; data: string; mimeType: string; _meta?: Record | undefined; }, { type: "audio"; data: string; mimeType: string; _meta?: Record | undefined; }>, ZodObject; }, { uri: z.ZodString; description: z.ZodOptional; mimeType: z.ZodOptional; _meta: z.ZodOptional, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>; }>, { icons: z.ZodOptional; sizes: z.ZodOptional>; }, "strip", z.ZodTypeAny, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }>, "many">>; }>, { type: ZodLiteral<"resource_link">; }>, "strip", z.ZodTypeAny, { type: "resource_link"; name: string; uri: string; _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }, { type: "resource_link"; name: string; uri: string; _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined; mimeType?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; }>, ZodObject<{ type: ZodLiteral<"resource">; resource: z.ZodUnion<[ZodObject; _meta: z.ZodOptional>; }, { text: z.ZodString; }>, "strip", z.ZodTypeAny, { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; }, { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; }>, ZodObject; _meta: z.ZodOptional>; }, { blob: z.ZodEffects; }>, "strip", z.ZodTypeAny, { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }, { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }>]>; _meta: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "resource"; resource: { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; } | { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }; _meta?: Record | undefined; }, { type: "resource"; resource: { uri: string; text: string; _meta?: Record | undefined; mimeType?: string | undefined; } | { uri: string; blob: string; _meta?: Record | undefined; mimeType?: string | undefined; }; _meta?: Record | undefined; }>]>, "many">>; structuredContent: z.ZodOptional>; isError: z.ZodOptional; }>, z.ZodTypeAny, "passthrough"> | z.objectOutputType>; }, { toolResult: z.ZodUnknown; }>, z.ZodTypeAny, "passthrough">>; /** * Cache validators for tool output schemas. * Called after listTools() to pre-compile validators for better performance. */ private cacheToolOutputSchemas; /** * Get cached validator for a tool */ private getToolOutputValidator; listTools(params?: ListToolsRequest['params'], options?: RequestOptions): Promise>; }, { nextCursor: z.ZodOptional; }>, { tools: z.ZodArray; }, { description: z.ZodOptional; inputSchema: ZodObject<{ type: ZodLiteral<"object">; properties: z.ZodOptional>>; required: z.ZodOptional>; }, "strip", z.ZodTypeAny, { type: "object"; required?: string[] | undefined; properties?: Record | undefined; }, { type: "object"; required?: string[] | undefined; properties?: Record | undefined; }>; outputSchema: z.ZodOptional; properties: z.ZodOptional>>; required: z.ZodOptional>; additionalProperties: z.ZodOptional; }, "strip", z.ZodTypeAny, { type: "object"; required?: string[] | undefined; properties?: Record | undefined; additionalProperties?: boolean | undefined; }, { type: "object"; required?: string[] | undefined; properties?: Record | undefined; additionalProperties?: boolean | undefined; }>>; annotations: z.ZodOptional; readOnlyHint: z.ZodOptional; destructiveHint: z.ZodOptional; idempotentHint: z.ZodOptional; openWorldHint: z.ZodOptional; }, "strip", z.ZodTypeAny, { title?: string | undefined; readOnlyHint?: boolean | undefined; destructiveHint?: boolean | undefined; idempotentHint?: boolean | undefined; openWorldHint?: boolean | undefined; }, { title?: string | undefined; readOnlyHint?: boolean | undefined; destructiveHint?: boolean | undefined; idempotentHint?: boolean | undefined; openWorldHint?: boolean | undefined; }>>; _meta: z.ZodOptional>; }>, { icons: z.ZodOptional; sizes: z.ZodOptional>; }, "strip", z.ZodTypeAny, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }, { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }>, "many">>; }>, "strip", z.ZodTypeAny, { name: string; inputSchema: { type: "object"; required?: string[] | undefined; properties?: Record | undefined; }; _meta?: Record | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; outputSchema?: { type: "object"; required?: string[] | undefined; properties?: Record | undefined; additionalProperties?: boolean | undefined; } | undefined; annotations?: { title?: string | undefined; readOnlyHint?: boolean | undefined; destructiveHint?: boolean | undefined; idempotentHint?: boolean | undefined; openWorldHint?: boolean | undefined; } | undefined; }, { name: string; inputSchema: { type: "object"; required?: string[] | undefined; properties?: Record | undefined; }; _meta?: Record | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; }[] | undefined; title?: string | undefined; description?: string | undefined; outputSchema?: { type: "object"; required?: string[] | undefined; properties?: Record | undefined; additionalProperties?: boolean | undefined; } | undefined; annotations?: { title?: string | undefined; readOnlyHint?: boolean | undefined; destructiveHint?: boolean | undefined; idempotentHint?: boolean | undefined; openWorldHint?: boolean | undefined; } | undefined; }>, "many">; }>, z.ZodTypeAny, "passthrough">>; sendRootsListChanged(): Promise; } //# sourceMappingURL=index.d.ts.map