@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and
147 lines (146 loc) • 4.86 kB
TypeScript
/**
* 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 { ExternalMCPServerInstance, ExternalMCPServerHealth, ExternalMCPConfigValidation, ExternalMCPOperationResult, ExternalMCPManagerConfig, ExternalMCPToolInfo } from "../types/externalMcp.js";
import type { MCPServerInfo } from "../types/mcpTypes.js";
import type { JsonObject } from "../types/common.js";
import type { ServerLoadResult } from "../types/typeAliases.js";
export declare class ExternalServerManager extends EventEmitter {
private servers;
private config;
private isShuttingDown;
private toolDiscovery;
private enableMainRegistryIntegration;
constructor(config?: ExternalMCPManagerConfig, options?: {
enableMainRegistryIntegration?: boolean;
});
/**
* Load MCP server configurations from .mcp-config.json file
* Automatically registers servers found in the configuration
* @param configPath Optional path to config file (defaults to .mcp-config.json in cwd)
* @returns Promise resolving to number of servers loaded
*/
loadMCPConfiguration(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
*/
shutdown(): 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;
}