Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

ast-mcp-server

MCP.Pizza Chef: angrysky56

The ast-mcp-server is an MCP server that offers advanced code analysis by parsing source code into Abstract Syntax Trees (AST) and Abstract Semantic Graphs (ASG). It supports multiple programming languages like Python and JavaScript, enabling detailed code structure and complexity analysis. Features include incremental parsing for large files, enhanced semantic scope handling, and AST diffing to detect code changes. Compatible with MCP clients such as Claude Desktop, it facilitates real-time, structured code insights for development workflows.

Use This MCP server To

Parse source code into AST for structural analysis Generate semantic graphs to understand code relationships Analyze code complexity across Python and JavaScript projects Detect code changes via AST diffing between versions Enable incremental parsing for efficient large file processing Integrate with MCP clients for real-time code insights Support multi-language codebases with unified analysis Improve code review by highlighting semantic differences

README

AST MCP Server

An MCP (Model Context Protocol) server that provides code structure and semantic analysis capabilities through Abstract Syntax Trees (AST) and Abstract Semantic Graphs (ASG).

Features

  • Parse code into Abstract Syntax Trees (AST)
  • Generate Abstract Semantic Graphs (ASG) from code
  • Analyze code structure and complexity
  • Support for multiple programming languages (Python, JavaScript)
  • Compatible with Claude Desktop and other MCP clients
  • Incremental parsing for faster processing of large files
  • Enhanced scope handling and more complete semantic analysis
  • AST diffing to identify changes between code versions

Installation

  1. Clone this repository:
git clone https://github.com/yourusername/ast-mcp-server.git
cd ast-mcp-server
  1. Set up the environment using uv:
# Install uv if you don't have it already
# pip install uv

# Create and activate virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
uv pip install -r requirements.txt
  1. Build the parsers:
uv run build_parsers.py

Usage with Claude Desktop

  1. Configure Claude Desktop to use the server. The easiest way is to use the provided claude_desktop_config.json file:
{
  "mcpServers": {
    "AstAnalyzer": {
      "command": "uv",
      "args": [
        "--directory", "/absolute/path/to/ast-mcp-server",
        "run", "server.py"
      ]
    }
  }
}
  1. Make sure to replace /absolute/path/to/ast-mcp-server with the actual absolute path on your system.

  2. Add this configuration to your Claude Desktop config:

    • On macOS: ~/Library/Application Support/claude-desktop/claude_desktop_config.json
    • On Linux: ~/.config/claude-desktop/claude_desktop_config.json
    • On Windows: %APPDATA%\claude-desktop\claude_desktop_config.json
  3. Restart Claude Desktop to load the new MCP server.

  4. In Claude Desktop, you can now use the AST-based code analysis tools.

The AST MCP Server is working correctly. Here's a summary of the features I've verified:

Basic AST Parsing ✓

Successfully parsed Python code into a detailed abstract syntax tree The structure shows proper node hierarchy with types, positions, and content

ASG Generation ✓

Generated an Abstract Semantic Graph with nodes and edges The graph correctly shows relationships between components

Code Analysis ✓

Successfully analyzed code structure, identifying:

Functions (with names, locations, and parameters) Classes Complexity metrics

Resource Caching ✓

The parse_and_cache function worked correctly A URI was generated for retrieving the parsed AST later

Multi-language Support ✓

Successfully parsed both Python and JavaScript code The supported_languages tool confirmed Python and JavaScript are available

The server is fully operational and all key functionality works as expected. When integrated with Claude Desktop using the updated configuration in claude_desktop_config.json, it will provide powerful code analysis capabilities.

Development and Testing

To run the server in development mode with the MCP inspector:

# Using the included script
./dev_server.sh

# Or manually
uv run -m mcp dev server.py

Available Tools

The server provides the following tools:

Basic Tools

  • parse_to_ast: Parse code into an Abstract Syntax Tree
  • generate_asg: Generate an Abstract Semantic Graph from code
  • analyze_code: Analyze code structure and complexity
  • supported_languages: Get the list of supported programming languages
  • parse_and_cache: Parse code into an AST and cache it for resource access
  • generate_and_cache_asg: Generate an ASG and cache it for resource access
  • analyze_and_cache: Analyze code and cache the results for resource access

Enhanced Tools

  • parse_to_ast_incremental: Parse code with incremental support for faster processing
  • generate_enhanced_asg: Generate an enhanced ASG with better scope handling
  • diff_ast: Find differences between two versions of code
  • find_node_at_position: Locate a specific node at a given line and column
  • parse_and_cache_incremental: Parse code incrementally and cache the results
  • generate_and_cache_enhanced_asg: Generate an enhanced ASG and cache it
  • ast_diff_and_cache: Generate an AST diff and cache it

Adding More Language Support

To add support for additional languages:

  1. Install the corresponding tree-sitter language package:
uv pip install tree-sitter-<language>
  1. Update the LANGUAGE_MODULES dictionary in build_parsers.py and ast_mcp_server/tools.py.

  2. Run uv run build_parsers.py to initialize the new language.

How It Works

The AST MCP Server connects with Claude Desktop through the Model Context Protocol (MCP). When launched:

  1. Claude Desktop starts the server using uv run with the appropriate working directory
  2. The server loads tree-sitter language modules for parsing various programming languages
  3. It registers tools and resources with the MCP protocol
  4. Claude can then access these tools to analyze code you share in the chat

All tool execution happens locally on your machine, with results returned to Claude for interpretation.

License

MIT

ast-mcp-server FAQ

How do I install the ast-mcp-server?
Clone the repository, set up a virtual environment using 'uv', and activate it before running the server.
Which programming languages does ast-mcp-server support?
It currently supports Python and JavaScript with plans for future language support.
Can ast-mcp-server handle large codebases efficiently?
Yes, it uses incremental parsing to speed up processing of large files.
How does AST diffing work in ast-mcp-server?
It compares Abstract Syntax Trees of different code versions to identify structural changes.
Is ast-mcp-server compatible with multiple MCP clients?
Yes, it works with clients like Claude Desktop and other MCP-compatible clients.
What benefits does semantic analysis provide?
It offers deeper understanding of code relationships and scope beyond simple syntax parsing.
Can I extend ast-mcp-server to support other languages?
The architecture allows adding new language parsers and semantic analyzers with development effort.
Does ast-mcp-server support real-time code analysis?
Yes, it supports incremental parsing for near real-time updates during code editing.