npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-ast-grep-mcp

v1.0.16

Published

Simple, direct ast-grep wrapper for AI coding agents. Zero abstractions, maximum performance.

Readme

tree-ast-grep MCP Server

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

🚀 Quick Start

Add to your MCP settings:

{
  "mcpServers": {
    "tree-ast-grep": {
      "command": "npx",
      "args": ["-y", "tree-ast-grep-mcp", "--auto-install"]
    }
  }
}

🎯 What It Does

Three simple tools that directly execute ast-grep commands:

  • ast_searchast-grep run --pattern (structural code search)
  • ast_replaceast-grep run --rewrite (AST-aware replacements)
  • ast_run_ruleast-grep scan --rule (generate & run custom rules)

✨ Key Features

  • Zero Overhead - Direct ast-grep execution, no abstractions
  • Perfect Compatibility - Behaves exactly like ast-grep CLI
  • Inline Code Support - Test patterns without files
  • Named Metavariables - $NAME, $ARG, $$$BODY work perfectly
  • Auto-Install - Downloads platform-specific ast-grep binary
  • Minimal Codebase - ~300 lines, crystal clear logic

📖 Usage Examples

Search for Patterns

// Find all console.log statements
ast_search({
  pattern: "console.log($ARG)",
  language: "javascript",
  code: "console.log('hello'); console.log('world');"
})

Replace Code Structures

// Convert var to let
ast_replace({
  pattern: "var $NAME = $VALUE",
  replacement: "let $NAME = $VALUE",
  language: "javascript",
  code: "var x = 5; var y = 10;"
})

Generate Custom Rules

// Create linting rule
ast_run_rule({
  id: "no-console-log",
  pattern: "console.log($ARG)",
  message: "Use logger.info instead",
  language: "javascript",
  fix: "logger.info($ARG)"
})

🏗️ Architecture

Intentionally Simple:

src/
├── index.ts           # MCP server
├── core/
│   ├── binary-manager.ts    # Execute ast-grep
│   └── workspace-manager.ts # Find workspace root
├── tools/
│   ├── search.ts      # Direct search
│   ├── replace.ts     # Direct replace
│   └── scan.ts        # Direct scan
└── types/errors.ts    # Basic errors

Each tool: Validate → Build Command → Execute → Parse → Return

🧪 Testing

Patterns work exactly like ast-grep CLI:

# Test patterns directly
ast-grep run --pattern "console.log($ARG)" --lang javascript file.js

# Test replacements
ast-grep run --pattern "var $NAME" --rewrite "let $NAME" --lang javascript file.js

# Test rules
ast-grep scan --rule rule.yml file.js

⚡ Performance

  • Direct Execution - No overhead vs ast-grep CLI
  • Streaming JSON - Fast results parsing
  • Binary Caching - One-time download per platform
  • Minimal Memory - No complex abstractions

🔧 Configuration Options

# Lightweight (requires system ast-grep)
npx tree-ast-grep-mcp --use-system

# Platform-specific binary
npx tree-ast-grep-mcp --platform=win32

# Auto-detect platform (recommended)
npx tree-ast-grep-mcp --auto-install

📝 Metavariable Guide

✅ Reliable Patterns:

  • $NAME, $ARG, $VALUE (single nodes)
  • $$$BODY, $$$ARGS (named multi-nodes)
  • console.log($ARG)logger.info($ARG)

⚠️ Use With Care:

  • Bare $$$ produces literal "$$$" in replacements
  • Complex structural patterns may not match reliably

🚫 What This ISN'T

  • ❌ A complex AST manipulation framework
  • ❌ A wrapper with proprietary pattern syntax
  • ❌ An abstraction layer over ast-grep
  • ❌ A reimplementation of ast-grep functionality

✅ What This IS

  • ✅ Direct ast-grep command execution
  • ✅ Minimal MCP protocol wrapper
  • ✅ Perfect CLI compatibility
  • ✅ Zero-overhead tool integration
  • ✅ Simple, maintainable codebase

🤝 Contributing

Keep it simple! Follow the CLAUDE.md guidelines:

  • No abstractions or base classes
  • Direct command execution only
  • Test against ast-grep CLI behavior
  • Favor duplication over complexity

📄 License

MIT License - Use freely, keep it simple!