@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
156 lines (155 loc) • 5.1 kB
TypeScript
/**
* MCP Tool Registry - Extended Registry with Tool Management
* Updated to match industry standard camelCase interfaces
*/
import type { ExecutionContext, ToolInfo } from "./contracts/mcpContract.js";
import type { ToolResult } from "./factory.js";
import type { MCPServerInfo } from "../types/mcpTypes.js";
import { MCPRegistry } from "./registry.js";
interface ToolImplementation {
execute: (params: unknown, context?: ExecutionContext) => Promise<unknown> | unknown;
description?: string;
inputSchema?: unknown;
outputSchema?: unknown;
category?: string;
permissions?: string[];
}
export type ToolExecutionResult = ToolResult;
/**
* Tool execution options
*/
export interface ToolExecutionOptions {
timeout?: number;
retries?: number;
context?: ExecutionContext;
preferredSource?: string;
fallbackEnabled?: boolean;
validateBeforeExecution?: boolean;
timeoutMs?: number;
}
export declare class MCPToolRegistry extends MCPRegistry {
private tools;
private toolImpls;
private toolExecutionStats;
private builtInServerInfos;
constructor();
/**
* Register all direct tools from directAgentTools
*/
private registerDirectTools;
/**
* Register a server with its tools - ONLY accepts MCPServerInfo (zero conversions)
*/
registerServer(serverInfo: MCPServerInfo, context?: ExecutionContext): Promise<void>;
registerServer(serverId: string, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
/**
* Execute a tool with enhanced context and automatic result wrapping
*
* This method handles both raw return values and ToolResult objects:
* - Raw values (primitives, objects) are automatically wrapped in ToolResult format
* - Existing ToolResult objects are enhanced with execution metadata
* - All results include execution timing and context information
*
* @param toolName - Name of the tool to execute
* @param args - Parameters to pass to the tool execution function
* @param context - Execution context with session, user, and environment info
* @returns Promise resolving to ToolResult object with data, metadata, and usage info
* @throws Error if tool is not found or execution fails
*
* @example
* ```typescript
* // Tool that returns raw value
* const result = await toolRegistry.executeTool("calculator", { a: 5, b: 3, op: "add" });
* // result.data === 8, result.metadata contains execution info
*
* // Tool that returns ToolResult
* const result = await toolRegistry.executeTool("complexTool", { input: "test" });
* // result is enhanced ToolResult with additional metadata
* ```
*/
executeTool<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
/**
* List all available tools (updated signature with filtering)
*/
listTools(): Promise<ToolInfo[]>;
listTools(context: ExecutionContext): Promise<ToolInfo[]>;
listTools(filter: {
category?: string;
serverId?: string;
serverCategory?: string;
permissions?: string[];
context?: ExecutionContext;
}): Promise<ToolInfo[]>;
/**
* Get tool information with server details
*/
getToolInfo(toolName: string): {
tool: ToolInfo;
server: {
id: string;
};
} | undefined;
/**
* Update execution statistics
*/
private updateStats;
/**
* Get execution statistics
*/
getExecutionStats(): Record<string, {
count: number;
averageTime: number;
totalTime: number;
}>;
/**
* Clear execution statistics
*/
clearStats(): void;
/**
* Get built-in servers
* @returns Array of MCPServerInfo for built-in tools
*/
getBuiltInServerInfos(): MCPServerInfo[];
/**
* Get tools by category
*/
getToolsByCategory(category: string): ToolInfo[];
/**
* Check if tool exists
*/
hasTool(toolName: string): boolean;
/**
* Register a tool with implementation directly
* This is used for external MCP server tools
*/
registerTool(toolId: string, toolInfo: ToolInfo, toolImpl: ToolImplementation): void;
/**
* Remove a tool
*/
removeTool(toolName: string): boolean;
/**
* Get tool count
*/
getToolCount(): number;
/**
* Get comprehensive statistics
*/
getStats(): {
totalServers: number;
totalTools: number;
serversByCategory: Record<string, number>;
toolsByCategory: Record<string, number>;
executionStats: Record<string, {
count: number;
averageTime: number;
totalTime: number;
}>;
};
/**
* Unregister a server
*/
unregisterServer(serverId: string): boolean;
}
export declare const toolRegistry: MCPToolRegistry;
export declare const defaultToolRegistry: MCPToolRegistry;
export type { ToolInfo } from "./contracts/mcpContract.js";