Allows for parsing and structural analysis of C++ code to evaluate complexity and generate Abstract Syntax Trees.
Enables the structural analysis of JavaScript code through AST generation and Abstract Semantic Graph construction.
Provides tools for parsing Python code into Abstract Syntax Trees and performing semantic analysis, including complexity and scope evaluation.
Facilitates the semantic analysis of Rust codebases by generating Abstract Syntax Trees and graphs for structural insights.
Supports structural and semantic analysis of TypeScript code, including incremental parsing and AST diffing to identify changes between code versions.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@AST MCP Serveranalyze the complexity of the process_data function in main.py"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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, TypeScript, Go, Rust, C/C++, Java)
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
Resource caching for improved performance
Installation
Prerequisites
Python 3.9 or higher
uv package manager (recommended) or pip
Using uv (Recommended)
Clone this repository:
Install the project and dependencies:
Build the tree-sitter parsers:
Using pip (Alternative)
Usage with Claude Desktop
Configure Claude Desktop to use the server by editing your configuration file:
Location of config file:
macOS:
~/Library/Application Support/claude-desktop/claude_desktop_config.jsonLinux:
~/.config/claude-desktop/claude_desktop_config.jsonWindows:
%APPDATA%\claude-desktop\claude_desktop_config.json
Add the AST MCP server configuration:
Important: Replace /absolute/path/to/ast-mcp-server with the actual absolute path on your system.
Restart Claude Desktop to load the new MCP server.
In Claude Desktop, you can now use the AST-based code analysis tools by referencing code files or pasting code snippets.
Development
Development Environment Setup
Running in Development Mode
To run the server in development mode with the MCP inspector:
Testing
Code Quality
Available Tools
The server provides the following tools for code analysis:
Basic Tools
parse_to_ast: Parse code into an Abstract Syntax Treegenerate_asg: Generate an Abstract Semantic Graph from codeanalyze_code: Analyze code structure and complexitysupported_languages: Get the list of supported programming languages
Caching Tools
parse_and_cache: Parse code into an AST and cache it for resource accessgenerate_and_cache_asg: Generate an ASG and cache it for resource accessanalyze_and_cache: Analyze code and cache the results for resource access
Enhanced Tools
parse_to_ast_incremental: Parse code with incremental support for faster processinggenerate_enhanced_asg: Generate an enhanced ASG with better scope handlingdiff_ast: Find differences between two versions of codefind_node_at_position: Locate a specific node at a given line and columnparse_and_cache_incremental: Parse code incrementally and cache the resultsgenerate_and_cache_enhanced_asg: Generate an enhanced ASG and cache itast_diff_and_cache: Generate an AST diff and cache it
Adding Language Support
To add support for additional programming languages:
Install the corresponding tree-sitter language package:
Update the
LANGUAGE_MODULESdictionary inbuild_parsers.pyandast_mcp_server/tools.py.Build the parsers:
Currently Supported Languages
Python (
tree-sitter-python)JavaScript (
tree-sitter-javascript)TypeScript (
tree-sitter-typescript)Go (
tree-sitter-go)Rust (
tree-sitter-rust)C (
tree-sitter-c)C++ (
tree-sitter-cpp)Java (
tree-sitter-java)
How It Works
The AST MCP Server connects with Claude Desktop through the Model Context Protocol (MCP):
Initialization: Claude Desktop starts the server using
uv runwith the appropriate working directoryLanguage Loading: The server loads tree-sitter language modules for parsing various programming languages
MCP Registration: It registers tools and resources with the MCP protocol
Analysis: Claude can access these tools to analyze code you share in the chat
Caching: Results are cached locally for improved performance
All tool execution happens locally on your machine, with results returned to Claude for interpretation and assistance.
Configuration Files
pyproject.toml: Project metadata, dependencies, and tool configurationclaude_desktop_config.json: Example Claude Desktop configurationdev_server.sh: Development server script.gitignore: Git ignore rules
Directory Structure
Troubleshooting
Parser Issues
If you encounter parser-related errors:
Claude Desktop Connection Issues
Verify the absolute path in your Claude Desktop configuration
Ensure uv is in your system PATH
Check Claude Desktop logs for error messages
Restart Claude Desktop after configuration changes
Performance Issues
Use incremental parsing tools for large files
Enable caching for repeated analysis
Consider analyzing smaller code sections
Contributing
Fork the repository
Create a feature branch:
git checkout -b feature-nameMake your changes with proper tests
Run the test suite:
uv run pytestSubmit a pull request
Development Guidelines
Follow PEP 8 style guidelines (enforced by black and flake8)
Add type hints to all public functions
Include docstrings for all modules, classes, and functions
Write tests for new functionality
Update documentation as needed
License
MIT License - see LICENSE file for details.
Changelog
v0.2.0
Added pyproject.toml configuration
Improved uv compatibility
Enhanced caching system
Added incremental parsing support
Expanded language support
Better error handling and logging
v0.1.0
Initial release
Basic AST/ASG parsing
Claude Desktop integration
Support for Python and JavaScript