import { Server, ServerOptions } from "./index.js"; import { z, ZodRawShape, ZodObject, AnyZodObject, ZodTypeAny, ZodType, ZodTypeDef, ZodOptional } from "zod"; import { Implementation, CallToolResult, Resource, ListResourcesResult, PromptArgument, GetPromptResult, ReadResourceResult } from "../types.js"; import { UriTemplate, Variables } from "../shared/uriTemplate.js"; import { RequestHandlerExtra } from "../shared/protocol.js"; import { Transport } from "../shared/transport.js"; /** * High-level MCP server that provides a simpler API for working with resources, tools, and prompts. * For advanced usage (like sending notifications or setting custom request handlers), use the underlying * Server instance available via the `server` property. */ export declare class McpServer { /** * The underlying Server instance, useful for advanced operations like sending notifications. */ readonly server: Server; protected _registeredResources: { [uri: string]: RegisteredResource; }; protected _registeredResourceTemplates: { [name: string]: RegisteredResourceTemplate; }; protected _registeredTools: { [name: string]: RegisteredTool; }; protected _registeredPrompts: { [name: string]: RegisteredPrompt; }; protected _toolHandlersInitialized: boolean; protected _completionHandlerInitialized: boolean; protected _resourceHandlersInitialized: boolean; protected _promptHandlersInitialized: boolean; constructor(serverInfo: Implementation, options?: ServerOptions); /** * Attaches to the given transport, starts it, and starts listening for messages. * * The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. */ connect(transport: Transport): Promise; /** * Closes the connection. */ close(): Promise; private setToolRequestHandlers; private setCompletionRequestHandler; private handlePromptCompletion; private handleResourceCompletion; private setResourceRequestHandlers; private setPromptRequestHandlers; /** * Registers a resource `name` at a fixed URI, which will use the given callback to respond to read requests. */ resource(name: string, uri: string, readCallback: ReadResourceCallback): void; /** * Registers a resource `name` at a fixed URI with metadata, which will use the given callback to respond to read requests. */ resource(name: string, uri: string, metadata: ResourceMetadata, readCallback: ReadResourceCallback): void; /** * Registers a resource `name` with a template pattern, which will use the given callback to respond to read requests. */ resource(name: string, template: ResourceTemplate, readCallback: ReadResourceTemplateCallback): void; /** * Registers a resource `name` with a template pattern and metadata, which will use the given callback to respond to read requests. */ resource(name: string, template: ResourceTemplate, metadata: ResourceMetadata, readCallback: ReadResourceTemplateCallback): void; /** * Registers a zero-argument tool `name`, which will run the given function when the client calls it. */ tool(name: string, cb: ToolCallback): void; /** * Registers a zero-argument tool `name` (with a description) which will run the given function when the client calls it. */ tool(name: string, description: string, cb: ToolCallback): void; /** * Registers a tool `name` accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. */ tool(name: string, paramsSchema: Args, cb: ToolCallback): void; /** * Registers a tool `name` (with a description) accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. */ tool(name: string, description: string, paramsSchema: Args, cb: ToolCallback): void; /** * Registers a zero-argument prompt `name`, which will run the given function when the client calls it. */ prompt(name: string, cb: PromptCallback): void; /** * Registers a zero-argument prompt `name` (with a description) which will run the given function when the client calls it. */ prompt(name: string, description: string, cb: PromptCallback): void; /** * Registers a prompt `name` accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. */ prompt(name: string, argsSchema: Args, cb: PromptCallback): void; /** * Registers a prompt `name` (with a description) accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. */ prompt(name: string, description: string, argsSchema: Args, cb: PromptCallback): void; } /** * A callback to complete one variable within a resource template's URI template. */ export type CompleteResourceTemplateCallback = (value: string) => string[] | Promise; /** * A resource template combines a URI pattern with optional functionality to enumerate * all resources matching that pattern. */ export declare class ResourceTemplate { private _callbacks; private _uriTemplate; constructor(uriTemplate: string | UriTemplate, _callbacks: { /** * A callback to list all resources matching this template. This is required to specified, even if `undefined`, to avoid accidentally forgetting resource listing. */ list: ListResourcesCallback | undefined; /** * An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values. */ complete?: { [variable: string]: CompleteResourceTemplateCallback; }; }); /** * Gets the URI template pattern. */ get uriTemplate(): UriTemplate; /** * Gets the list callback, if one was provided. */ get listCallback(): ListResourcesCallback | undefined; /** * Gets the callback for completing a specific URI template variable, if one was provided. */ completeCallback(variable: string): CompleteResourceTemplateCallback | undefined; } /** * Callback for a tool handler registered with Server.tool(). * * Parameters will include tool arguments, if applicable, as well as other request handler context. */ export type ToolCallback = Args extends ZodRawShape ? (args: z.objectOutputType, extra: RequestHandlerExtra) => CallToolResult | Promise : (extra: RequestHandlerExtra) => CallToolResult | Promise; type RegisteredTool = { description?: string; inputSchema?: AnyZodObject; callback: ToolCallback; }; /** * Additional, optional information for annotating a resource. */ export type ResourceMetadata = Omit; /** * Callback to list all resources matching a given template. */ export type ListResourcesCallback = (extra: RequestHandlerExtra) => ListResourcesResult | Promise; /** * Callback to read a resource at a given URI. */ export type ReadResourceCallback = (uri: URL, extra: RequestHandlerExtra) => ReadResourceResult | Promise; type RegisteredResource = { name: string; metadata?: ResourceMetadata; readCallback: ReadResourceCallback; }; /** * Callback to read a resource at a given URI, following a filled-in URI template. */ export type ReadResourceTemplateCallback = (uri: URL, variables: Variables, extra: RequestHandlerExtra) => ReadResourceResult | Promise; type RegisteredResourceTemplate = { resourceTemplate: ResourceTemplate; metadata?: ResourceMetadata; readCallback: ReadResourceTemplateCallback; }; type PromptArgsRawShape = { [k: string]: ZodType | ZodOptional>; }; export type PromptCallback = Args extends PromptArgsRawShape ? (args: z.objectOutputType, extra: RequestHandlerExtra) => GetPromptResult | Promise : (extra: RequestHandlerExtra) => GetPromptResult | Promise; type RegisteredPrompt = { description?: string; argsSchema?: ZodObject; callback: PromptCallback; }; export declare function promptArgumentsFromSchema(schema: ZodObject): PromptArgument[]; export {}; //# sourceMappingURL=mcp.d.ts.map