UNPKG

il2cpp-dump-analyzer-mcp

Version:

Agentic RAG system for analyzing IL2CPP dump.cs files from Unity games

160 lines (159 loc) 5.43 kB
/** * Base Tool Handler for MCP Tools * Eliminates code duplication by providing a common foundation for all MCP tool implementations */ import { Document } from '@langchain/core/documents'; import { ValidationResult } from '../utils/parameter-validator'; import { MCPResponse } from '../utils/mcp-response-formatter'; /** * Logger interface for consistent logging across tools */ interface Logger { debug(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } /** * Vector store interface for tool operations */ interface VectorStore { similaritySearch(query: string, k: number): Promise<Document[]>; searchWithFilter(query: string, filter: Record<string, any>, k: number): Promise<Document[]>; } /** * Tool execution context */ export interface ToolExecutionContext { vectorStore: VectorStore; logger: Logger; isInitialized: () => boolean; } /** * Base tool configuration */ export interface BaseToolConfig { name: string; description: string; maxExecutionTime?: number; enableParameterValidation?: boolean; enableResponseFormatting?: boolean; } /** * Tool execution result */ export interface ToolExecutionResult { success: boolean; data?: any; errors?: string[]; warnings?: string[]; executionTime?: number; metadata?: Record<string, any>; } /** * Abstract base class for all MCP tool handlers */ export declare abstract class BaseMCPToolHandler<TParams = any, TResult extends string | object = any> { protected readonly config: BaseToolConfig; protected readonly context: ToolExecutionContext; protected startTime: number; constructor(config: BaseToolConfig, context: ToolExecutionContext); /** * Main execution method - handles the complete tool lifecycle */ execute(params: TParams): Promise<MCPResponse>; /** * Abstract method for core tool logic - must be implemented by subclasses */ protected abstract executeCore(params: TParams): Promise<TResult>; /** * Validate tool parameters - can be overridden by subclasses */ protected validateParameters(params: TParams): Promise<ValidationResult>; /** * Apply parameter adjustments from validation */ protected applyParameterAdjustments(originalParams: TParams, adjustedValues?: Record<string, any>): TParams; /** * Format the tool response - can be overridden by subclasses */ protected formatResponse(result: TResult, warnings?: string[]): MCPResponse; /** * Handle errors consistently across all tools */ protected handleError(error: any, params?: TParams): MCPResponse; /** * Ensure the system is properly initialized */ protected ensureInitialized(): void; /** * Log tool execution start */ protected logToolStart(params: TParams): void; /** * Log tool execution completion */ protected logToolCompletion(result: TResult): void; /** * Sanitize parameters for logging (remove sensitive data) */ protected sanitizeParamsForLogging(params: TParams): any; /** * Helper method for vector store searches with consistent error handling */ protected performVectorSearch(query: string, filter?: Record<string, any>, limit?: number): Promise<Document[]>; /** * Helper method to create search filters from parameters */ protected createSearchFilter(params: any): Record<string, any>; /** * Helper method to extract and validate query from parameters */ protected extractQuery(params: any): string; } /** * Specialized base class for search-based tools */ export declare abstract class BaseSearchToolHandler<TParams = any> extends BaseMCPToolHandler<TParams, Document[]> { /** * Execute search and format results */ protected executeCore(params: TParams): Promise<Document[]>; /** * Format search results with metadata */ protected formatResponse(results: Document[], warnings?: string[]): MCPResponse; } /** * Specialized base class for analysis tools */ export declare abstract class BaseAnalysisToolHandler<TParams = any, TResult extends string | object = any> extends BaseMCPToolHandler<TParams, TResult> { /** * Perform analysis with consistent error handling and logging */ protected performAnalysis(analysisFunction: () => Promise<TResult>): Promise<TResult>; } /** * Specialized base class for code generation tools */ export declare abstract class BaseGenerationToolHandler<TParams = any, TResult extends string | object = any> extends BaseMCPToolHandler<TParams, TResult> { /** * Perform code generation with consistent error handling and logging */ protected performGeneration(generationFunction: () => Promise<TResult>): Promise<TResult>; /** * Validate class name for generation */ protected validateClassNameForGeneration(className: string): ValidationResult; /** * Format generation results with metadata */ protected formatGenerationResponse(generatedCode: string, metadata: { className?: string; fileName?: string; language?: string; warnings?: string[]; statistics?: Record<string, any>; }, warnings?: string[]): MCPResponse; } export {};