Best for
- Developers who need to search codebases by syntax structure rather than plain text.
- AI-assisted workflows that create or debug ast-grep search rules.
This experimental developer-tools server provides four tools for AST inspection, rule testing, and structural code search. The README includes stdio configuration examples for Cursor and Claude Desktop and states that the server needs read access to target code directories.
Strongest · Documentation 13/20 Weakest · Security and permissions 8/20
Static review · not runReviewed 2026-11-29
Read the FMRS scoring method →Runtime:Python · Prebuilt binary
AST_GREP_CONFIG
Optional: set this to the path of a custom `sgconfig.yaml`; you can also specify the config with the `--config` command-line argument.
AST_GREP_PATH
Optional: set this to the ast-grep executable path or a command prefix; it defaults to `ast-grep` when unset.
Install ast-grep and uv, clone the repository, and run uv sync. Add the README's MCP configuration example to Cursor or Claude Desktop, replacing the directory with the repository's absolute local path. You can also run it directly from GitHub with uvx.
{"mcpServers":{"ast-grep":{"command":"uv","args":["--directory","/absolute/path/to/ast-grep-mcp","run","main.py"],"env":{}}}}
Shown for Cursor. Other clients may use a different file or key (VS Code uses "servers") — the configurator below converts it.
{
"servers": {
"ast-grep": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/ast-grep-mcp",
"run",
"main.py"
],
"env": {}
}
}
}
Goes in your project's .vscode/mcp.json (VS Code uses a "servers" key).
[mcp_servers.ast-grep] command = "uv" args = ["--directory", "/absolute/path/to/ast-grep-mcp", "run", "main.py"]
Append to ~/.codex/config.toml (OpenAI Codex CLI uses TOML).
claude mcp add ast-grep -- uv --directory /absolute/path/to/ast-grep-mcp run main.py
Run it in a terminal; replace any <…> placeholders with your own values first.
Check that `dump_syntax_tree`, `test_match_code_rule`, `find_code`, and `find_code_by_rule` appear in the client's MCP tool list. Call `dump_syntax_tree` on a code snippet and confirm that it returns a syntax tree.
Once connected, you can ask your AI assistant things like:
No matching tools
Listed from the project's documentation, not tested by this site.
ast-grep MCP Server is an experimental MCP server that gives AI assistants structural code search and analysis capabilities through ast-grep. It can inspect syntax trees, test YAML rules, and search codebases with simple patterns or advanced rules.
Connect code, docs, and infrastructure in a local knowledge graph.
Docker's official MCP gateway CLI plugin for managing and running MCP servers.
Fast, low-cost structured judgments for agents.
Local call graphs and structural analysis for Go repositories.
Source revision 51d5a23f025c Data synced 2026-12-05 Read the FMRS scoring method Markdown