UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

163 lines (162 loc) • 5.68 kB
/** * MCP Tool Registry - Extended Registry with Tool Management * Updated to match industry standard camelCase interfaces */ import type { MCPServerInfo, ToolImplementation, ToolInfo, ExecutionContext, FileToolRootPolicy, HITLManager } from "../types/index.js"; import { MCPRegistry } from "./registry.js"; export declare class MCPToolRegistry extends MCPRegistry { private tools; private toolImplementations; private toolExecutionStats; private builtInServerInfos; private hitlManager?; private fileToolRootResolver; constructor(); /** * Set HITL manager for human-in-the-loop safety mechanisms * @param hitlManager - HITL manager instance (optional, can be undefined to disable) */ setHITLManager(hitlManager?: HITLManager): void; /** * Get current HITL manager */ getHITLManager(): HITLManager | undefined; /** * Resolve file-tool roots for built-in tools executed on this registry * without a per-call policy. Set by the NeuroLink instance that created it. */ setFileToolRootResolver(resolver: () => FileToolRootPolicy): void; /** * The built-in tool bound to the policy that applies to this execution: one * NeuroLink bound on the context, else this registry's owner's roots. */ private directToolFor; /** * 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[]>; private resolveToolExecutionTarget; private createExecutionContext; /** * 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[]; /** * NL-001: Get available tools, filtering out those with OPEN circuit breakers. * Returns both the filtered tools and the list of unavailable tool names. */ getAvailableTools(circuitBreakers: Map<string, import("../utils/errorHandling.js").CircuitBreaker>): { tools: ToolInfo[]; unavailableTools: string[]; }; /** * 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): Promise<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;