ast-grep alternative: trace-mcp vs ast-grep

TL;DR. ast-grep (ast-grep/ast-grep, 16K stars, MIT, Rust) is the best structural grep most teams have never tried: write a pattern that looks like ordinary code with $LIKE_THIS wildcards, and it finds or rewrites every AST node with that shape — fast, multi-core, configured in YAML, runnable in CI. trace-mcp is a different kind of tool: it parses the repo into a persistent dependency graph (symbols, imports, call edges, framework edges across 88 integrations) and serves it over MCP, so an agent asks “who calls this” and “what breaks if I change it” instead of re-searching files every turn.

If the job is “find every if (x && x()) and rewrite it”, ast-grep wins outright. If the job is “an agent working in this repo for forty turns”, the graph wins.

Head-to-head

Capability trace-mcp ast-grep
GitHub stars 175 16K
License MIT MIT
Written in TypeScript Rust
Model persistent index (SQLite + FTS5) one-shot structural search
Pattern search ✓ symbol/FTS search (text + graph) ✓ AST patterns with metavariables
Rewriting ✓ AST codemod, rename, move, extract ✓ --rewrite + YAML rules
Cross-file call graph ✓ bidirectional, graph-based ✗ per-file pattern matches
Impact analysis ✓ reverse dependency traversal ✗
Framework-aware edges ✓ 88 integrations ✗
MCP tools advertised (default) 29 (~11.6K tok); 182 on full 0 — CLI, no MCP server in README
Works offline, no API keys ✓ ✓
CI / lint integration ✓ SARIF 2.1.0, quality gates ✓ YAML rules as lint
Session memory ✓ code-linked decisions, staleness-checked ✗
Security scanning ✓ OWASP Top-10 taint ✗ (custom rules possible, not shipped)

Verified on September 26, 2026 against the ast-grep README at main (16K stars, ast-grep/ast-grep) plus the GitHub API for stars, license and language. Language count for ast-grep not stated as a single figure in the README on that date, so the table carries no number rather than a guessed one.

When to pick ast-grep

Honest version, and it is a real list:

When to pick trace-mcp

The honest caveat

Two of them. First, ast-grep’s pattern engine is the tool ours is not: for “every call shaped like X”, a pattern is more precise than our symbol search plus graph filter, and cheaper than any graph query. We would rather say that here than have you benchmark it yourself.

Second, our default tool surface is expensive next to a CLI. trace-mcp advertises 29 tools at roughly 11.6K tokens on the shipped default path; ast-grep advertises nothing because there is no session to advertise into. A short scripted job genuinely costs less through ast-grep.

Our security scanning has a ceiling, stated on the comparisons page rather than only here. The control-flow graph is line-based, not AST-based, and taint analysis is lexical/regex, not a real dataflow engine. Type-aware pruning cuts false positives; it does not turn this into a dataflow analyser.

FAQ

What is the core difference between ast-grep and trace-mcp? ast-grep matches structural patterns per invocation; trace-mcp precomputes a persistent graph and serves it over MCP. Pattern matching versus a queryable index.

Can ast-grep do impact analysis or find callers? Not as a traversal. A pattern for the callee name approximates callers until overloads, re-exports or dynamic dispatch defeat the pattern. Transitive impact needs resolved edges, which is the graph’s job.

Does ast-grep have an MCP server? Not in its README as read on September 26, 2026. It ships as a CLI with YAML rules; an agent uses it by shelling out.

Which is better for large-scale codemods? ast-grep for shape-based rewrites (isomorphic patterns, YAML lint rules, multi-core). trace-mcp when the rewrite follows edges — rename with import rewriting, moves, signature changes verified against the graph.

Can I use both? Yes — ast-grep for structural search and rewrites in CI and scripts, trace-mcp as the agent’s live index for navigation, impact analysis and framework-aware questions.

Next steps

Last updated: September 26, 2026