/**
 * MCP Client Service
 *
 * Enables Crewly agents to connect to external MCP (Model Context Protocol)
 * servers and use their tools. This is the client-side counterpart to our
 * existing MCP server — it lets agents consume tools from any MCP-compatible
 * server (filesystem, GitHub, database, etc.).
 *
 * Supports stdio-based MCP servers (child process spawning) which is the
 * standard transport for local MCP servers.
 *
 * @module services/mcp-client
 */
/**
 * MCP Client configuration constants
 */
export declare const MCP_CLIENT_CONSTANTS: {
    /** Client identification sent during MCP handshake */
    readonly CLIENT_INFO: {
        readonly NAME: "crewly-agent";
        readonly VERSION: "1.0.0";
    };
    /** Default timeout for tool calls (30 seconds) */
    readonly TOOL_CALL_TIMEOUT_MS: 30000;
    /** Default timeout for server connection (15 seconds) */
    readonly CONNECTION_TIMEOUT_MS: 15000;
};
/**
 * Configuration for an external MCP server.
 *
 * Matches the format used in `crewly.config.ts`:
 * ```typescript
 * mcpServers: {
 *   filesystem: { command: 'npx', args: ['-y', '@anthropic/mcp-filesystem'] },
 *   github: { command: 'npx', args: ['-y', '@anthropic/mcp-github'] },
 * }
 * ```
 */
export interface McpServerConfig {
    /** The executable command to run (e.g., 'npx', 'node', 'python') */
    command: string;
    /** Command-line arguments for the executable */
    args?: string[];
    /** Environment variables to set for the server process */
    env?: Record<string, string>;
}
/**
 * Normalized tool information from an MCP server.
 */
export interface McpToolInfo {
    /** Tool name as registered on the MCP server */
    name: string;
    /** Human-readable description of the tool */
    description?: string;
    /** JSON Schema describing the tool's input parameters */
    inputSchema: Record<string, unknown>;
    /** Name of the MCP server that provides this tool */
    serverName: string;
}
/**
 * Result from calling an MCP tool.
 */
export interface McpToolResult {
    /** Content blocks returned by the tool */
    content: McpContentBlock[];
    /** Whether the tool call resulted in an error */
    isError: boolean;
}
/**
 * A single content block in a tool result.
 */
export interface McpContentBlock {
    /** Content type: 'text', 'image', or 'resource' */
    type: string;
    /** Text content (when type is 'text') */
    text?: string;
    /** Base64-encoded data (when type is 'image') */
    data?: string;
    /** MIME type (when type is 'image') */
    mimeType?: string;
}
/**
 * Status information for a connected MCP server.
 */
export interface McpServerStatus {
    /** Server identifier */
    name: string;
    /** Whether the server is currently connected */
    connected: boolean;
    /** Number of tools available from this server */
    toolCount: number;
    /** Server name reported during handshake */
    serverName?: string;
    /** Server version reported during handshake */
    serverVersion?: string;
}
/**
 * Manages connections to external MCP servers and provides a unified
 * interface for discovering and calling tools across all connected servers.
 *
 * Agents use this service to:
 * 1. Connect to configured MCP servers at startup
 * 2. Discover available tools across all servers
 * 3. Call tools by name with type-safe arguments
 * 4. Gracefully disconnect on shutdown
 *
 * @example
 * ```typescript
 * const mcpClient = new McpClientService();
 *
 * // Connect to a filesystem MCP server
 * await mcpClient.connectServer('filesystem', {
 *   command: 'npx',
 *   args: ['-y', '@anthropic/mcp-filesystem', '/home/user'],
 * });
 *
 * // List all available tools
 * const tools = mcpClient.listTools();
 *
 * // Call a tool
 * const result = await mcpClient.callTool('filesystem', 'read_file', {
 *   path: '/home/user/file.txt',
 * });
 *
 * // Disconnect all servers
 * await mcpClient.disconnectAll();
 * ```
 */
export declare class McpClientService {
    /** Map of server name -> active connection */
    private connections;
    /**
     * Connect to an external MCP server via stdio transport.
     *
     * Spawns the server as a child process, performs the MCP handshake,
     * and caches the list of available tools.
     *
     * @param name - Unique identifier for this server connection
     * @param config - Server configuration (command, args, env)
     * @throws Error if already connected to a server with this name
     * @throws Error if the connection or handshake fails
     */
    connectServer(name: string, config: McpServerConfig): Promise<void>;
    /**
     * Disconnect from a specific MCP server.
     *
     * Closes the transport and cleans up the child process.
     *
     * @param name - Name of the server to disconnect
     * @throws Error if the server is not connected
     */
    disconnectServer(name: string): Promise<void>;
    /**
     * Disconnect from all connected MCP servers.
     *
     * Closes all transports and cleans up child processes. Errors from
     * individual disconnections are caught and do not prevent other
     * servers from being disconnected. Connections are always removed
     * from the internal map, even if `close()` fails.
     */
    disconnectAll(): Promise<void>;
    /**
     * List all available tools across connected MCP servers.
     *
     * @param serverName - Optional: filter tools to a specific server
     * @returns Array of tool information objects
     */
    listTools(serverName?: string): McpToolInfo[];
    /**
     * Call a tool on a specific MCP server.
     *
     * @param serverName - Name of the server that provides the tool
     * @param toolName - Name of the tool to call
     * @param args - Arguments to pass to the tool
     * @returns The tool's result containing content blocks and error status
     * @throws Error if the server is not connected
     * @throws Error if the tool is not found on the server
     * @throws Error if the tool call fails
     */
    callTool(serverName: string, toolName: string, args?: Record<string, unknown>): Promise<McpToolResult>;
    /**
     * Refresh the tool list for a specific server.
     *
     * Useful when a server's tools may have changed since the initial connection.
     *
     * @param serverName - Name of the server to refresh
     * @throws Error if the server is not connected
     */
    refreshTools(serverName: string): Promise<void>;
    /**
     * Get the names of all currently connected MCP servers.
     *
     * @returns Array of server names
     */
    getConnectedServers(): string[];
    /**
     * Check if a specific MCP server is currently connected.
     *
     * @param name - Server name to check
     * @returns True if the server is connected
     */
    isServerConnected(name: string): boolean;
    /**
     * Get status information for all connected servers.
     *
     * @returns Array of server status objects including tool counts
     */
    getServerStatuses(): McpServerStatus[];
    /**
     * Connect to multiple MCP servers from a configuration map.
     *
     * This is the primary entrypoint for agent startup. Errors from
     * individual connections are caught — failing servers do not prevent
     * other servers from connecting.
     *
     * @param configs - Map of server name -> server config
     * @returns Map of server name -> error (only for servers that failed to connect)
     *
     * @example
     * ```typescript
     * const errors = await mcpClient.connectAll({
     *   filesystem: { command: 'npx', args: ['-y', '@anthropic/mcp-filesystem', '/tmp'] },
     *   github: { command: 'npx', args: ['-y', '@anthropic/mcp-github'] },
     * });
     *
     * if (errors.size > 0) {
     *   console.warn('Some MCP servers failed to connect:', errors);
     * }
     * ```
     */
    connectAll(configs: Record<string, McpServerConfig>): Promise<Map<string, Error>>;
}
//# sourceMappingURL=mcp-client.d.ts.map