get_class
Retrieve class definitions and specific methods without reading entire files to reduce token usage by 80%+ in code navigation.
Instructions
⭐ PREFERRED OVER Read: Get class definition without reading the entire file. Optionally filter specific methods. Saves 80%+ tokens vs reading full files. Use this when you need class structure or specific class methods.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| className | Yes | The name of the class to retrieve | |
| methods | No | Optional: specific method names to include. If omitted, returns all methods. | |
| filePath | No | Optional: specific file path if known |
Implementation Reference
- src/retriever.ts:89-133 (handler)The actual implementation of the getClass logic that searches the index and retrieves class definitions.
async getClass( className: string, methods?: string[], filePath?: string ): Promise<string> { const symbols = this.indexer.findSymbols(className, 'class'); if (symbols.length === 0) { return `Class "${className}" not found in index.`; } let targetSymbol: Symbol; if (filePath) { // Normalize path to handle Windows vs Unix separators const normalizedInput = path.normalize(filePath); const matches = symbols.filter((s) => path.normalize(s.filePath) === normalizedInput); if (matches.length === 0) { return `Class "${className}" not found in file "${filePath}".\nFound in: ${symbols.map((s) => s.filePath).join(', ')}`; } targetSymbol = matches[0]; } else { if (symbols.length > 1) { const locations = symbols.map((s) => ` - ${s.filePath}:${s.line}`).join('\n'); return `Multiple classes named "${className}" found:\n${locations}\n\nPlease specify filePath to get the exact class.`; } targetSymbol = symbols[0]; } // If specific methods requested, extract only those if (methods && methods.length > 0) { return this.extractClassMethods(targetSymbol, methods); } return this.formatSymbolWithContext(targetSymbol); } async getRelevantContext(query: string, maxTokens: number): Promise<string> { // Use advanced search engine const allSymbols = this.getAllSymbols(); const files = this.indexer.getAllFiles(); const searchOptions: SearchOptions = { maxResults: 50, // Get more candidates, then filter by tokens fuzzyThreshold: 0.7, - src/index.ts:198-220 (registration)Registration of the 'get_class' tool definition including schema.
{ name: 'get_class', description: '⭐ PREFERRED OVER Read: Get class definition without reading the entire file. Optionally filter specific methods. Saves 80%+ tokens vs reading full files. Use this when you need class structure or specific class methods.', inputSchema: { type: 'object', properties: { className: { type: 'string', description: 'The name of the class to retrieve', }, methods: { type: 'array', items: { type: 'string' }, description: 'Optional: specific method names to include. If omitted, returns all methods.', }, filePath: { type: 'string', description: 'Optional: specific file path if known', }, }, required: ['className'], }, }, - src/index.ts:442-464 (handler)Tool handler switch case that calls retriever.getClass.
case 'get_class': { const a = args as any; const className: string = a.className || a.name; const methods: string[] | undefined = a.methods; const filePath: string | undefined = a.filePath || a.path || a.file; if (!className) { return { content: [{ type: 'text', text: 'Error: className is required. Provide the name of the class to retrieve.' }], isError: true, }; } const result = await retriever.getClass(className, methods, filePath); return { content: [ { type: 'text', text: result, }, ], }; } case 'get_relevant_context': {