Server facts
ast-grep-mcp
GitHub stars
503
Last commit
Dec 3, 2026
Runtime
python
License
MIT
Project
- Author
- ast-grep
- Repository
- github.com/ast-grep/ast-grep-mcp
- License
- MIT
- Category
- Search & Web Data
Tech
- Runtime
- python
- Transports
- stdio
- Remote access
- No
- Authentication
- None (local codebase read access)
Activity
- GitHub stars
- 503
- Last commit
- Data as of
Tags
- Code Search
- ast grep
- mcp
Overview
Codebase search breaks down when plain regex hits comments, strings, or nested syntax—`ast-grep/ast-grep-mcp` (MIT license) solves `ast grep mcp` queries by wrapping the official `ast-grep` binary in a lightweight Python `stdio` server using the MCP Python SDK. Install the `ast-grep` CLI (via Homebrew, Nix, or Cargo) plus `uv`, then either test straight from GitHub by invoking the `ast-grep-server` entrypoint via `uvx` without cloning, or check out the repo locally (`uv sync`) and configure Cursor (`.cursor-mcp/settings.json`) or Claude Desktop to launch `main.py` inside the project folder with `uv`. No API keys are needed; custom binary paths or wrappers (like `npx ast-grep` or `uv run ast-grep`) plug in via `AST_GREP_PATH`, while custom `sgconfig.yaml` files and custom language grammars load via `--config` or `AST_GREP_CONFIG`.
Instead of sprawling tool catalogs, it focuses tightly on 4 composable tools: `dump_syntax_tree` inspects AST node kinds to debug non-matching patterns, `test_match_code_rule` validates multi-condition YAML rules against snippets before scanning huge repos, `find_code` runs direct pattern queries, and `find_code_by_rule` executes relational YAML constraints (`inside`, `has`, `precedes`, `follows`). Both search tools support `max_results` and default to compact `"text"` output (saving roughly 75% fewer tokens than full `"json"` metadata), complemented by an `ast-grep.mdc` rule guide ready to drop into Cursor rules or `CLAUDE.md`.
Install & configure
Requirements
- `ast-grep` CLI installed (`brew install ast-grep`, `nix-shell -p ast-grep`, or `cargo install ast-grep --locked`), or custom command configured via `AST_GREP_PATH`
- `uv` Python package manager (`uvx --from git+https://github.com/ast-grep/ast-grep-mcp ast-grep-server`, or local clone + `uv sync`)
- Read permissions on target codebase directories (and optional `sgconfig.yaml` via `--config` or `AST_GREP_CONFIG`)
uvx --from git+https://github.com/ast-grep/ast-grep-mcp ast-grep-serverAdd `ast-grep` under `mcpServers` in Cursor or Claude Desktop calling `uv --directory /absolute/path/to/ast-grep-mcp run main.py` (or try without cloning using `uvx --from git+https://github.com/ast-grep/ast-grep-mcp ast-grep-server`). Set `AST_GREP_PATH` if `ast-grep` is not in `PATH`, and optionally attach `ast-grep.mdc` to Cursor rules or `CLAUDE.md`.
Examples are translated from the published configuration. Supply your own credentials and verify requirements in the upstream README. Remote connectors are shown only where a supported configuration format is known.
Config file · macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Use Settings → Developer → Edit Config when available. Do not assume a Linux configuration path; check the client documentation for your platform. Remote servers use the app’s connector flow when supported, not the local stdio file shown here. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"ast-grep": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/ast-grep-mcp",
"run",
"main.py"
],
"env": {}
}
}
}Config file · Project: .cursor/mcp.json
User: ~/.cursor/mcp.json
The project path is relative to the workspace root. The tilde denotes your user home directory. Use Cursor’s MCP settings to confirm which configuration and scope your installed version is reading. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"ast-grep": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/ast-grep-mcp",
"run",
"main.py"
],
"env": {}
}
}
}Config file · Workspace: .vscode/mcp.json
For user scope, use the “MCP: Open User Configuration” command if available. Do not guess a user configuration path across operating systems, profiles, containers, or remote workspaces; check the client documentation. Merge this example with existing settings; do not overwrite unrelated servers.
{
"servers": {
"ast-grep": {
"type": "stdio",
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/ast-grep-mcp",
"run",
"main.py"
],
"env": {}
}
}
}Config file · macOS/Linux: ~/.codeium/windsurf/mcp_config.json
Windows: %USERPROFILE%\.codeium\windsurf\mcp_config.json
Open the MCP configuration through Windsurf’s settings when possible to confirm the active file. Paths can differ in managed or future releases; check the client documentation if this location is not present. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"ast-grep": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/ast-grep-mcp",
"run",
"main.py"
],
"env": {}
}
}
}Config file · Project scope: .mcp.json at the repository root
The project file uses mcpServers. For user scope, use claude mcp add --scope user rather than assuming .mcp.json in your home directory is the user configuration. Check the client documentation for managed settings and storage details. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"ast-grep": {
"type": "stdio",
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/ast-grep-mcp",
"run",
"main.py"
],
"env": {}
}
}
}Examples are translated from the published configuration. Supply your own credentials and verify requirements in the upstream README. Remote connectors are shown only where a supported configuration format is known.
Tools
Source: repository README. Tool descriptions are a documented snapshot, not a live capability check.
| Tool | What it does |
|---|---|
| dump_syntax_tree | Visualize the Abstract Syntax Tree of a code snippet to inspect node kinds and debug why a search pattern missed. |
| test_match_code_rule | Validate an ast-grep YAML matching rule against small code snippets before running it across a full repository. |
| find_code | Search codebases with direct ast-grep structural patterns, supporting max_results and text (default, ~75% fewer tokens) or json output_format. |
| find_code_by_rule | Run advanced multi-condition YAML ast-grep rules with relational constraints (inside, has, precedes, follows), max_results, and text or json output. |
Use cases
- Locate complex language patterns—such as async functions containing `await` or specific API calls—without false positives from comments or strings.
- Inspect unfamiliar AST node shapes with `dump_syntax_tree` and verify YAML rules via `test_match_code_rule` before scanning a monorepo.
- Save prompt tokens during large-repo audits by pairing `find_code` / `find_code_by_rule` default `text` output (~75% fewer tokens) with `max_results` caps.
- Query domain-specific or custom languages configured through a project's `sgconfig.yaml` via `--config` or `AST_GREP_CONFIG`.
Strengths
- Maintained directly under the official `ast-grep` GitHub organization with MIT licensing and clean `uvx` or local `uv` setup.
- Compact 4-tool surface (`dump_syntax_tree`, `test_match_code_rule`, `find_code`, `find_code_by_rule`) plus bundled `ast-grep.mdc` authoring guidance.
- Default `text` output reduces token usage by roughly 75% compared with full JSON metadata while still supporting `json` when needed.
- Flexible deployment overrides via `AST_GREP_PATH` (custom binary, `npx ast-grep`, `uv run ast-grep`) and `sgconfig.yaml` custom languages.
Limitations
- Marked as an experimental project focused on read-only structural search and rule testing rather than automated AST code rewriting/codemods.
- Requires installing the `ast-grep` executable separately (or wiring `AST_GREP_PATH`) in addition to Python `uv`.
- Relational YAML rules (`has`, `inside`) can unexpectedly return empty matches unless `stopBy: end` is explicitly specified.
ast-grep-mcp setup notes
- ast-grep-mcp's stdio example needs a client that launches local processes.