Labsco
MCP SERVER

ast-grep MCP

by ast-grep

Search a codebase by syntax structure instead of by text, and test the rule before running it everywhere.

Code Intelligence & Repository Indexing
Summary
The debugging tools are the point: you can see the AST and test the rule before the search.

Structural search fails silently when the pattern does not match the tree, and that is where most of the time goes. dump_syntax_tree and test_match_code_rule turn that into a two-step loop, and the repository ships ast-grep.mdc — rule documentation you can attach to your assistant so it writes the YAML for you.

What it is

An MCP server over ast-grep, giving structural search across a codebase through AST pattern matching rather than regular expressions.

What you get
  • find_code — search with a simple ast-grep pattern, with max_results and output_format
  • find_code_by_rule — search with a full YAML rule, for relational constraints like inside, has, precedes and follows
  • test_match_code_rule — run a rule against a snippet before turning it loose on the repository
  • dump_syntax_tree — see the AST of a snippet, which is how you work out why a pattern is not matching
  • Text output by default, which the project reports as roughly 75% fewer tokens than the JSON form; JSON is available when you want the full metadata
  • Whatever languages ast-grep supports, plus custom ones added through sgconfig.yaml
Requirements

Ast-grep installed and on your PATH — via Homebrew, nix or cargo — and uv. Run it from GitHub with uvx, or clone and point the client at main.py. If ast-grep is not on PATH, set AST_GREP_PATH to the executable or a command prefix; a custom config goes in AST_GREP_CONFIG or the --config argument.

Setup effort

One command — uvx --from git+https://github.com/ast-grep/ast-grep-mcp ast-grep-server