ast-grep-mcp
indie dev tool — ast-grep-mcp
Documentation
ast-grep-mcp
MCP server that exposes ast-grep (`sg`) as two tools for structural code search.
Prerequisites
Install `sg` (ast-grep CLI):
# via npm
npm i -g @ast-grep/cli
# via cargo
cargo install ast-grepVerify: `sg --version`
Install & run
# from this directory
npm install
node src/index.js # starts MCP server on stdio
# or via npx after publish:
# npx ast-grep-mcpTools
`ast_search`
Structural code search using an ast-grep pattern.
| param | type | required | description |
|---|---|---|---|
| `lang` | string | yes | Language: `js`, `ts`, `py`, `go`, `rust`, `java`, … |
| `pattern` | string | yes | ast-grep pattern (e.g. `console.log($MSG)`) |
| `dir` | string | no | Directory to search (default: `.`) |
Returns: JSON array of `{ file, line, match, snippet }`
Example prompt:
> Use ast_search with lang=ts, pattern=`console.log($MSG)`, dir=./src
`ast_search_preset`
Run a named code-smell preset.
| param | type | required | description |
|---|---|---|---|
| `name` | enum | yes | One of the 5 presets below |
| `dir` | string | no | Directory to search (default: `.`) |
Available presets:
| name | what it finds |
|---|---|
| `async-no-catch` | `await` expressions — check for missing try/catch |
| `hooks-missing-deps` | `useEffect(..., [])` — empty deps may hide missing dependencies |
| `route-no-auth` | Express `app.METHOD(path, handler)` — routes that may lack auth middleware |
| `sql-no-param` | Template-literal SQL strings — potential injection risk |
| `promise-no-return` | `new Promise(...)` bodies — check all paths resolve/reject |
Claude Desktop config
`~/Library/Application Support/Claude/claude_desktop_config.json`
{
"mcpServers": {
"ast-grep": {
"command": "node",
"args": ["/absolute/path/to/ast-grep-mcp/src/index.js"]
}
}
}Cursor `mcp.json`
`.cursor/mcp.json` in your project root:
{
"mcpServers": {
"ast-grep": {
"command": "node",
"args": ["/absolute/path/to/ast-grep-mcp/src/index.js"]
}
}
}Or if you publish to npm:
{
"mcpServers": {
"ast-grep": {
"command": "npx",
"args": ["ast-grep-mcp"]
}
}
}Pattern quick-reference
$VAR – single node (any)
$$$NODES – multiple nodes (spread)
`template $X` – template literal containing X
foo($A, $B) – function call with two argsSee ast-grep pattern syntax for full docs.
Frequently asked questions
What is ast-grep-mcp?
ast-grep-mcp is indie dev tool — ast-grep-mcp
How do I install ast-grep-mcp?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is ast-grep-mcp open source?
Yes — it is hosted on GitHub at https://github.com/Isco0819/ast-grep-mcp.
Related MCP tools
🔥 Official Firecrawl MCP Server - Adds powerful web scraping and search to Cursor, Claude and any other LLM clients.
Use any LLMs (Large Language Models) for Deep Research. Support SSE API and MCP server.
Enhanced MCP server for interactive user feedback and command execution in AI-assisted development, featuring dual interface support (Web UI and Desktop Application) with intelligent environment detection and cross-platform compatibility.
A powerful Zotero AI and MCP plugin with ChatGPT, Gemini 3.7, Claude Fable 5, Claude Opus 5, DeepSeek V4, Grok, OpenRouter, Kimi k3, GLM 5.3, SiliconFlow, GPT-oss, Gemma 4, Qwen 3.8
Connect your browser to AI models. Just use Dia on Chrome, Arc or Firefox.
文颜 MCP Server 可以让 AI 自动将 Markdown 文章排版后发布至微信公众号。
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP