/** * MCP Client - Connects to MCP servers and discovers tools * * Uses the official @modelcontextprotocol/sdk as an optional peer dependency. * If the SDK is not installed, attempting to use MCP features will throw * a helpful error with installation instructions. */ import type { MCPClientConfig, MCPConnectionStatus, MCPToolDefinition, MCPToolResult, MCPClientEventHandler } from './types.js'; /** * MCP Client for connecting to a single MCP server * * @example * ```typescript * const client = new MCPClient({ * name: 'filesystem', * transport: 'stdio', * stdio: { * command: 'npx', * args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'], * }, * }); * * await client.connect(); * const tools = await client.listTools(); * const result = await client.callTool('read_file', { path: '/tmp/test.txt' }); * await client.disconnect(); * ``` */ export declare class MCPClient { readonly name: string; private readonly config; private client; private transport; private _status; private readonly eventHandlers; private cachedTools; constructor(config: MCPClientConfig); /** * Current connection status */ get status(): MCPConnectionStatus; /** * Whether the client is connected */ get isConnected(): boolean; /** * Connect to the MCP server * @throws MCPError if connection fails */ connect(): Promise; /** * Disconnect from the MCP server */ disconnect(): Promise; /** * List available tools from the server * @throws MCPError if not connected or listing fails */ listTools(): Promise; /** * Call a tool on the server * @param toolName Name of the tool to call * @param args Arguments to pass to the tool * @throws MCPError if not connected, tool not found, or execution fails */ callTool(toolName: string, args?: Record): Promise; /** * Register an event handler */ onEvent(handler: MCPClientEventHandler): () => void; /** * Convenience method to listen for tools changed events */ onToolsChanged(callback: (tools: MCPToolDefinition[]) => void): () => void; /** * Convenience method to listen for errors */ onError(callback: (error: Error) => void): () => void; /** * Convenience method to listen for disconnect */ onDisconnect(callback: () => void): () => void; /** * Emit an event to all handlers */ private emit; /** * Get the connected client, throwing if not connected * @throws MCPError if not connected * @returns The connected SDK client */ private getConnectedClient; }