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

ast-search-mcp

v1.2.1

Published

MCP server for ast-search — structural code search for AI agents

Readme

ast-search-mcp

npm

MCP server for ast-search-js — structural code search for AI agents. Exposes AST pattern search as MCP tools so any MCP-compatible client (Claude Code, Claude Desktop, etc.) can search source code by shape rather than text.

Table of Contents

Installation

npm install -g ast-search-mcp

# Optional: add Python support
npm install -g ast-search-python

Setup

Add the server to your MCP client's configuration. For Claude Code, add to .claude/settings.json in your project (or ~/.claude/settings.json globally):

{
  "mcpServers": {
    "ast-search": {
      "command": "ast-search-mcp"
    }
  }
}

For Claude Desktop, add to claude_desktop_config.json:

{
  "mcpServers": {
    "ast-search": {
      "command": "ast-search-mcp"
    }
  }
}

Or run without a global install using npx:

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

Tools

search

Search source code using AST structural patterns. Returns match locations with file path, line, column, and source snippet.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | queries | string[] | required | One or more AST selector queries. CSS selectors for JS/TS/Vue; S-expressions for Python. | | dir | string | cwd | Root directory to search | | lang | string | all | Restrict to one language backend, e.g. "js" or "python" | | exclude | string[] | none | Glob patterns to exclude, e.g. ["**/*.test.ts", "dist/**"] | | limit | number | none | Stop after N matches — useful for exploratory scope checks | | context | number | 0 | Lines of source context to include above and below each match | | showAst | boolean | false | Include the AST subtree of each matched node — useful when writing or debugging queries | | plugins | string[] | none | Language plugin packages to load, e.g. ["ast-search-python"] |

Result shape:

{
  "matches": [
    {
      "file": "src/app.ts",
      "line": 10,
      "col": 4,
      "start": 312,
      "end": 337,
      "offsetEncoding": "utf16",
      "source": "logger.info(\"hello world\")",
      "captures": { "callee.property.name": "info" }
    }
  ],
  "_meta": {
    "matchCount": 1,
    "filesSearched": 42,
    "wallMs": 180,
    "queries": ["call[callee.property.name=/^(log|info|warn|error)$/]"],
    "truncated": false
  }
}

start/end are character offsets whose encoding is indicated by offsetEncoding: "utf16" for JS/TS (Babel), "bytes" for Python (tree-sitter). source_full is included when a match spans multiple lines. captures is present when the query used regex attribute matchers. query is present on each match when multiple queries were provided.

validate_query

Validate an AST selector without running a search. For JS queries, also returns a plain-English explanation of what nodes the selector matches.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | query | string | required | AST selector to validate | | lang | string | "js" | Language backend to validate against: "js" or "python" | | plugins | string[] | none | Language plugin packages required for the target language |

Result shape (valid):

{
  "valid": true,
  "lang": "js",
  "explanation": "Matches `CallExpression` nodes where `callee.property.name` matches /^(log|info)$/"
}

Result shape (invalid):

{
  "valid": false,
  "error": "Unknown pseudo-class ':hasChild'"
}

show_ast

Print the AST structure of a code snippet or source file. Use this to discover node types and property paths when writing queries.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | code | string | — | Inline code snippet to parse and print | | file | string | — | Path to a source file to parse | | lines | string | — | Line range when using file, e.g. "10-20" (1-indexed, inclusive) | | lang | string | inferred | Language to use: "js" (default) or "python". Inferred from file extension when file is given. | | plugins | string[] | none | Language plugin packages required for the target language |

Provide either code or file — not both.

Python support

To search .py and .pyw files, install the Python plugin and pass it in the plugins parameter of any tool call:

npm install -g ast-search-python

Then in your tool calls, include "plugins": ["ast-search-python"]. Plugins are loaded once per server session — subsequent calls with the same plugin name are no-ops.

Python queries use tree-sitter S-expression syntax. See ast-search-python for the full query syntax and shorthands.

{
  "queries": ["fn"],
  "dir": "/path/to/project",
  "plugins": ["ast-search-python"],
  "lang": "python"
}