ast-grep-edit-mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
ast-grep-edit-mcp
An MCP server that gives an AI agent ast-grep structural search and multi-file rewrite as first-class tools, so it reaches for syntax-aware tooling when a task is about the shape of code instead of plain text.
Tool | What it does |
| Finds code by AST pattern: calls with arguments, JSX, declarations, nesting, missing guards. Returns compact |
| Multi-file structural rewrite that keeps the surrounding formatting. Returns a diff by default; |
The server also tells the agent when to use each tool (MCP instructions) and ships a skill, ast-grep, with
pattern examples. It works over stdio with any MCP client (OpenCode, Claude Code, VS Code…) in both protocol
eras (2026-07-28 and 2025).
The tools are ported from opencode-ast-grep by Don Bowman, an OpenCode plugin; this package makes them available to every MCP client.
Requirements
Node 22 or later.
ast-grep0.40+ onPATH(pip install ast-grep-cli,npm i -g @ast-grep/cli,cargo install ast-grep --locked, orbrew install ast-grep).
Related MCP server: ast-grep MCP Server
Install
// OpenCode (opencode.json)
{
"mcp": {
"servers": {
"ast-grep": { "type": "local", "command": ["npx", "-y", "ast-grep-edit-mcp"] }
}
}
}# Claude Code
claude mcp add ast-grep -- npx -y ast-grep-edit-mcpThen ask for something structural: "find every console.log call with its arguments" or
"rename all oldApi(...) calls to newApi(...) under src".
Usage
// ast_grep_search — pattern is code with metavariables: $A one node, $$$ many, $_ no capture
{ "pattern": "console.log($$$ARGS)", "lang": "ts", "paths": ["src"] }
{ "pattern": "$A && $A()", "globs": ["!**/node_modules/**"], "limit": 50 }
// ast_grep_edit — 1) preview: returns a diff, writes nothing
{ "pattern": "console.log($$$ARGS)", "rewrite": "logger.info($$$ARGS)", "lang": "ts" }
// 2) apply
{ "pattern": "console.log($$$ARGS)", "rewrite": "logger.info($$$ARGS)", "lang": "ts", "apply": true }Both tools accept lang, paths, globs and strictness (cst | smart | ast | relaxed | signature |
template). Search also accepts context (lines around each match) and limit; edit also accepts apply.
Patterns are code, not regex. A pattern matches a whole node:
std::env::var($X)does not match a bareenv::var($X); try both forms.$$$absorbs any number of nodes: argument lists, bodies.Zero matches is a normal result, not an error.
Configuration
Variable | Default | Meaning |
|
| Path to the ast-grep binary |
| the directory the client starts it in | Project directory that paths are relative to |
Timeouts are fixed (20 s search, 30 s edit) and output is cut at about 50,000 characters so a huge match set cannot flood the context. The binary runs directly, never through a shell.
Development
npm install
npm test # build + smoke test over stdio (needs ast-grep)
npm run typecheckLicense
MIT — see LICENSE. Tools ported from opencode-ast-grep © Don Bowman (MIT).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
GitHub Copilot MCP: code, repo, PR, workflow tools for AI assistants.
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Scan AI agent skills, MCP server packages and MCP configs before you install them. Static analysis.
Related MCP Servers
- AlicenseBqualityDmaintenanceAdvanced code search and transformation MCP server for AI assistants. Combines ugrep's speed with intelligent replace capabilities, dry-run previews, and language-aware refactoring across 11 tools.110MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to search and analyze codebases using Abstract Syntax Tree (AST) pattern matching with ast-grep. Supports structural code search, pattern testing, and AST visualization across multiple programming languages.4503MIT
- AlicenseNot gradedqualityDmaintenanceA modular MCP server for code analysis using ast-grep, enabling structural pattern matching and transformations across multiple languages.MIT
- AlicenseAqualityDmaintenanceEnables structural code search and refactoring across 20+ programming languages using ast-grep patterns, with safe dry-run mode and flexible filtering.1MIT