UNPKG

jezweb-mcp-core

Version:

Jezweb Model Context Protocol (MCP) Core - A universal server for providing AI tools and resources, designed for seamless integration with various AI models and clients. Features adaptable multi-provider support, comprehensive tool and resource management

113 lines 3.62 kB
/** * Tool Registry - Central registry for managing and executing tool handlers * * This class implements the Registry pattern and acts as a facade for tool execution: * - Maintains a map of tool names to handler instances * - Provides registration and execution methods * - Handles unknown tools with proper error messages * - Supports dynamic handler registration for extensibility * * Usage: * 1. Register handlers: registry.register('assistant-create', new AssistantCreateHandler(context)) * 2. Execute tools: await registry.execute('assistant-create', args) */ import { BaseToolHandler, ToolHandlerContext } from './handlers/base-tool-handler.js'; /** * Interface for tool registry statistics */ export interface ToolRegistryStats { totalHandlers: number; handlersByCategory: Record<string, number>; registeredTools: string[]; } /** * Central registry for tool handlers * * Responsibilities: * - Store and manage tool handler instances * - Route tool execution requests to appropriate handlers * - Provide introspection capabilities * - Handle registration and deregistration of handlers */ export declare class ToolRegistry { private handlers; private context; constructor(context: ToolHandlerContext); /** * Register a tool handler * * @param toolName - The name of the tool (e.g., 'assistant-create') * @param handler - The handler instance * @throws MCPError if tool is already registered */ register(toolName: string, handler: BaseToolHandler): void; /** * Unregister a tool handler * * @param toolName - The name of the tool to unregister * @returns true if handler was found and removed, false otherwise */ unregister(toolName: string): boolean; /** * Execute a tool by name * * @param toolName - The name of the tool to execute * @param args - The arguments to pass to the tool * @returns Promise resolving to the tool execution result * @throws MCPError if tool is not found or execution fails */ execute(toolName: string, args: any): Promise<any>; /** * Check if a tool is registered * * @param toolName - The name of the tool to check * @returns true if the tool is registered, false otherwise */ isRegistered(toolName: string): boolean; /** * Get all registered tool names * * @returns Array of registered tool names */ getRegisteredTools(): string[]; /** * Get registry statistics * * @returns Statistics about the registry */ getStats(): ToolRegistryStats; /** * Get handler for a specific tool (for testing/debugging) * * @param toolName - The name of the tool * @returns The handler instance or undefined if not found */ getHandler(toolName: string): BaseToolHandler | undefined; /** * Clear all registered handlers (useful for testing) */ clear(): void; /** * Register multiple handlers at once * * @param handlerMap - Map of tool names to handler instances */ registerBatch(handlerMap: Record<string, BaseToolHandler>): void; /** * Create an error for unknown tools with helpful suggestions */ private createUnknownToolError; /** * Find similar tool names for suggestions */ private findSimilarTools; /** * Log handler registration */ private logRegistration; /** * Sanitize arguments for logging (remove sensitive data) */ private sanitizeArgsForLogging; } //# sourceMappingURL=tool-registry.d.ts.map