findCallers
Find all functions that call a given function to trace reverse call graph and understand code dependencies.
Instructions
Find all functions that call a given function (reverse call graph)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| functionName | Yes | Name of the function to find callers for |
Implementation Reference
- src/index.ts:557-609 (handler)The handleFindCallers method: the main handler that executes the findCallers tool logic. It looks up the symbol by name, then queries the call graph for callers, and formats the result.
private async handleFindCallers(functionName: string): Promise<{ content: TextContent[] }> { if (!this.codeAnalyzer || !this.callGraphAnalyzer) { return { content: [ { type: 'text', text: 'Analyzer not initialized', }, ], }; } const config = this.configManager.getConfig(); const vscodeLinkGen = new VSCodeLinkGenerator(config); const symbols = this.codeAnalyzer.findSymbolByName(functionName); if (symbols.length === 0) { return { content: [ { type: 'text', text: `No symbol found with name: ${functionName}`, }, ], }; } const symbol = symbols[0]; const callers = this.callGraphAnalyzer.findCallers(symbol.id); let result = `# Callers of ${functionName}\n\n`; result += `Found ${callers.length} callers:\n\n`; for (const caller of callers) { const vscodeLink = vscodeLinkGen.generate(caller); result += `- **${caller.name}** (${caller.type})\n`; result += ` Location: ${caller.location.file}:${caller.location.range.start.line}\n`; if (vscodeLink) { result += ` [Open in VSCode](${vscodeLink})\n`; } result += '\n'; } return { content: [ { type: 'text', text: result, }, ], }; } - src/index.ts:70-82 (schema)Tool registration with input schema defining the 'functionName' parameter for findCallers.
{ name: 'findCallers', description: 'Find all functions that call a given function (reverse call graph)', inputSchema: { type: 'object' as const, properties: { functionName: { type: 'string', description: 'Name of the function to find callers for', }, }, required: ['functionName'], }, - src/index.ts:169-170 (registration)Routing in the tool dispatch switch statement: maps 'findCallers' tool name to handleFindCallers.
case 'findCallers': return this.handleFindCallers(args.functionName); - The core graph algorithm: findCallers method on CallGraphAnalyzer. Uses graphology inNeighbors to find all symbols that call the given symbol.
findCallers(symbolId: string): Symbol[] { const callers: Symbol[] = []; const inNeighbors = this.graph.inNeighbors(symbolId); inNeighbors.forEach((callerId: string) => { const node = this.graph.getNodeAttributes(callerId); if (node.symbol) { callers.push(node.symbol); } }); return callers; } - src/index.ts:528-530 (helper)Helper usage of findCallers within handleWhoTriggers to filter out symbols with no upstream callers (top-level entries).
const realEntries = upstream.filter( (s) => this.callGraphAnalyzer!.findCallers(s.id).length === 0 );