AST MCP Server logo

AST MCP Server

Community
angrysky56

By transforming source code into a queryable Semantic Graph and a structured AST, this tool bridges the gap between "reading text" and "understanding structure." For an AI assistant, it provides the "spatial" awareness needed to navigate deep dependencies without getting lost in large files.

Publisherangrysky56
Repositoryast-mcp-server
LanguagePython
Forks
7
Stars
36
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    AST MCP Server exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    36 stars and 7 forks from the linked repository.

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)

  1. Clone this repository:
bash
git clone https://github.com/angrysky56/ast-mcp-server.git
cd ast-mcp-server
  1. Install the project and dependencies:
bash
# Install the project in development mode with all dependencies
uv sync

# Or install with specific optional dependencies
uv sync --extra dev  # Development tools
uv sync --extra testing  # Testing dependencies
uv sync --extra docs  # Documentation tools
  1. Build the tree-sitter parsers:
bash
uv run build-parsers

Using pip (Alternative)

bash
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e .

# Build parsers
python build_parsers.py

Usage with Claude Desktop

  1. 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.json
  • Linux: ~/.config/claude-desktop/claude_desktop_config.json
  • Windows: %APPDATA%\claude-desktop\claude_desktop_config.json
  1. Add the AST MCP server configuration:
json
{
  "mcpServers": {
    "AstAnalyzer": {
      "command": "uv",
      "args": [
        "--directory",
        "/home/ty/Repositories/ai_workspace/ast-mcp-server/ast_mcp_server",
        "run",
        "server.py"
      ]
    }
  }
}

Important: Replace /absolute/path/to/ast-mcp-server with the actual absolute path on your system.

  1. Restart Claude Desktop to load the new MCP server.

  2. In Claude Desktop, you can now use the AST-based code analysis tools by referencing code files or pasting code snippets.

Antigravity Self-Scan Example

Development

Development Environment Setup

bash
# Install with development dependencies
uv sync --extra dev

# Install pre-commit hooks (optional)
uv run pre-commit install

Running in Development Mode

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

bash
# Using uv
uv run --extra dev -- -m mcp dev server.py

# Or using the development script
./dev_server.sh

Testing

bash
# Run all tests
uv run --extra testing pytest

# Run tests with coverage
uv run --extra testing pytest --cov=ast_mcp_server --cov-report=html

# Run specific tests
uv run --extra testing pytest tests/test_specific.py

Code Quality

bash
# Format code
uv run black .
uv run isort .

# Lint code
uv run flake8 .

# Type checking
uv run mypy ast_mcp_server/

Available Tools

The server provides the following tools for code analysis:

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

Caching Tools

  • 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 Language Support

To add support for additional programming languages:

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

  2. Build the parsers:

bash
uv run build-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):

  1. Initialization: Claude Desktop starts the server using uv run with the appropriate working directory
  2. Language Loading: The server loads tree-sitter language modules for parsing various programming languages
  3. MCP Registration: It registers tools and resources with the MCP protocol
  4. Analysis: Claude can access these tools to analyze code you share or local files. Tools are designed to be robust: they can intelligently read from local filename paths if the provided code is a placeholder.
  5. 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 configuration
  • claude_desktop_config.json: Example Claude Desktop configuration
  • dev_server.sh: Development server script
  • .gitignore: Git ignore rules

Directory Structure

ast-mcp-server/
├── ast_mcp_server/          # Main package
│   ├── __init__.py
│   ├── tools.py             # Core AST/ASG tools
│   ├── enhanced_tools.py    # Enhanced analysis features
│   ├── resources.py         # MCP resource handlers
│   └── parsers/             # Tree-sitter parser cache
├── examples/                # Usage examples
├── tests/                   # Test suite
├── server.py                # Main server entry point
├── build_parsers.py         # Parser setup script
├── pyproject.toml           # Project configuration
└── README.md               # This file

Troubleshooting

Parser Issues

If you encounter parser-related errors:

bash
# Rebuild parsers
uv run build-parsers

# Check for missing language packages
uv add tree-sitter-python tree-sitter-javascript

Claude Desktop Connection Issues

  1. Verify the absolute path in your Claude Desktop configuration
  2. Ensure uv is in your system PATH
  3. Check Claude Desktop logs for error messages
  4. 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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes with proper tests
  4. Run the test suite: uv run pytest
  5. Submit 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

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "angrysky56-ast-mcp-server": {
      "command": "",
      "args": []
    }
  }
}

Use AST MCP Server MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once AST MCP Server is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add AST MCP Server as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the AST MCP Server MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "angrysky56-ast-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "ast-mcp-server"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the AST MCP Server MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the AST MCP Server MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use AST MCP Server to help me with this task?
AST MCP Server
Sure. I read it.
Here is what I found using AST MCP Server.

Frequently asked questions

What is the AST MCP Server MCP server used for?

AST MCP Server is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use AST MCP Server MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use AST MCP Server with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use AST MCP Server MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With AST MCP Server connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect AST MCP Server MCP to TypingMind?

AST MCP Server runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does AST MCP Server MCP provide in TypingMind?

AST MCP Server exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use AST MCP Server MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If AST MCP Server requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇