Sponsored by Deepsite.site

AST MCP Server

Created By
angrysky568 months ago
AST/ASG Code Analysis MCP Server
Content

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

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
DeepChatYour AI Partner on Desktop
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
WindsurfThe new purpose-built IDE to harness magic
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Playwright McpPlaywright MCP server
CursorThe AI Code Editor
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Amap Maps高德地图官方 MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
ChatWiseThe second fastest AI chatbot™
Serper MCP ServerA Serper MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors