Ast Grep Mcp
FreeMaintainedMCP stdio server exposing ast-grep structural search and safe rewrites to agents
About
MCP stdio server exposing ast-grep structural search and safe rewrites to agents
README
ast-grep-mcp is a local stdio Model Context Protocol server that gives agents access to the real ast-grep CLI for structural search, scan, rule testing, and explicitly gated rewrites.
It is designed for agentic coding workflows where text search is not enough and filesystem safety matters.
Features
- Structural search with
ast-grep runand JSON results. - Project scans with
ast-grep scanusing config files, rule files, inline rules, or filters. - Rule test execution with
ast-grep test. - Version and binary resolution diagnostics.
- Rewrite preview by default, with mutation gated behind an explicit
apply: trueinput. - Workspace-relative path validation that rejects absolute paths,
..escapes, and symlinks that resolve outside the workspace. - No network listener: stdio transport only.
Requirements
- Node.js 20 or newer.
- An MCP client that can launch stdio servers.
The package depends on @ast-grep/cli, which installs the matching platform binary during package installation. You can still override binary resolution with AST_GREP_BIN when needed.
Installation
Use it directly from npm in your MCP client configuration:
{
"mcpServers": {
"ast-grep": {
"command": "npx",
"args": ["-y", "ast-grep-mcp"],
"cwd": "/path/to/workspace"
}
}
}
Or install it globally:
npm install -g ast-grep-mcp
{
"mcpServers": {
"ast-grep": {
"command": "ast-grep-mcp",
"cwd": "/path/to/workspace"
}
}
}
Set cwd to the workspace the agent should inspect. Tool paths are resolved relative to that workspace.
Tools
| Tool | Purpose |
|---|---|
ast_grep_search |
Runs ast-grep run with structural patterns, optional rewrites, and JSON output. |
ast_grep_scan |
Runs ast-grep scan with config, rule files, inline rules, filters, and JSON output. |
ast_grep_test |
Runs ast-grep test for rule suites. |
ast_grep_version |
Reports the resolved ast-grep binary path, source, and version. |
Rewrite Safety
Rewrite-capable requests require an explicit apply value:
{
"pattern": "$A && $A()",
"rewrite": "$A?.()",
"apply": false,
"lang": "ts",
"paths": ["src"]
}
apply: falsepreviews replacements and does not pass--update-all.apply: truepasses--update-alland applies all replacements or scan rule fixes.rewriterequiresapply, so callers must explicitly choose preview or mutation.apply: truewithout a rewrite or fix-capable scan request is rejected.
For ast_grep_scan, fixes must be defined in ast-grep rules or config. scan does not accept an ad-hoc rewrite string.
Binary Resolution
The server resolves ast-grep in this order:
AST_GREP_BINast-greponPATHsgonPATH, only whensg --versionidentifies ast-grep- The bundled
@ast-grep/clidependency
Use ast_grep_version to confirm which binary the server selected.
Safety Model
- stdio only; no HTTP server or socket listener.
- All file inputs are workspace-relative.
- Absolute paths and
..escapes are rejected. - Existing symlink components that resolve outside the workspace are rejected.
- Commands use
spawnargv arrays withshell: false. - Interactive ast-grep mode is not exposed.
- Tool calls use timeouts and bounded stdout/stderr buffers.
- Results are returned as JSON text plus MCP
structuredContent.
Local Development
pnpm install
pnpm run verify
Useful scripts:
| Script | Description |
|---|---|
pnpm run dev |
Start the MCP server from TypeScript source. |
pnpm run build |
Clean and build declarations plus the bundled CLI entrypoint. |
pnpm run test |
Run the Vitest suite. |
pnpm run typecheck |
Run TypeScript type checking. |
pnpm run format:check |
Check formatting with oxfmt. |
pnpm run lint |
Lint with oxlint. |
pnpm run verify |
Run format, lint, typecheck, tests, and build. |
pnpm run pack:dry-run |
Build and inspect the npm package contents. |
For local MCP development against this repository:
{
"mcpServers": {
"ast-grep": {
"command": "pnpm",
"args": ["run", "dev"],
"cwd": "/path/to/ast-grep-mcp"
}
}
}
When developing the server itself, launch it from this repository. When using the published package, set cwd to the target workspace.
Release Process
This project uses Changesets and GitHub Actions.
- Add a changeset with
pnpm changesetfor user-facing changes. - Open a pull request. The PR workflow runs formatting, linting, type checking, tests, build, and an npm pack dry run on Node 20 and 22.
- Merge to
main. The release workflow opens or updates a version PR. - Merge the version PR. The release workflow publishes to npm with provenance using
NPM_TOKEN.
Repository maintainers need to configure an npm automation token as the NPM_TOKEN GitHub Actions secret.
License
MIT
Install Ast Grep Mcp in Claude Desktop, Claude Code & Cursor
unyly install ast-grep-mcpInstalls into Claude Desktop, Claude Code, Cursor & VS Code — handles npx, uvx and build-from-source repos for you.
First time? Get the CLI: curl -fsSL https://unyly.org/install | sh
Or configure manually
Run in your terminal:
claude mcp add ast-grep-mcp -- npx -y ast-grep-mcpStep-by-step: how to install Ast Grep Mcp
FAQ
Is Ast Grep Mcp MCP free?
Yes, Ast Grep Mcp MCP is free — one-click install via Unyly at no cost.
Does Ast Grep Mcp need an API key?
No, Ast Grep Mcp runs without API keys or environment variables.
Is Ast Grep Mcp hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install Ast Grep Mcp in Claude Desktop, Claude Code or Cursor?
Open Ast Grep Mcp on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
GitHub
PRs, issues, code search, CI status
by GitHubFilesystem
Secure file operations with configurable access controls.
Memory
Knowledge graph-based persistent memory system.
Template MCP Server
A CLI tool to create a new Model Context Protocol server project with TypeScript support, dual transport options, and an extensible structure
by mcpdotdirectAmap Maps Mcp Server
MCP server for using the AMap Maps API
by duxiaohuiSupabase
Database, auth and storage
by SupabaseEverything
Reference / test server with prompts, resources, and tools.
Git
Tools to read, search, and manipulate Git repositories.
Sequential Thinking
Dynamic and reflective problem-solving through thought sequences.
Time
Time and timezone conversion capabilities.
Compare Ast Grep Mcp with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All development MCPs
