@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
111 lines (110 loc) • 3.25 kB
TypeScript
/**
* 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 { MCPTool, RoutingDecision, ToolRouterConfig } from "../../types/index.js";
/**
* 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;