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

typescript-ast-server

v1.0.2

Published

MCP server for TypeScript AST analysis

Readme

TypeScript AST MCP Server

A Model Context Protocol (MCP) server that provides TypeScript AST analysis capabilities using the TypeScript Compiler API.

Features

  • AST Analysis: Analyze TypeScript files for functions, objects, and other code structures
  • tsconfig.json Auto-detection: Automatically finds and uses project TypeScript configuration
  • No Text-based Search: Uses TypeScript Compiler API instead of grep or text parsing
  • Rich Metadata: Returns detailed information including parameters, types, locations, and export status

Setup Instructions

1. Install Dependencies

npm install

2. Configure Claude Desktop/CLI

Copy the generated claude_desktop_config.json content to your Claude Desktop configuration:

For Claude Desktop:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

For Claude CLI: Add the server configuration to your ~/.claude/config.json:

{
  "mcpServers": {
    "typescript-ast-server": {
      "command": "npx",
      "args": ["tsx", "typescript-ast-server.ts"],
      "env": {}
    }
  }
}

3. Test the Server

Run the server directly to test:

npm start

Usage

Tool: analyze-typescript-ast

Analyzes TypeScript files and extracts information about code structures.

Parameters:

  • filePath (required): Path to the TypeScript file to analyze
  • queryType (required): Type of analysis - "functions", "objects", or "all"
  • projectRoot (optional): Project root path (defaults to current working directory)

Sample CLI Commands

Once the MCP server is configured, you can use it from Claude CLI:

# Analyze functions in a specific file
claude --tool analyze-typescript-ast --filePath "./src/utils.ts" --queryType "functions"

# Analyze all objects in a file
claude --tool analyze-typescript-ast --filePath "./src/config.ts" --queryType "objects"

# Analyze both functions and objects
claude --tool analyze-typescript-ast --filePath "./src/app.ts" --queryType "all"

# Specify a different project root
claude --tool analyze-typescript-ast --filePath "./libs/shared/index.ts" --queryType "functions" --projectRoot "./libs/shared"

Example Output

Function Analysis:

{
  "functions": [
    {
      "name": "calculateTotal",
      "parameters": [
        {
          "name": "items",
          "type": "Item[]",
          "isOptional": false
        },
        {
          "name": "tax",
          "type": "number",
          "isOptional": true
        }
      ],
      "returnType": "number",
      "location": {
        "line": 15,
        "column": 1,
        "file": "/path/to/file.ts"
      },
      "isAsync": false,
      "isExported": true
    }
  ],
  "file": "/path/to/file.ts"
}

Object Analysis:

{
  "objects": [
    {
      "name": "config",
      "properties": [
        {
          "name": "apiUrl",
          "type": "string",
          "value": "'https://api.example.com'"
        },
        {
          "name": "timeout",
          "type": "number",
          "value": "5000"
        }
      ],
      "location": {
        "line": 8,
        "column": 1,
        "file": "/path/to/file.ts"
      },
      "isExported": true
    }
  ],
  "file": "/path/to/file.ts"
}

Error Handling

The server includes comprehensive error handling for:

  • Missing or invalid file paths
  • Missing tsconfig.json files
  • TypeScript compilation errors
  • Invalid query types

Development

Running in Development Mode

npm run dev

Manual Testing

Create a test TypeScript file and run analysis:

echo "export function test(a: string, b?: number): boolean { return true; }" > test.ts
npx tsx typescript-ast-server.ts
# Then use the analyze-typescript-ast tool via Claude CLI

Technical Details

  • Uses TypeScript Compiler API for AST parsing
  • Supports both tsconfig.json-based and standalone analysis
  • Extracts detailed type information when available
  • Handles various function types: declarations, expressions, arrow functions, and methods
  • Analyzes object literals with property details and type information