# ast-grep

The ast-grep MCP server for Claude Code provides syntax-aware code search, linting, and expression rewrites through abstract syntax trees. It is used for precise codebase refactoring.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI
- Author: dgageot
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/dgageot/mcp-ast-grep
- Updated: 2026-10-29
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/mcp/ast-grep

## What it does

This server connects coding assistants to `ast-grep`, a Rust-based command-line tool. Instead of standard text matching, it evaluates code grammar through abstract syntax trees. This approach avoids false hits in strings or comments while matching target constructs.

The tool handles pattern-driven searches, rule checks, and AST modifications. Queries accept arguments such as `const $NAME = $VAL` and output data as JSON. Running this MCP component requires Docker.

## Requirements
- Needs: Docker

## Install

### Claude Code (native platform)

**Install**
- The MCP registry has no launch command for it: see the repository README

## When to use it
- locate code patterns through syntax-aware tree matching
- rewrite code fragments based on abstract syntax trees
- run structural linter checks across project files
- export structural match outputs as structured JSON

## Example prompts
- Search for variable declarations matching `const $NAME = $VAL` via ast-grep
- Run a structural code search across the project root with JSON output

## Similar
- [ast-grep-find](https://affpapa.org/en/nevibecode/skills/ast-grep-find.md) — skill · 524 installs
- [ast-grep-outline](https://affpapa.org/en/nevibecode/skills/ast-grep-outline.md) — skill · 2800 installs
- [codegraph-ast-grep](https://affpapa.org/en/nevibecode/skills/codegraph-ast-grep.md) — skill · 2800 installs
- [codemod](https://affpapa.org/en/nevibecode/skills/codemod.md) — skill · 341 installs
- [explain](https://affpapa.org/en/nevibecode/commands/indx-explain.md) — command · ★ 113 repo stars
- [tldr-deep](https://affpapa.org/en/nevibecode/skills/tldr-deep.md) — skill · 485 installs

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
