Skip to main content
Glama

get_blast_radius

Analyze code dependencies by tracing where a specific symbol is imported or used across files. Helps prevent orphaned code and identifies candidates for inlining before making changes.

Instructions

Before deleting or modifying code, check the BLAST RADIUS. Traces every file and line where a specific symbol (function, class, variable) is imported or used. Prevents orphaned code. Also warns if usage count is low (candidate for inlining).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbol_nameYesThe function, class, or variable name to trace across the codebase.
file_contextNoThe file where the symbol is defined. Excludes the definition line from results.

Implementation Reference

  • The main implementation of the getBlastRadius function.
    export async function getBlastRadius(options: BlastRadiusOptions): Promise<string> {
      const entries = await walkDirectory({ rootDir: options.rootDir, depthLimit: 0 });
      const files = entries.filter((e) => !e.isDirectory && isSupportedFile(e.path));
      const usages: SymbolUsage[] = [];
      const symbolPattern = new RegExp(`\\b${escapeRegex(options.symbolName)}\\b`, "g");
    
      for (const file of files) {
        try {
          const content = await readFile(file.path, "utf-8");
          const lines = content.split("\n");
    
          for (let i = 0; i < lines.length; i++) {
            if (symbolPattern.test(lines[i])) {
              const isDefinition = options.fileContext && file.relativePath === options.fileContext && isDefinitionLine(lines[i], options.symbolName);
              if (!isDefinition) {
                usages.push({
                  file: file.relativePath,
                  line: i + 1,
                  context: lines[i].trim().substring(0, 120),
                });
              }
              symbolPattern.lastIndex = 0;
            }
          }
        } catch {
        }
      }
    
      if (usages.length === 0) return `Symbol "${options.symbolName}" is not used anywhere in the codebase.`;
    
      const byFile = new Map<string, SymbolUsage[]>();
      for (const u of usages) {
        const existing = byFile.get(u.file) ?? [];
        existing.push(u);
        byFile.set(u.file, existing);
      }
    
      const lines: string[] = [
        `Blast radius for "${options.symbolName}": ${usages.length} usages in ${byFile.size} files\n`,
      ];
    
      for (const [file, fileUsages] of byFile) {
        lines.push(`  ${file}:`);
        for (const u of fileUsages) {
          lines.push(`    L${u.line}: ${u.context}`);
        }
      }
    
      if (usages.length <= 1) {
        lines.push(`\n⚠ LOW USAGE: This symbol is used only ${usages.length} time(s). Consider inlining if it's under 20 lines.`);
      }
    
      return lines.join("\n");
    }
  • The interface defining the input parameters for the getBlastRadius tool.
    export interface BlastRadiusOptions {
      rootDir: string;
      symbolName: string;
      fileContext?: string;
    }
  • src/index.ts:281-291 (registration)
    The tool registration and invocation logic in the main MCP handler.
    "get_blast_radius",
    "Before deleting or modifying code, check the BLAST RADIUS. Traces every file and line where a specific symbol " +
    "(function, class, variable) is imported or used. Prevents orphaned code. Also warns if usage count is low (candidate for inlining).",
    {
      symbol_name: z.string().describe("The function, class, or variable name to trace across the codebase."),
      file_context: z.string().optional().describe("The file where the symbol is defined. Excludes the definition line from results."),
    },
    withRequestActivity(async ({ symbol_name, file_context }) => ({
      content: [{
        type: "text" as const,
        text: await getBlastRadius({ rootDir: ROOT_DIR, symbolName: symbol_name, fileContext: file_context }),

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/ForLoopCodes/contextplus'

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