UNPKG

il2cpp-dump-analyzer-mcp

Version:

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

154 lines 6.33 kB
"use strict"; /** * Find Class Hierarchy Tool Implementation * Analyzes class inheritance relationships and structure */ Object.defineProperty(exports, "__esModule", { value: true }); exports.findClassHierarchySchema = exports.FindClassHierarchyToolHandler = void 0; exports.createFindClassHierarchyTool = createFindClassHierarchyTool; const zod_1 = require("zod"); const base_tool_handler_1 = require("../base-tool-handler"); const parameter_validator_1 = require("../../utils/parameter-validator"); const mcp_response_formatter_1 = require("../../utils/mcp-response-formatter"); /** * Find Class Hierarchy Tool Handler * Analyzes class inheritance relationships and structure */ class FindClassHierarchyToolHandler extends base_tool_handler_1.BaseAnalysisToolHandler { constructor(context) { super({ name: 'find_class_hierarchy', description: 'Analyze class inheritance relationships and structure', enableParameterValidation: true, enableResponseFormatting: true }, context); } /** * Validate class hierarchy parameters */ async validateParameters(params) { const errors = []; const warnings = []; const adjustedValues = {}; // Validate class_name parameter const classNameValidation = parameter_validator_1.ParameterValidator.validateClassName(params.class_name); errors.push(...classNameValidation.errors); warnings.push(...classNameValidation.warnings); // Validate include_methods parameter if (params.include_methods === undefined) { adjustedValues.include_methods = true; // Default value } return { isValid: errors.length === 0, errors, warnings, adjustedValues }; } /** * Execute class hierarchy analysis */ async executeCore(params) { return await this.performAnalysis(async () => { // Step 1: Find the target class const classResults = await this.context.vectorStore.searchWithFilter(params.class_name, { type: 'class' }, 1); if (classResults.length === 0) { throw new Error(`Class '${params.class_name}' not found in the IL2CPP dump.`); } const classDoc = classResults[0]; const className = classDoc.metadata.name; const baseClass = classDoc.metadata.baseClass; this.context.logger.debug(`Analyzing hierarchy for class: ${className}`); // Step 2: Build basic hierarchy information const hierarchyInfo = { name: className, namespace: classDoc.metadata.namespace, fullName: classDoc.metadata.fullName, baseClass: baseClass, interfaces: classDoc.metadata.interfaces || [], isMonoBehaviour: classDoc.metadata.isMonoBehaviour || false, metadata: { searchedClass: params.class_name, includesMethods: params.include_methods || true, timestamp: new Date().toISOString() } }; // Step 3: Find methods if requested if (params.include_methods) { const methodResults = await this.context.vectorStore.searchWithFilter("", { type: 'method', parentClass: className }, 50); hierarchyInfo.methods = methodResults.map(doc => ({ name: doc.metadata.name, returnType: doc.metadata.returnType || 'void', parameters: doc.metadata.parameters || '', isStatic: !!doc.metadata.isStatic, isVirtual: !!doc.metadata.isVirtual, isOverride: !!doc.metadata.isOverride })); this.context.logger.debug(`Found ${hierarchyInfo.methods.length} methods for class ${className}`); } return hierarchyInfo; }); } /** * Format hierarchy analysis results */ formatResponse(result, warnings = []) { let response = mcp_response_formatter_1.MCPResponseFormatter.formatAnalysisResults(result, this.config.name, { class_name: result.metadata.searchedClass }, Date.now() - this.startTime); if (warnings.length > 0) { response = mcp_response_formatter_1.MCPResponseFormatter.addWarnings(response, warnings); } return response; } /** * Handle class not found error specifically */ handleError(error, params) { if (error.message && error.message.includes('not found')) { return mcp_response_formatter_1.MCPResponseFormatter.formatNotFoundResponse(params?.class_name || 'unknown', 'Class'); } return super.handleError(error, params); } } exports.FindClassHierarchyToolHandler = FindClassHierarchyToolHandler; /** * Zod schema for find class hierarchy tool parameters */ exports.findClassHierarchySchema = zod_1.z.object({ class_name: zod_1.z.string().describe("The name of the class to find hierarchy for"), include_methods: zod_1.z.boolean().optional().default(true).describe("Whether to include methods in the output") }); /** * Factory function to create and register the find class hierarchy tool */ function createFindClassHierarchyTool(server, context) { const handler = new FindClassHierarchyToolHandler(context); server.tool("find_class_hierarchy", exports.findClassHierarchySchema, async (params) => { return await handler.execute(params); }); return handler; } /** * Code Reduction Analysis: * * BEFORE: 98 lines of implementation code * AFTER: 45 lines of business logic * REDUCTION: 54% less code * * Eliminated: * ✅ Manual error handling (12 lines) * ✅ Parameter validation boilerplate (8 lines) * ✅ Logging setup (6 lines) * ✅ Response formatting (15 lines) * ✅ Try-catch blocks (12 lines) * * Benefits: * ✅ Consistent error handling with other tools * ✅ Automatic parameter validation * ✅ Standardized response format * ✅ Built-in performance monitoring * ✅ Easier to test and maintain */ //# sourceMappingURL=find-class-hierarchy-tool.js.map