Skip to main content
Glama

what_breaks

Analyze code impact by identifying references to a specific symbol using structural search. Shows what might break when modifying functions or classes in Python, JavaScript, TypeScript, or Go projects.

Instructions

💥 STEP 3: See what code might break if you change this symbol.

USE THIS AFTER find_symbol() to understand the impact of changing a function/class.

IMPROVEMENTS:

  • Uses structural search (ast-grep) to find ACTUAL code references (ignoring comments/strings).

  • Returns 2 lines of context around each match.

INPUT:

  • exact_symbol: Pass THE ENTIRE SYMBOL OBJECT from find_symbol(), not just the name! Must be a dictionary with AT LEAST 'name' and 'path' keys.

EXAMPLE INPUT:

First, get a symbol from find_symbol():

symbols = find_symbol("/Users/john/project", "authenticate") symbol = symbols[0] # Pick the first result

Then pass THE WHOLE SYMBOL OBJECT:

what_breaks(symbol)

EXAMPLE OUTPUT: { "references": [ { "file": "/Users/john/project/src/api.py", "line": 23, "text": " # Authenticate the user user = authenticate_user(username, password) if not user:", "type": "code" } ], "total_count": 1, "strategy": "structural", "note": "Found 1 references using structural search." }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exact_symbolYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler and registration for 'what_breaks'. Extracts repository root, gets indexer, calls core what_breaks method.
    @mcp.tool  
    def what_breaks(exact_symbol: Dict[str, Any]) -> Dict[str, Any]:
        """
        💥 STEP 3: See what code might break if you change this symbol.
        
        USE THIS AFTER find_symbol() to understand the impact of changing a function/class.
        
        IMPROVEMENTS:
        - Uses structural search (ast-grep) to find ACTUAL code references (ignoring comments/strings).
        - Returns 2 lines of context around each match.
        
        INPUT:
        - exact_symbol: Pass THE ENTIRE SYMBOL OBJECT from find_symbol(), not just the name!
                       Must be a dictionary with AT LEAST 'name' and 'path' keys.
        
        EXAMPLE INPUT:
        # First, get a symbol from find_symbol():
        symbols = find_symbol("/Users/john/project", "authenticate")
        symbol = symbols[0]  # Pick the first result
        
        # Then pass THE WHOLE SYMBOL OBJECT:
        what_breaks(symbol)
        
        EXAMPLE OUTPUT:
        {
            "references": [
                {
                    "file": "/Users/john/project/src/api.py",
                    "line": 23,
                    "text": "    # Authenticate the user\n    user = authenticate_user(username, password)\n    if not user:",
                    "type": "code"
                }
            ],
            "total_count": 1,
            "strategy": "structural",
            "note": "Found 1 references using structural search."
        }
        """
        try:
            # Extract root path from the symbol's path
            symbol_path = Path(exact_symbol['path'])
            root_path = str(symbol_path.parent)
            
            # Find a suitable root (go up until we find a git repo or reach root)
            while root_path != '/':
                if (Path(root_path) / '.git').exists():
                    break
                parent = Path(root_path).parent
                if parent == Path(root_path):
                    break
                root_path = str(parent)
            
            indexer = get_indexer(root_path)
            return indexer.what_breaks(exact_symbol)
        except Exception as e:
            return {"error": f"Error finding references: {str(e)}"}
  • Core logic of what_breaks: structural search with ast-grep (prioritized), fallback to text search (ripgrep/python), filters definition file/line, returns references with context.
    def what_breaks(self, exact_symbol: Dict[str, Any], context_lines: int = 2) -> Dict[str, Any]:
        """
        Find what uses a symbol (reverse dependencies) using structural search.
        Prioritizes ast-grep for code references, falls back to text search.
        """
        symbol_name = exact_symbol['name']
        definition_path = str(Path(exact_symbol['path']).resolve())
        definition_start = exact_symbol.get('start_line', -1)
        
        references = []
        strategy = "structural"
        
        # Try structural search first (ast-grep)
        struct_refs = self._ast_grep_search(symbol_name, context_lines)
        
        if struct_refs:
            # Filter out the definition itself
            for ref in struct_refs:
                ref_path = str(Path(ref['file']).resolve())
                ref_line = ref['line']
                
                # Simple collision check: same file and line is close to definition
                # (ast-grep definition match might be on definition line)
                if ref_path == definition_path and abs(ref_line - definition_start) <= 1:
                    continue
                    
                references.append(ref)
        else:
            # Fallback to text search if ast-grep found nothing (or failed)
            # Note: This might happen if the symbol is not in a supported language file
            # or if it's only used in comments/strings (which we might want to know about as fallback?)
            # For now, if structural search returns empty list, we trust it for code.
            # But we might want to run text search as a backup for non-code files?
            # Let's stick to the previous behavior's fallback logic: if ast-grep *fails to run*, we use grep.
            # If ast-grep runs and finds nothing, we return nothing (for code).
            # BUT, to be safe and "improve" without breaking, let's run text search 
            # if structural search is empty, but mark them as "text matches".
            
            # Actually, let's just use the text search if structural returned nothing.
            strategy = "text"
            references = self._text_search(symbol_name, context_lines)
    
        return {
            "references": references,
            "total_count": len(references),
            "strategy": strategy,
            "note": f"Found {len(references)} references using {strategy} search."
        }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it performs structural search using ast-grep, ignores comments and strings, returns 2 lines of context around each match, and outputs a structured result with references and metadata. However, it doesn't mention potential limitations like performance or error handling.

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

Conciseness4/5

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

The description is well-structured with clear sections (purpose, usage, improvements, input, examples), but it includes an extensive example input and output that could be condensed. Most sentences earn their place by providing essential information, though the examples are detailed and might be overly verbose for a concise description.

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

Completeness5/5

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

Given the tool's complexity (structural code analysis), no annotations, and an output schema that covers return values, the description is complete enough. It explains the tool's purpose, usage context, behavioral traits, parameter requirements, and provides illustrative examples, compensating well for the lack of structured metadata.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate. It adds significant meaning beyond the schema by explaining that 'exact_symbol' must be 'THE ENTIRE SYMBOL OBJECT from find_symbol(), not just the name!' and specifying it 'Must be a dictionary with AT LEAST 'name' and 'path' keys.' This clarifies the parameter's purpose and constraints that aren't in the schema.

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's purpose: 'See what code might break if you change this symbol.' It specifies the verb ('see what code might break') and resource ('this symbol'), and distinguishes it from sibling tools by explicitly mentioning it should be used 'AFTER find_symbol()' and contrasting with 'structural search' versus other approaches.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool: 'USE THIS AFTER find_symbol() to understand the impact of changing a function/class.' It also specifies an alternative approach by noting it 'Uses structural search (ast-grep) to find ACTUAL code references (ignoring comments/strings),' implying a distinction from other search methods.

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/srijanshukla18/xray'

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