get_function
Retrieve specific function implementations from code files to reduce token usage by extracting only needed function definitions instead of reading entire files.
Instructions
⭐ PREFERRED OVER Read: Get complete function code without reading the entire file. Saves 85% tokens compared to Read. Use when you need a specific function implementation instead of reading full files. Returns only the function definition with signature.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| functionName | Yes | The name of the function to retrieve | |
| filePath | No | Optional: specific file path if known |
Implementation Reference
- src/retriever.ts:61-96 (handler)The actual implementation of the getFunction logic which searches for symbols and retrieves the function code.
async getFunction(functionName: string, filePath?: string): Promise<string> { const symbols = this.indexer.findSymbols(functionName, 'function'); if (symbols.length === 0) { return `Function "${functionName}" not found in index.\nTry indexing the repository first with index_repository tool.`; } 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 `Function "${functionName}" 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 functions named "${functionName}" found:\n${locations}\n\nPlease specify filePath to get the exact function.`; } targetSymbol = symbols[0]; } return this.formatSymbolWithContext(targetSymbol); } async getClass( className: string, methods?: string[], filePath?: string ): Promise<string> { const symbols = this.indexer.findSymbols(className, 'class'); if (symbols.length === 0) { - src/index.ts:180-197 (registration)Tool definition and registration of get_function in the MCP tool list.
{ name: 'get_function', description: '⭐ PREFERRED OVER Read: Get complete function code without reading the entire file. Saves 85% tokens compared to Read. Use when you need a specific function implementation instead of reading full files. Returns only the function definition with signature.', inputSchema: { type: 'object', properties: { functionName: { type: 'string', description: 'The name of the function to retrieve', }, filePath: { type: 'string', description: 'Optional: specific file path if known', }, }, required: ['functionName'], }, }, - src/index.ts:421-440 (handler)The tool call handling switch case that parses the arguments and invokes the retriever's getFunction method.
case 'get_function': { const a = args as any; const functionName: string = a.functionName || a.name; const filePath: string | undefined = a.filePath || a.path || a.file; if (!functionName) { return { content: [{ type: 'text', text: 'Error: functionName is required. Provide the name of the function to retrieve.' }], isError: true, }; } const result = await retriever.getFunction(functionName, filePath); return { content: [ { type: 'text', text: result, }, ], }; }