# ast-grep MCP Server

> Search and analyze code by AST structure.

- **URL**: https://followmcp.com/en/servers/ast-grep-mcp
- **Category**: Dev Tools
- **Origin**: Community
- **Stars**: 504
- **FMRS Score**: 50/100 (Grade D)
- **Source**: https://github.com/ast-grep/ast-grep-mcp
- **Transports**: stdio (local process)
- **Runtimes**: Python, Prebuilt binary
- **Auth**: No credential needed

## 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.

## 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
- 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.

## Client config (JSON)
```json
{"mcpServers":{"ast-grep":{"command":"uv","args":["--directory","/absolute/path/to/ast-grep-mcp","run","main.py"],"env":{}}}}
```

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