/**
 * External MCP Server Manager
 * Handles lifecycle management of external MCP servers including:
 * - Process spawning and management
 * - Health monitoring and automatic restart
 * - Connection management and cleanup
 * - Tool discovery and registration
 */
import { EventEmitter } from "events";
import { ToolDiscoveryService } from "./toolDiscoveryService.js";
import type { HITLManager, JsonObject, ServerLoadResult, ExternalMCPServerInstance, ExternalMCPServerHealth, ExternalMCPConfigValidation, ExternalMCPOperationResult, ExternalMCPManagerConfig, ExternalMCPToolInfo, MCPServerInfo } from "../types/index.js";
/**
 * ExternalServerManager
 * Core class for managing external MCP servers
 */
export declare class ExternalServerManager extends EventEmitter {
    private servers;
    private config;
    private isShuttingDown;
    private toolDiscovery;
    private enableMainRegistryIntegration;
    private hitlManager?;
    constructor(config?: ExternalMCPManagerConfig, options?: {
        enableMainRegistryIntegration?: boolean;
    });
    /**
     * Attach a McpOutputNormalizer to the underlying ToolDiscoveryService.
     * All tool outputs will be measured and (if oversized) replaced with compact
     * surrogates before being returned to callers.
     */
    setOutputNormalizer(normalizer: import("./mcpOutputNormalizer.js").McpOutputNormalizer): void;
    /**
     * Set HITL manager for human-in-the-loop safety mechanisms
     * @param hitlManager - HITL manager instance (optional, can be undefined to disable)
     */
    setHITLManager(hitlManager?: HITLManager): void;
    /**
     * Get current HITL manager
     */
    getHITLManager(): HITLManager | undefined;
    /**
     * Resolve the human-readable server name for an event payload.
     * Falls back to serverId if the instance or config.name isn't available.
     */
    getServerName(serverId: string): string;
    /**
     * Load MCP server configurations from .mcp-config.json file with parallel loading support
     * Automatically registers servers found in the configuration
     * @param configPath Optional path to config file (defaults to .mcp-config.json in cwd)
     * @param options Loading options including parallel support
     * @returns Promise resolving to { serversLoaded, errors }
     */
    loadMCPConfiguration(configPath?: string, options?: {
        parallel?: boolean;
    }): Promise<ServerLoadResult>;
    /**
     * Load MCP servers in parallel for improved performance
     * @param configPath Optional path to config file (defaults to .mcp-config.json in cwd)
     * @returns Promise resolving to batch operation result
     */
    loadMCPConfigurationParallel(configPath?: string | null): Promise<ServerLoadResult>;
    /**
     * Load MCP servers sequentially (original implementation for backward compatibility)
     * @param configPath Optional path to config file (defaults to .mcp-config.json in cwd)
     * @returns Promise resolving to batch operation result
     */
    loadMCPConfigurationSequential(configPath?: string): Promise<ServerLoadResult>;
    /**
     * Validate external MCP server configuration
     */
    validateConfig(config: MCPServerInfo): ExternalMCPConfigValidation;
    /**
     * Convert MCPServerInfo format (keeping for backward compatibility)
     * Helper function for transitioning to zero-conversion architecture
     */
    private convertConfigToMCPServerInfo;
    /**
     * Add a new external MCP server - Backward compatibility overload
     */
    addServer(serverId: string, config: MCPServerInfo): Promise<ExternalMCPOperationResult<ExternalMCPServerInstance>>;
    /**
     * Add a new external MCP server - Updated to accept MCPServerInfo
     */
    addServer(serverId: string, serverInfo: MCPServerInfo): Promise<ExternalMCPOperationResult<ExternalMCPServerInstance>>;
    /**
     * Remove an external MCP server
     */
    removeServer(serverId: string): Promise<ExternalMCPOperationResult<void>>;
    /**
     * Start an external MCP server
     */
    private startServer;
    /**
     * Stop an external MCP server
     */
    private stopServer;
    /**
     * Update server status and emit events
     */
    private updateServerStatus;
    /**
     * Handle server errors
     */
    private handleServerError;
    /**
     * Handle server disconnection
     */
    private handleServerDisconnection;
    /**
     * Schedule server restart with exponential backoff
     */
    private scheduleRestart;
    /**
     * Start health monitoring for a server
     */
    private startHealthMonitoring;
    /**
     * Perform health check on a server
     */
    private performHealthCheck;
    /**
     * Get server instance - converted to ExternalMCPServerInstance for compatibility
     */
    getServer(serverId: string): ExternalMCPServerInstance | undefined;
    /**
     * Get all servers - converted to ExternalMCPServerInstance for compatibility
     */
    getAllServers(): Map<string, ExternalMCPServerInstance>;
    /**
     * List servers as MCPServerInfo - ZERO conversion needed
     */
    listServers(): MCPServerInfo[];
    /**
     * Get server statuses
     */
    getServerStatuses(): ExternalMCPServerHealth[];
    /**
     * Shutdown all servers and clean up resources
     * This method should be called during application shutdown to prevent memory leaks
     */
    shutdown(): Promise<void>;
    /**
     * Destroy the manager and all associated resources
     * Alias for shutdown() to match the pattern used by other components
     */
    destroy(): Promise<void>;
    /**
     * Get manager statistics
     */
    getStatistics(): {
        totalServers: number;
        connectedServers: number;
        failedServers: number;
        totalTools: number;
        totalConnections: number;
        totalErrors: number;
    };
    /**
     * Discover tools from a server
     */
    private discoverServerTools;
    /**
     * Register server tools with main tool registry for unified access
     * This enables external MCP tools to be accessed via the main toolRegistry.executeTool()
     */
    private registerServerToolsWithMainRegistry;
    /**
     * Unregister server tools from main tool registry
     */
    private unregisterServerToolsFromMainRegistry;
    /**
     * Execute a tool on a specific server
     */
    executeTool(serverId: string, toolName: string, parameters: JsonObject, options?: {
        timeout?: number;
    }): Promise<unknown>;
    /**
     * Get all tools from all servers
     */
    getAllTools(): ExternalMCPToolInfo[];
    /**
     * Get tools for a specific server
     */
    getServerTools(serverId: string): ExternalMCPToolInfo[];
    /**
     * Get tool discovery service
     */
    getToolDiscovery(): ToolDiscoveryService;
}
