/**
 * Tool Router - Routes tool calls to appropriate MCP servers
 * Based on tool categories, annotations, and server capabilities
 *
 * Provides intelligent routing strategies for multi-server MCP environments:
 * - Round-robin for even distribution
 * - Least-loaded for optimal performance
 * - Capability-based for specialized servers
 * - Affinity-based for session consistency
 */
import { EventEmitter } from "events";
import type { ToolInfo } from "../../types/tools.js";
import type { MCPToolAnnotations } from "../mcpServerBase.js";
/**
 * Routing strategy types
 */
export type RoutingStrategy = "round-robin" | "least-loaded" | "capability-based" | "affinity" | "priority" | "random";
/**
 * Server routing weight configuration
 */
export type ServerWeight = {
    serverId: string;
    weight: number;
    capabilities?: string[];
};
/**
 * Category to server mapping
 */
export type CategoryMapping = {
    category: string;
    serverIds: string[];
    priority?: number;
};
/**
 * Affinity rule for session-based routing
 */
export type AffinityRule = {
    key: string;
    serverId: string;
    expiresAt?: number;
};
/**
 * Tool Router configuration
 */
export type ToolRouterConfig = {
    /**
     * Primary routing strategy
     */
    strategy: RoutingStrategy;
    /**
     * Enable session/user affinity for consistent routing
     */
    enableAffinity?: boolean;
    /**
     * Category to server mapping for capability-based routing
     */
    categoryMapping?: Record<string, string[]>;
    /**
     * Server weights for priority-based routing
     */
    serverWeights?: ServerWeight[];
    /**
     * Fallback strategy if primary fails
     */
    fallbackStrategy?: RoutingStrategy;
    /**
     * Maximum retries for failed routes
     */
    maxRetries?: number;
    /**
     * Health check interval in milliseconds
     */
    healthCheckInterval?: number;
    /**
     * Affinity TTL in milliseconds (default: 30 minutes)
     */
    affinityTtl?: number;
};
/**
 * Routing decision result
 */
export type RoutingDecision = {
    serverId: string;
    strategy: RoutingStrategy;
    confidence: number;
    alternates?: string[];
    reason?: string;
};
/**
 * Tool Router events
 */
export type ToolRouterEvents = {
    routeDecision: {
        toolName: string;
        decision: RoutingDecision;
    };
    routeFailed: {
        toolName: string;
        error: Error;
        attemptedServers: string[];
    };
    affinitySet: {
        key: string;
        serverId: string;
    };
    affinityExpired: {
        key: string;
    };
    healthUpdate: {
        serverId: string;
        healthy: boolean;
    };
};
/**
 * MCP Tool type with annotations
 */
export type MCPTool = ToolInfo & {
    annotations?: MCPToolAnnotations;
    serverId?: string;
    category?: string;
};
/**
 * Default router configuration for common use cases
 */
export declare const DEFAULT_ROUTER_CONFIG: ToolRouterConfig;
/**
 * Tool Router - Intelligent routing for MCP tool calls
 *
 * @example
 * ```typescript
 * const router = new ToolRouter({
 *   strategy: 'least-loaded',
 *   enableAffinity: true,
 *   categoryMapping: {
 *     'database': ['db-server-1', 'db-server-2'],
 *     'ai': ['ai-server-primary', 'ai-server-secondary'],
 *   },
 * });
 *
 * const decision = router.route(tool, { sessionId: 'user-123' });
 * console.log(`Routing to: ${decision.serverId}`);
 * ```
 */
export declare class ToolRouter extends EventEmitter {
    private config;
    private roundRobinIndex;
    private serverLoads;
    private affinityRules;
    private healthStatus;
    private availableServers;
    private affinityCleanupTimer?;
    constructor(config?: ToolRouterConfig);
    destroy(): void;
    private cleanupExpiredAffinities;
    /**
     * Register a server as available for routing
     */
    registerServer(serverId: string, capabilities?: string[]): void;
    /**
     * Unregister a server from routing
     */
    unregisterServer(serverId: string): void;
    /**
     * Route a tool call to the best server
     */
    route(tool: MCPTool, context?: {
        sessionId?: string;
        userId?: string;
    }): RoutingDecision;
    /**
     * Route by tool category
     */
    routeByCategory(tool: MCPTool, category: string): string[];
    /**
     * Route by tool annotation hints
     */
    routeByAnnotation(tool: MCPTool): string[];
    /**
     * Route by required capabilities
     */
    routeByCapability(tool: MCPTool, requiredCapabilities: string[]): string[];
    /**
     * Update server load for least-loaded routing
     */
    updateServerLoad(serverId: string, delta: number): void;
    /**
     * Update server health status
     */
    updateHealthStatus(serverId: string, healthy: boolean): void;
    /**
     * Set session/user affinity
     */
    setAffinity(key: string, serverId: string): void;
    /**
     * Clear affinity for a key
     */
    clearAffinity(key: string): void;
    /**
     * Get current routing statistics
     */
    getStats(): {
        availableServers: number;
        healthyServers: number;
        activeAffinities: number;
        serverLoads: Record<string, number>;
    };
    private getCandidateServers;
    private applyStrategy;
    private roundRobinSelect;
    private leastLoadedSelect;
    private capabilityBasedSelect;
    private prioritySelect;
    private randomSelect;
    private isServerHealthy;
}
/**
 * Factory function to create a ToolRouter instance
 */
export declare const createToolRouter: (config: ToolRouterConfig) => ToolRouter;
