/**
 * MCP Client - Single Server Connection
 *
 * Manages connection to one MCP server and provides
 * methods to list/call tools, read resources, etc.
 *
 * Transport is provided by the official `@modelcontextprotocol/sdk`:
 *   - stdio  → subprocess JSON-RPC over stdin/stdout
 *   - http   → Streamable HTTP (POST for client→server, plus a server→client
 *              push channel — the SDK opens the SSE stream and a standalone GET
 *              SSE for server-initiated messages, and handles reconnect/
 *              session-expiry by re-using the session id)
 *   - sse    → legacy HTTP+SSE transport (when `transport: "sse"` is requested)
 *
 * The SDK gives us a real persistent connection, a server→client push channel,
 * dispatch of server NOTIFICATIONS, answering of server REQUESTS (elicitation,
 * roots/list, sampling, ping), and bounded reconnect on a dropped stream /
 * expired session — none of which the hand-rolled POST-only transport did.
 */
import type { MCPServerConfig, MCPToolDefinition, MCPResource, MCPPrompt, MCPToolCallResult, MCPLogHandler, MCPProgressHandler, MCPElicitationHandler, MCPRoot } from "./types.js";
/**
 * Options for creating an MCP client.
 */
export interface MCPClientOptions {
    /** Unique name for this client */
    name: string;
    /** Server connection configuration */
    config: MCPServerConfig;
    /** Optional timeout in milliseconds */
    timeout?: number;
    /** Optional log handler */
    logger?: MCPLogHandler;
    /** Whether to enable server logs (default: true) */
    enableServerLogs?: boolean;
    /** Whether to enable progress tracking (default: false) */
    enableProgressTracking?: boolean;
    /** Filesystem roots to expose to the server */
    roots?: MCPRoot[];
}
/**
 * MCP Client - manages connection to a single MCP server.
 *
 * Supports stdio (subprocess) and HTTP (Streamable HTTP / legacy SSE) transports.
 * Provides methods to list tools, call tools, read resources, etc.
 *
 * @example
 * ```typescript
 * const client = new MCPClient({
 *   name: "filesystem",
 *   config: {
 *     command: "npx",
 *     args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
 *   },
 * });
 *
 * await client.connect();
 * const tools = await client.listTools();
 * const result = await client.callTool("read_file", { path: "./test.txt" });
 * await client.disconnect();
 * ```
 */
export declare class MCPClient {
    private options;
    private client?;
    private transport?;
    private isConnected;
    private connectionPromise;
    private serverCapabilities?;
    private logHandler?;
    private enableServerLogs;
    private enableProgressTracking;
    private _roots;
    private elicitationHandler?;
    private samplingHandler?;
    private resourceUpdatedHandler?;
    private resourceListChangedHandler?;
    private toolListChangedHandler?;
    private promptListChangedHandler?;
    private progressHandler?;
    /** Server name */
    readonly serverName: string;
    /** Server config */
    readonly config: MCPServerConfig;
    /** Request timeout */
    readonly timeout: number;
    constructor(options: MCPClientOptions);
    /**
     * Connect to the MCP server.
     * Safe to call multiple times - returns existing connection if already connected.
     */
    connect(): Promise<void>;
    private doConnect;
    /**
     * Build the SDK transport for the configured server.
     *
     *  - stdio: `StdioClientTransport` (inherits the parent env, merges config.env).
     *  - http:  `StreamableHTTPClientTransport` (POST + server-push SSE channel,
     *           reconnect + session-expiry handled by the SDK), unless the config
     *           asks for the legacy `SSEClientTransport`.
     */
    private createTransport;
    /**
     * Register handlers for server-initiated REQUESTS and NOTIFICATIONS.
     *
     * REQUESTS (have both `.method` AND `.id`) must be ANSWERED with a JSON-RPC
     * RESPONSE carrying the matching id — the SDK does this automatically for the
     * value a request handler returns (or rejects). The previous hand-rolled
     * transport routed these into the notification path, so they were never
     * answered (bug #13).
     *
     * Defaults:
     *   - ping              → {}
     *   - roots/list        → the configured roots
     *   - elicitation/create→ decline ({action:"cancel"}) unless a host handler is set
     *   - sampling          → reject "Method not found" unless a host handler is set
     */
    private registerServerHandlers;
    /**
     * Disconnect from the MCP server.
     *
     * The SDK's `client.close()` closes the transport and rejects any pending
     * requests — a clean teardown for both stdio (graceful subprocess shutdown)
     * and HTTP (close the push channel / end the session).
     */
    disconnect(): Promise<void>;
    /**
     * Whether the client is connected.
     */
    get connected(): boolean;
    /**
     * List all tools available from the server.
     */
    listTools(): Promise<MCPToolDefinition[]>;
    /**
     * Call a tool on the server.
     */
    callTool(name: string, args: Record<string, unknown>): Promise<MCPToolCallResult>;
    /**
     * List all resources available from the server.
     */
    listResources(): Promise<MCPResource[]>;
    /**
     * Read a resource from the server.
     */
    readResource(uri: string): Promise<unknown>;
    /**
     * Subscribe to resource updates.
     */
    subscribeResource(uri: string): Promise<void>;
    /**
     * Unsubscribe from resource updates.
     */
    unsubscribeResource(uri: string): Promise<void>;
    /**
     * List all prompts available from the server.
     */
    listPrompts(): Promise<MCPPrompt[]>;
    /**
     * Get a prompt from the server.
     */
    getPrompt(name: string, args?: Record<string, unknown>): Promise<unknown>;
    /**
     * Get the configured roots.
     */
    get roots(): MCPRoot[];
    /**
     * Update the roots and notify the server.
     */
    setRoots(roots: MCPRoot[]): Promise<void>;
    /**
     * Set a handler for resource updated notifications.
     */
    setResourceUpdatedHandler(handler: (params: {
        uri: string;
    }) => void): void;
    /**
     * Set a handler for resource list changed notifications.
     */
    setResourceListChangedHandler(handler: () => void): void;
    /**
     * Set a handler for tool list changed notifications.
     */
    setToolListChangedHandler(handler: () => void): void;
    /**
     * Set a handler for prompt list changed notifications.
     */
    setPromptListChangedHandler(handler: () => void): void;
    /**
     * Set a handler for elicitation requests. When set, the server's
     * `elicitation/create` REQUEST is answered with the host's decision; when
     * unset the request is declined ({action:"cancel"}).
     */
    setElicitationHandler(handler: MCPElicitationHandler): void;
    /**
     * Set a handler for sampling (`sampling/createMessage`) requests. When set,
     * the server request is answered with the host's result; when unset the
     * request is rejected with "Method not found".
     */
    setSamplingHandler(handler: (params: unknown) => Promise<unknown>): void;
    /**
     * Set a handler for progress notifications.
     */
    setProgressHandler(handler: MCPProgressHandler): void;
    private ensureConnected;
    /**
     * Normalize an SDK/transport error into an MCPError. Session-expiry style
     * failures (404 session / -32001) are surfaced as SESSION_ERROR so callers
     * (the pool) can decide to reconnect; the SDK's StreamableHTTP transport
     * already attempts a bounded reconnect re-using the session id before this.
     */
    private wrapError;
    private log;
}
