MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / handleImpact

Method handleImpact

src/mcp/tools.ts:3596–3671  ·  view source on GitHub ↗

* Handle codegraph_impact

(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

3594 * Handle codegraph_impact
3595 */
3596 private async handleImpact(args: Record<string, unknown>): Promise<ToolResult> {
3597 const symbol = this.validateString(args.symbol, 'symbol');
3598 if (typeof symbol !== 'string') return symbol;
3599
3600 const cg = this.getCodeGraph(args.projectPath as string | undefined);
3601 const depth = clamp((args.depth as number) || 2, 1, 10);
3602 const fileFilter = typeof args.file === 'string' ? args.file : undefined;
3603
3604 const allMatches = this.findAllSymbols(cg, symbol);
3605 if (allMatches.nodes.length === 0) {
3606 return this.textResult(`Symbol "${symbol}" not found in the codebase${allMatches.note}`);
3607 }
3608
3609 const { groups, filteredOut } = this.groupDefinitions(allMatches.nodes, fileFilter);
3610 const answerPaths = new Set(groups.flat().map(node => node.filePath));
3611 const filterNote = filteredOut
3612 ? `\n\n> **Note:** no definition of "${symbol}" matches file "${fileFilter}" — showing all definitions instead.`
3613 : '';
3614
3615 const impactOf = (defNodes: Node[]) => {
3616 const mergedNodes = new Map<string, Node>();
3617 const mergedEdges: Edge[] = [];
3618 const seenEdges = new Set<string>();
3619 let truncated = false;
3620 for (const node of defNodes) {
3621 const impact = cg.getImpactRadius(node.id, depth);
3622 truncated ||= impact.truncated === true;
3623 for (const [id, n] of impact.nodes) {
3624 if (!mergedNodes.has(id) && mergedNodes.size >= DEFAULT_IMPACT_MAX_NODES) {
3625 truncated = true;
3626 continue;
3627 }
3628 mergedNodes.set(id, n);
3629 answerPaths.add(n.filePath);
3630 }
3631 for (const e of impact.edges) {
3632 if (!mergedNodes.has(e.source) || !mergedNodes.has(e.target)) {
3633 truncated = true;
3634 continue;
3635 }
3636 const key = `${e.source}->${e.target}:${e.kind}`;
3637 if (!seenEdges.has(key)) {
3638 if (mergedEdges.length >= DEFAULT_IMPACT_MAX_EDGES) {
3639 truncated = true;
3640 continue;
3641 }
3642 seenEdges.add(key);
3643 mergedEdges.push(e);
3644 }
3645 }
3646 }
3647 return { nodes: mergedNodes, edges: mergedEdges, roots: defNodes.map((n) => n.id), truncated };
3648 };
3649
3650 // Single definition (or same-file overloads): the familiar merged report.
3651 if (groups.length === 1) {
3652 const formatted = this.formatImpact(symbol, impactOf(groups[0]!)) + (fileFilter && !filteredOut ? "" : allMatches.note) + filterNote;
3653 return this.answerResult(cg, this.truncateOutput(formatted), answerPaths);

Callers 1

dispatchToolMethod · 0.95

Calls 13

validateStringMethod · 0.95
getCodeGraphMethod · 0.95
findAllSymbolsMethod · 0.95
textResultMethod · 0.95
groupDefinitionsMethod · 0.95
formatImpactMethod · 0.95
answerResultMethod · 0.95
truncateOutputMethod · 0.95
clampFunction · 0.90
mapMethod · 0.80
pushMethod · 0.80
impactOfFunction · 0.50

Tested by

no test coverage detected