Skip to content

A **simple, direct wrapper** around ast-grep for AI coding agents. Zero abstractions, maximum performance, perfect ast-grep compatibility.

License

Notifications You must be signed in to change notification settings

Justar96/tree-grep-mcp

Repository files navigation

tree-ast-grep MCP Server

MCP server for structural code search and transformation using ast-grep. Direct CLI wrapper with zero abstractions.

Official ast-grep documentation: https://github.com/ast-grep/ast-grep, https://ast-grep.github.io/

Note: This project is in early development. Please report issues at GitHub Issues.

Installation

1. Install ast-grep:

npm install -g @ast-grep/cli   # or: brew install ast-grep

2. Add to MCP config:

{
  "mcpServers": {
    "tree-ast-grep": {
      "command": "npx",
      "args": ["-y", "@cabbages/tree-grep"]
    }
  }
}

Tools

This server provides four tools for LLM agents:

  • ast_search - Search code using AST pattern matching
  • ast_replace - Replace code using AST patterns (supports dry-run mode)
  • ast_run_rule - Execute YAML rules with constraints and fixes
  • ast_explain_pattern - Debug patterns and see metavariable captures

Tool schemas and parameters are provided via MCP protocol.

Troubleshooting

Binary not found:

npm install -g @ast-grep/cli
ast-grep --version

Requirements

  • Node.js >= 18.0.0 or Bun >= 1.0.0
  • ast-grep installed on system

Token Usage

The MCP server exposes 4 tools with a total context cost of ~10,898 tokens (approximation method, ±20% variance).

Context Window Impact

╔══════════════════════════════════════════════════════════════════════════════╗
║ 🚀 Context Window Impact - Latest 2025 Models                               ║
╠══════════════════════════════════════════════════════════════════════════════╣
║ 🤖 GPT-5                  400K │  2.72% ██████░░░░░░░░░░░░░░░░░░░░░░░░ ║
║ 🧠 Claude Sonnet 4.5      200K │  5.45% ███████████░░░░░░░░░░░░░░░░░░░ ║
║ ⚡ Grok 4               2,000K │  0.54% ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ║
║ 💎 Gemini 2.5 Pro       1,000K │  1.09% ███░░░░░░░░░░░░░░░░░░░░░░░░░░░ ║
╚══════════════════════════════════════════════════════════════════════════════╝

Run Token analysis:

node scripts/count-tool-tokens.js

Links

License

MIT

About

A **simple, direct wrapper** around ast-grep for AI coding agents. Zero abstractions, maximum performance, perfect ast-grep compatibility.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published