Skip to main content
Glama
ast-grep

ast-grep MCP Server

by ast-grep

find_code

Search code in a project folder using AST patterns to locate specific code structures across multiple programming languages.

Instructions

Find code in a project folder that matches the given ast-grep pattern. Pattern is good for simple and single-AST node result. For more complex usage, please use YAML by find_code_by_rule.

Internally calls: ast-grep run --pattern [--json] <project_folder>

Output formats:

  • text (default): Compact text format with file:line-range headers and complete match text Example: Found 2 matches:

    path/to/file.py:10-15 def example_function(): # function body return result

    path/to/file.py:20-22 def another_function(): pass

  • json: Full match objects with metadata including ranges, meta-variables, etc.

The max_results parameter limits the number of complete matches returned (not individual lines). When limited, the header shows "Found X matches (showing first Y of Z)".

Example usage: find_code(pattern="class $NAME", max_results=20) # Returns text format find_code(pattern="class $NAME", output_format="json") # Returns JSON with metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_folderYesThe absolute path to the project folder. It must be absolute path.
patternYesThe ast-grep pattern to search for. Note, the pattern must have valid AST structure.
languageNoThe language of the code. Supported: bash, c, cpp, csharp, css, elixir, go, haskell, html, java, javascript, json, jsx, kotlin, lua, nix, php, python, ruby, rust, scala, solidity, swift, tsx, typescript, yaml. If not specified, will be auto-detected based on file extensions.
max_resultsNoMaximum results to return
output_formatNo'text' or 'json'text

Tool Definition Quality

Score is being calculated. Check back soon.

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/ast-grep/ast-grep-mcp'

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