← Back to directory
A

ast-grep MCP Server

Community
Search and analyze code by AST structure.
Category
Dev Tools #409 of 751
Stars
★ 504 Very popular
Transport
stdio (local process)
Runtime
Python · Prebuilt binary
Credentials
No credential needed
License
MIT
Last commit
Tools
4
50FMRS · D

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

Reliability
9/20
Security and permissions
8/20
Maintenance
8/20
Documentation
13/20
Setup experience
12/20
Why each score
Reliability 9/20
The README names four tools and describes their purposes, some parameters, and examples, giving the happy path some support. It provides no server manifest, CI, tests, or verifiable startup and handshake evidence; error handling and edge behavior are also unclear, so points are deducted.
Security and permissions 8/20
The documented purpose is code search and AST inspection, with no evidence of credential collection, data exfiltration, or destructive actions. However, the server is expected to read target directories, and AST_GREP_PATH can be set to a command prefix; permission scope and command invocation boundaries are not explained. Without the manifest or implementation, actual data flows and least privilege cannot be confirmed, so points are deducted. No evidence triggers a red line.
Maintenance 8/20
The repository is identified as MIT licensed and not archived, but the provided material contains no commit history, releases, dependency updates, security response channel, or maintainer response record. Star and open issue counts do not establish sustained maintenance, so points are deducted.
Documentation 13/20
The README covers prerequisites, client configuration, tool purposes, parameters, examples, language support, and common troubleshooting, making it useful for getting started. It does not explain tool permissions, data flows, limits, or complete error diagnosis; the missing manifest also prevents checking its claims against the actual tools, so the score is limited.
Setup experience 12/20
The README gives preparation steps for ast-grep and uv, a uvx launch example, and configuration examples for Cursor and Claude Desktop. The path is reasonably clear, but it depends on two external tools, uses a local absolute path in client configuration, and provides no platform coverage, automated setup, or verifiable execution evidence, so points are deducted.

Static review · not runReviewed 2026-11-29

Read the FMRS scoring method →

Fit and risk

What it can accessReads local filesRuns commands or code

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.

Not for

  • Workflows that only need ordinary text search.
  • Environments without ast-grep, uv, or an MCP-compatible client.

Required permissions

  • The server needs read access to the target code directories.
  • When using custom ast-grep configuration, it needs access to the specified configuration file.

Risks and side effects

  • The project is described as experimental, so behavior or support may change.
  • Search results depend on ast-grep patterns, rules, and configuration; a missing match does not necessarily mean the target construct is absent.
  • Contents of code directories granted to the server may appear in tool results.

Setup

Before you start

Runtime:Python · Prebuilt binary

Other optional settings (2)
AST_GREP_CONFIG optional 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 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.

.cursor/mcp.json
{"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.

.vscode/mcp.json
{
  "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).

~/.codex/config.toml
[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).

Terminal
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 it works

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.

Troubleshooting

  1. For command-not-found errors, check that ast-grep is installed and on PATH, or verify AST_GREP_PATH.
  2. For no matches, inspect the rule and relational constraints; the README suggests adding stopBy: end to relational rules when needed.
  3. For patterns that do not match, use dump_syntax_tree to inspect the target code's AST structure.
  4. For permission errors, confirm the server can read the target directories.

Things to try

Once connected, you can ask your AI assistant things like:

  • Show me the syntax tree for this code snippet.
  • Find all console.log calls in the codebase using ast-grep patterns.
  • Test a YAML rule that finds async functions containing await.

Tools 4

dump_syntax_tree read-only
Displays the abstract syntax tree for a code snippet to help understand match structure and debug patterns.
test_match_code_rule read-only
Tests ast-grep YAML rules against code snippets.
find_code read-only
Searches a codebase for structural matches using simple ast-grep patterns.
find_code_by_rule read-only
Searches a codebase with advanced YAML rules that can express relational constraints and multiple conditions.

Use cases

Find specific function calls, variable declarations, or other code constructs.
Inspect syntax trees to understand the structure of target code.
Test and refine complex ast-grep YAML search rules.

Supported clients

Cursor
Claude Desktop

Listed from the project's documentation, not tested by this site.

Overview

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.

Similar servers

Source revision 51d5a23f025c Data synced 2026-12-05 Read the FMRS scoring method Markdown

Maintainer badge: embed FMRS score

Paste this Markdown into your repository README to display a live score badge:

README.md
[![FollowMCP](https://followmcp.com/badges/ast-grep-mcp.svg)](https://followmcp.com/en/servers/ast-grep-mcp)