ast-grep MCP Server
MCP server that lets AI assistants search and analyze codebases with ast-grep structural AST pattern matching.
Tested on Linux
Use it
Linux x86_64
You need first
- Runtimes:
uv - System packages:
ast-grep
uv tool install the MCP server from git, plus ast-grep-cli for the ast-grep binary
uv tool install git+https://github.com/ast-grep/ast-grep-mcp && uv tool install ast-grep-cli
Check that it works
ast-grep --versionThe output should contain “ast-grep 0.51.2”.
Add it to your agent
claude mcp add ast-grep-mcp -- ast-grep-serverJSON for Claude Desktop, Cursor and other clients
{
"mcpServers": {
"ast-grep-mcp": {
"command": "ast-grep-server",
"args": []
}
}
}Add ast-grep-server as a server command in your MCP client, then ask your assistant to use its tools such as find_code.
What it does
- Search code by its syntax structureTested
How to use it
- Ask your assistant to call the
find_codetool with your project folder, a pattern such asconsole.log($$$), and the language. - Read the list of matching code locations it returns.
- Ask your assistant to call the
- Write and test YAML search rulesTested
How to use it
- Write a YAML rule with an
id,language, andrule: pattern: <your pattern>. - Ask your assistant to call the
test_match_code_ruletool with the rule and a sample of <your code>. - Check the returned matches to confirm the rule works.
- Write a YAML rule with an
- View the syntax tree of a code snippetTested
How to use it
- Ask your assistant to call the
dump_syntax_treetool with <your code> and its language. - Read the printed tree to see how the code is structured, for example to fix a pattern that does not match.
- Ask your assistant to call the
How far pickfit got
Linux x86_64
- Installs
- Connects
- 3 of 3 features work
- Works offline
Good for
- find all console.log statements in a JavaScript codebase
- find async functions that use await
- debug why an ast-grep pattern isn't matching
How pickfit tested it
Each run starts from a clean machine and follows the steps above. How pickfit verifies
Linux x86_64
An MCP client called one of its tools
- Replayed from scratch
- Works offline
- Checked on 15 Nov 2026
An MCP client handshake over stdio listed 4 tools, and a call to find_code returned a result.
Differences the test machine hit
- README: Install ast-grep via brew, nix-shell or cargo
In the test: `uv tool install ast-grep-cli` (published PyPI package) put ast-grep on PATH without root or a Rust toolchain - README: uv sync in a clone / uvx --from git+... ast-grep-server
In the test: `uv tool install git+https://github.com/ast-grep/ast-grep-mcp` installs the ast-grep-server command on PATH so the server can start with the network off - README: Complex rule example (async-with-await) for test_match_code_rule
In the test: Run against `async function load() { const x = await fetch(1); }`, the README's async-with-await rule made test_match_code_rule return an error (the probe showed no message), possibly because the rule matched nothing. The README's simpler console.log rule worked.