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

83 lines 2.8 kB
/** * Base Tool Handler - Abstract class defining the interface for all tool handlers * * This class implements the Strategy pattern for tool handling, providing: * - Consistent validation and execution interface * - Error handling and logging capabilities * - Template method pattern for handle() operation * * Each concrete handler must implement: * - validate(): Validates input arguments * - execute(): Performs the actual tool operation */ import { MCPError, LLMProvider } from '../../types/index.js'; import { ValidationResult } from '../../validation/index.js'; /** * Interface for tool handler execution context */ export interface ToolHandlerContext { provider: LLMProvider; toolName: string; requestId: string | number | null; } /** * Interface for tool execution result */ export interface ToolExecutionResult { success: boolean; data?: any; error?: string; } /** * Abstract base class for all tool handlers * * Implements the Template Method pattern: * 1. handle() orchestrates the validation + execution flow * 2. Concrete handlers implement validate() and execute() * 3. Error handling and logging are centralized */ export declare abstract class BaseToolHandler { protected context: ToolHandlerContext; constructor(context: ToolHandlerContext); /** * Template method that orchestrates validation and execution * This is the main entry point for tool handling */ handle(args: any): Promise<any>; /** * Abstract method: Validate input arguments * Each handler must implement its specific validation logic */ abstract validate(args: any): ValidationResult; /** * Abstract method: Execute the tool operation * Each handler must implement its specific execution logic */ abstract execute(args: any): Promise<any>; /** * Get the tool name this handler is responsible for */ abstract getToolName(): string; /** * Get the tool category (e.g., 'assistant', 'thread', 'message', 'run', 'run-step') */ abstract getCategory(): string; /** * Centralized error logging * Can be extended for more sophisticated logging in the future */ protected logError(error: any, args: any): void; /** * Sanitize arguments for logging (remove sensitive data) */ protected sanitizeArgsForLogging(args: any): any; /** * Helper method to create validation errors with consistent formatting */ protected createValidationError(message: string, paramName?: string): MCPError; /** * Helper method to create execution errors with consistent formatting */ protected createExecutionError(message: string, originalError?: any): MCPError; } //# sourceMappingURL=base-tool-handler.d.ts.map