get_classes
Analyze JavaScript/TypeScript class structures to review architecture, identify hierarchies, audit methods and properties, and prepare for testing.
Instructions
Get all classes with comprehensive method and property analysis. Perfect for OOP code review.
Examples: • Architecture review: get_classes() to understand class structure • API design: get_classes() to see public method interfaces • Inheritance analysis: get_classes() to identify class hierarchies • Method-only view: get_classes({includeProperties: false}) to focus on behavior • Property audit: get_classes({includeMethods: false}) to review state management • Testing prep: get_classes() to identify methods needing unit tests
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeProperties | No | Include class properties (default: true). Set false to focus only on methods. | |
| includeMethods | No | Include class methods (default: true). Set false to focus only on properties. |
Implementation Reference
- src/index.ts:656-701 (handler)The core handler function that implements the logic for the 'get_classes' tool. It validates the presence of a parsed AST, fetches detailed class information using the tree-hugger-js library's getClassDetails() method, conditionally includes methods and properties based on input parameters, processes and truncates textual representations for output, updates the analysis cache, and returns a formatted text response containing the JSON-stringified class data or an error message.private async getClasses(args: { includeProperties?: boolean; includeMethods?: boolean }) { if (!this.currentAST) { return { content: [{ type: "text", text: "No AST loaded. Please use parse_code first.", }], isError: true, }; } try { // Use enhanced library methods for detailed class analysis const classData: ClassInfo[] = this.currentAST.tree.getClassDetails() .map(cls => ({ ...cls, text: cls.text.length > 150 ? cls.text.slice(0, 150) + '...' : cls.text, methods: args.includeMethods !== false ? cls.methods.map(method => ({ ...method, text: method.text.length > 100 ? method.text.slice(0, 100) + '...' : method.text, })) : [], properties: args.includeProperties !== false ? cls.properties : [], })); this.lastAnalysis = { ...this.lastAnalysis, classes: classData, timestamp: new Date(), } as AnalysisResult; return { content: [{ type: "text", text: `Found ${classData.length} classes:\n${JSON.stringify(classData, null, 2)}`, }], }; } catch (error) { return { content: [{ type: "text", text: `Error getting classes: ${error instanceof Error ? error.message : String(error)}`, }], isError: true, }; } }
- src/index.ts:254-266 (schema)The input schema definition for the 'get_classes' tool, specifying optional boolean parameters for including properties and methods in the class analysis output.inputSchema: { type: "object", properties: { includeProperties: { type: "boolean", description: "Include class properties (default: true). Set false to focus only on methods." }, includeMethods: { type: "boolean", description: "Include class methods (default: true). Set false to focus only on properties." } }, },
- src/index.ts:251-267 (registration)The tool registration in the ListToolsRequestSchema handler, including the name, description, and input schema for 'get_classes'.{ name: "get_classes", description: "Get all classes with comprehensive method and property analysis. Perfect for OOP code review.\n\nExamples:\n• Architecture review: get_classes() to understand class structure\n• API design: get_classes() to see public method interfaces\n• Inheritance analysis: get_classes() to identify class hierarchies\n• Method-only view: get_classes({includeProperties: false}) to focus on behavior\n• Property audit: get_classes({includeMethods: false}) to review state management\n• Testing prep: get_classes() to identify methods needing unit tests", inputSchema: { type: "object", properties: { includeProperties: { type: "boolean", description: "Include class properties (default: true). Set false to focus only on methods." }, includeMethods: { type: "boolean", description: "Include class methods (default: true). Set false to focus only on properties." } }, }, },
- src/index.ts:425-426 (registration)The dispatch registration in the CallToolRequestSchema switch statement that routes calls to the getClasses handler.case "get_classes": return await this.getClasses(args as { includeProperties?: boolean; includeMethods?: boolean });