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
| Name | Required | Description | Default |
|---|---|---|---|
| symbol_name | Yes | The function, class, or variable name to trace across the codebase. | |
| file_context | No | The file where the symbol is defined. Excludes the definition line from results. |
Implementation Reference
- src/tools/blast-radius.ts:20-73 (handler)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"); } - src/tools/blast-radius.ts:8-12 (schema)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 }),