@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
194 lines (193 loc) • 5.09 kB
TypeScript
/**
* Tool Discovery Service
* Automatically discovers and registers tools from external MCP servers
* Handles tool validation, transformation, and lifecycle management
*/
import { EventEmitter } from "events";
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
import type { ExternalMCPToolInfo, ExternalMCPToolResult, ExternalMCPToolContext } from "../types/externalMcp.js";
import type { JsonObject } from "../types/common.js";
/**
* Tool discovery result
*/
export interface ToolDiscoveryResult {
/** Whether discovery was successful */
success: boolean;
/** Number of tools discovered */
toolCount: number;
/** Discovered tools */
tools: ExternalMCPToolInfo[];
/** Error message if failed */
error?: string;
/** Discovery duration in milliseconds */
duration: number;
/** Server ID */
serverId: string;
}
/**
* Tool execution options
*/
export interface ToolExecutionOptions {
/** Execution timeout in milliseconds */
timeout?: number;
/** Additional context for execution */
context?: Partial<ExternalMCPToolContext>;
/** Whether to validate input parameters */
validateInput?: boolean;
/** Whether to validate output */
validateOutput?: boolean;
}
/**
* Tool validation result
*/
export interface ToolValidationResult {
/** Whether the tool is valid */
isValid: boolean;
/** Validation errors */
errors: string[];
/** Validation warnings */
warnings: string[];
/** Tool metadata */
metadata?: {
category?: string;
complexity?: "simple" | "moderate" | "complex";
requiresAuth?: boolean;
isDeprecated?: boolean;
};
}
/**
* Tool registry events
*/
export interface ToolRegistryEvents {
toolRegistered: {
serverId: string;
toolName: string;
toolInfo: ExternalMCPToolInfo;
timestamp: Date;
};
toolUnregistered: {
serverId: string;
toolName: string;
timestamp: Date;
};
toolUpdated: {
serverId: string;
toolName: string;
oldInfo: ExternalMCPToolInfo;
newInfo: ExternalMCPToolInfo;
timestamp: Date;
};
discoveryCompleted: {
serverId: string;
toolCount: number;
duration: number;
timestamp: Date;
};
discoveryFailed: {
serverId: string;
error: string;
timestamp: Date;
};
}
/**
* ToolDiscoveryService
* Handles automatic tool discovery and registration from external MCP servers
*/
export declare class ToolDiscoveryService extends EventEmitter {
private serverToolStorage;
private toolRegistry;
private serverTools;
private discoveryInProgress;
constructor();
/**
* Discover tools from an external MCP server
*/
discoverTools(serverId: string, client: Client, timeout?: number): Promise<ToolDiscoveryResult>;
/**
* Perform the actual tool discovery
*/
private performToolDiscovery;
/**
* Register discovered tools
*/
private registerDiscoveredTools;
/**
* Create tool info from MCP tool definition
*/
private createToolInfo;
/**
* Infer tool category from tool definition
*/
private inferToolCategory;
/**
* Validate a tool
*/
private validateTool;
/**
* Infer tool complexity
*/
private inferComplexity;
/**
* Infer if tool requires authentication
*/
private inferAuthRequirement;
/**
* Execute a tool
*/
executeTool(toolName: string, serverId: string, client: Client, parameters: JsonObject, options?: ToolExecutionOptions): Promise<ExternalMCPToolResult>;
/**
* Validate tool parameters
*/
private validateToolParameters;
/**
* Validate parameter type
*/
private validateParameterType;
/**
* Validate tool output with enhanced type safety
*/
private validateToolOutput;
/**
* Update tool statistics
*/
private updateToolStats;
/**
* Get tool by name and server
*/
getTool(toolName: string, serverId: string): ExternalMCPToolInfo | undefined;
/**
* Get all tools for a server
*/
getServerTools(serverId: string): ExternalMCPToolInfo[];
/**
* Get all registered tools
*/
getAllTools(): ExternalMCPToolInfo[];
/**
* Clear tools for a server
*/
clearServerTools(serverId: string): void;
/**
* Update tool availability
*/
updateToolAvailability(toolName: string, serverId: string, isAvailable: boolean): void;
/**
* Create tool key for registry
*/
private createToolKey;
/**
* Create timeout promise
*/
private createTimeoutPromise;
/**
* Get discovery statistics
*/
getStatistics(): {
totalTools: number;
availableTools: number;
unavailableTools: number;
totalServers: number;
toolsByServer: Record<string, number>;
toolsByCategory: Record<string, number>;
};
}