Skip to main content
Glama

codebase_impact

Identify every file and function that depends on a target file or symbol, showing the blast radius before refactoring or deleting code.

Instructions

Impact Analysis — return the BLAST RADIUS for a file or symbol. Lists every file (and, where helpful, function) that could break if you change the target. Polymorphic on target: a path-like string ('src/foo.ts') triggers file-mode; a name-like string ('validateUser') triggers symbol-mode. Use this BEFORE refactoring, renaming, or deleting code to know what depends on it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathNoAbsolute path to the project directory.
targetYesTarget file path (relative) OR symbol name.
depthNoHow many hops back to walk (default 3, max 10).

Implementation Reference

  • The handler case for 'codebase_impact' inside handleGraphTool(). Extracts target/depth args, loads the symbol graph cache, calls getImpactRadius(), and formats the blast-radius output.
    case "codebase_impact": {
      const target = (args.target as string)?.trim();
      if (!target) return "Missing required argument: target";
      const depth = typeof args.depth === "number" ? args.depth : 3;
      const projectId = projectIdFromPath(projectPath);
      const cache = await getSymbolGraphCache(projectId);
      if (!cache) {
        return "No symbol graph found. Run codebase_graph_build (or codebase_index) first.";
      }
      const result = await getImpactRadius(cache, target, depth);
      const lines = [
        `Blast radius for ${result.targetKind}: ${result.target}`,
        `Depth: ${result.depth}    Total impacted files: ${result.totalFiles}`,
        "",
      ];
      if (result.totalFiles === 0) {
        lines.push("No callers found — nothing else depends on this.");
      } else {
        for (const [hop, files] of result.filesByDepth.entries()) {
          lines.push(`Hop ${hop} (${files.length} files):`);
          for (const f of files) lines.push(`  - ${f}`);
          lines.push("");
        }
      }
      return lines.join("\n").trimEnd();
    }
  • The core impact analysis function getImpactRadius(). Does BFS over the reverseFileIndex to find all files that depend on a given target file or symbol, up to a configurable depth.
    export async function getImpactRadius(
      cache: SymbolGraphCache,
      target: string,
      depth: number = 3,
    ): Promise<ImpactResult> {
      const safeDepth = Math.max(1, Math.min(depth, MAX_IMPACT_DEPTH));
      const reverseIndex = await cache.getReverseFileIndex();
    
      const targetKind: "file" | "symbol" = looksLikeFilePath(target)
        ? "file"
        : "symbol";
    
      // Resolve to one or more "seed" files
      let seedFiles: Set<string>;
      if (targetKind === "file") {
        seedFiles = new Set([target]);
      } else {
        seedFiles = new Set();
        const nameIndex = await cache.getNameIndex();
        const refs = nameIndex.get(target) ?? [];
        for (const r of refs) seedFiles.add(r.file);
      }
    
      const visited = new Set<string>();
      const filesByDepth = new Map<number, string[]>();
      let frontier = new Set(seedFiles);
      for (const f of seedFiles) visited.add(f);
    
      let truncated = false;
      for (let hop = 1; hop <= safeDepth; hop++) {
        const next = new Set<string>();
        for (const calleeFile of frontier) {
          const callers = reverseIndex.get(calleeFile);
          if (!callers) continue;
          for (const callerFile of callers) {
            if (visited.has(callerFile)) continue;
            next.add(callerFile);
            visited.add(callerFile);
          }
        }
        if (next.size === 0) break;
        filesByDepth.set(hop, Array.from(next).sort());
        frontier = next;
        // After reaching the depth limit, check if more callers exist beyond it.
        if (hop === safeDepth) {
          for (const calleeFile of frontier) {
            const callers = reverseIndex.get(calleeFile);
            if (!callers) continue;
            for (const callerFile of callers) {
              if (!visited.has(callerFile)) {
                truncated = true;
                break;
              }
            }
            if (truncated) break;
          }
        }
      }
    
      let totalFiles = 0;
      for (const arr of filesByDepth.values()) totalFiles += arr.length;
      return {
        target, targetKind, depth: safeDepth, filesByDepth, totalFiles,
        truncated,
      };
    }
  • src/index.ts:312-326 (registration)
    Tool registration on the MCP server using server.tool() with name 'codebase_impact', schema for projectPath/target/depth, and handler that delegates to handleGraphTool().
    // ── Impact analysis (symbol-level call graph) ───────────────────────────
    
    server.tool(
      "codebase_impact",
      "Impact Analysis — return the BLAST RADIUS for a file or symbol. Lists every file (and, where helpful, function) that could break if you change the target. Polymorphic on target: a path-like string ('src/foo.ts') triggers file-mode; a name-like string ('validateUser') triggers symbol-mode. Use this BEFORE refactoring, renaming, or deleting code to know what depends on it.",
      {
        projectPath: z.string().describe("Absolute path to the project directory.").optional(),
        target: z.string().describe("Target file path (relative) OR symbol name."),
        depth: z.number().describe("How many hops back to walk (default 3, max 10).").optional(),
      },
      async (args) => ({
        content: [{ type: "text", text: await handleGraphTool("codebase_impact", args) }],
      }),
    );
  • Import of getImpactRadius from the graph-impact service (note: the actual function signature is an async function with cache, target, depth params returning ImpactResult).
    import {
      type FlowNode,
      getCallFlow,
      getImpactRadius,
      getSymbolContext,
      listSymbols,
      looksLikeFilePath,
    } from "../services/graph-impact.js";
  • Constant MAX_IMPACT_DEPTH = 10, defining the maximum BFS depth for codebase_impact queries.
    /** Maximum BFS depth for `codebase_impact` (blast radius) queries. */
    export const MAX_IMPACT_DEPTH = 10;
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description fully explains the polymorphic behavior (file-mode vs symbol-mode) and the output (list of files and functions). It does not explicitly state read-only status, but the nature of 'impact analysis' strongly implies no side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three short, focused sentences. The first delivers the core purpose, the second specifies output, and the third explains polymorphism and usage. Every sentence adds value; no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description adequately describes the output as a list of files and functions. The depth parameter's effect is covered in the schema description. The tool's behavior is sufficiently explained for an AI agent to invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already describes all parameters, but the description adds meaningful context: the polymorphic nature of the 'target' parameter based on string format, and the default/max for 'depth'. This enriches understanding beyond schema descriptions alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool returns the 'BLAST RADIUS' for a file or symbol, listing dependent files/functions. It distinguishes between file-mode and symbol-mode based on target format, and the purpose is distinct from sibling tools like codebase_flow or codebase_context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly advises 'Use this BEFORE refactoring, renaming, or deleting code', providing clear context for when to employ the tool. While it doesn't name alternative tools, the usage guidance is specific and actionable.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/giancarloerra/SocratiCode'

If you have feedback or need assistance with the MCP directory API, please join our Discord server