trackmcp
Back to directory
Isco0819

ast-grep-mcp

View on GitHub

indie dev tool — ast-grep-mcp

0 stars JavaScriptOthers Updated Jul 7, 2026

Documentation

ast-grep-mcp

MCP server that exposes ast-grep (`sg`) as two tools for structural code search.

Prerequisites

Install `sg` (ast-grep CLI):

bash
# via npm
npm i -g @ast-grep/cli

# via cargo
cargo install ast-grep

Verify: `sg --version`

Install & run

bash
# from this directory
npm install
node src/index.js        # starts MCP server on stdio
# or via npx after publish:
# npx ast-grep-mcp

Tools

Structural code search using an ast-grep pattern.

paramtyperequireddescription
`lang`stringyesLanguage: `js`, `ts`, `py`, `go`, `rust`, `java`, …
`pattern`stringyesast-grep pattern (e.g. `console.log($MSG)`)
`dir`stringnoDirectory 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.

paramtyperequireddescription
`name`enumyesOne of the 5 presets below
`dir`stringnoDirectory to search (default: `.`)

Available presets:

namewhat 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`

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:

json
{
  "mcpServers": {
    "ast-grep": {
      "command": "node",
      "args": ["/absolute/path/to/ast-grep-mcp/src/index.js"]
    }
  }
}

Or if you publish to npm:

json
{
  "mcpServers": {
    "ast-grep": {
      "command": "npx",
      "args": ["ast-grep-mcp"]
    }
  }
}

Pattern quick-reference

code
$VAR          – single node (any)
$$$NODES      – multiple nodes (spread)
`template $X` – template literal containing X
foo($A, $B)   – function call with two args

See 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

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP