grep_ast
Search and analyze source code using AST context to reveal structural relationships, such as functions or classes containing matching patterns. Ideal for understanding code organization and exploring unfamiliar codebases.
Instructions
Search through source code files and see matching lines with useful AST (Abstract Syntax Tree) context. This tool helps you understand code structure by showing how matched lines fit into functions, classes, and other code blocks.
Unlike traditional search tools like search_content
that only show matching lines, grep_ast
leverages the AST to reveal the structural context around matches, making it easier to understand the code organization.
When to use this tool:
When you need to understand where a pattern appears within larger code structures
When searching for function or class definitions that match a pattern
When you want to see not just the matching line but its surrounding context in the code
When exploring unfamiliar codebases and need structural context
When examining how a specific pattern is used across different parts of the codebase
This tool is superior to regular grep/search_content when you need to understand code structure, not just find text matches.
Example usage:
Input Schema
Name | Required | Description | Default |
---|---|---|---|
ignore_case | No | Whether to ignore case when matching | |
line_number | No | Whether to display line numbers | |
path | Yes | The path to search in (file or directory) | |
pattern | Yes | The regex pattern to search for in source code files |