Skip to main content
MCP server CX Codex

ast-grep — Claude Code MCP server: what it does, how to install

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.

no license updated 2026-10-29

Open on GitHub

What ast-grep 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.

What it helps with

  • 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 for the agent

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

How to install ast-grep

Install

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

Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more

Questions about ast-grep

What does the ast-grep MCP server do?

It enables language models to run AST-based code matching, rule-based linting, and syntax-level code rewriting.

How do you invoke ast-grep with Docker MCP?

Run docker mcp tools call ast-grep args=run args="--pattern" args='const $NAME = $VAL' args="--json" args=".".

What language powers the underlying ast-grep tool?

The core ast-grep command-line utility is built with Rust.

Similar MCP servers

All MCP servers for Code review and refactoring →

Project sponsors

Companies that keep this analytics open