find_usage
Locate symbol usage across a codebase by providing project name, symbol, and optional file or language filters. Returns detailed usage locations for efficient code analysis.
Instructions
Find usage of a symbol.
Args:
project: Project name
symbol: Symbol name to find
file_path: Optional file to look in (for local symbols)
language: Language to search in
Returns:
List of usage locations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | No | ||
| language | No | ||
| project | Yes | ||
| symbol | Yes |
Implementation Reference
- The main handler function for the 'find_usage' MCP tool. It is decorated with @mcp_server.tool() for registration and implements the tool logic by constructing a Tree-sitter query to find identifier usages matching the given symbol and executing it via query_code.@mcp_server.tool() def find_usage( project: str, symbol: str, file_path: Optional[str] = None, language: Optional[str] = None, ) -> List[Dict[str, Any]]: """Find usage of a symbol. Args: project: Project name symbol: Symbol name to find file_path: Optional file to look in (for local symbols) language: Language to search in Returns: List of usage locations """ # Detect language if not provided but file_path is if not language and file_path: language = language_registry.language_for_file(file_path) if not language: raise ValueError("Either language or file_path must be provided") # Build a query to find references to the symbol query = f""" ( (identifier) @reference (#eq? @reference "{symbol}") ) """ from ..tools.search import query_code return query_code( project_registry.get_project(project), query, language_registry, tree_cache, file_path, language )