Logo vun AST MCP Server

AST MCP Server

Communautéit
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.

Editeurangrysky56
Repositoryast-mcp-server
SproochPython
Forks
7
Stären
36
Disponibel Tools
0
Transporttypstdio
Kategorien
LizenzMIT
Linken
  • Tools mat KI-Workflows verbannen

    AST MCP Server stellt MCP-Funktioune bereit, déi vu kompatibele KI-Clienten a KI-Agente kënne benotzt ginn.

  • 0 disponibel Tools

    Kuckt Iech déi opruffbar Aktiounen hei drënner un, mat Nimm a Beschreiwungen, wa se vum Server geliwwert ginn.

  • Konfiguratioun fir ze kopéieren

    Benotzt d'Installatiounsbeispiller, fir dëse Server an Ärem bevorzugte MCP-Client ze konfiguréieren.

  • Indicateure fir Open Source

    36 Stären an 7 Forks aus dem verlinkte 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

Installatioun

TypingMind
Viraussetzungen:

Node.js 18+

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

AST MCP Server MCP mat verschiddene KI-Modeller benotzen

TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Soubal AST MCP Server verbonnen ass, kënnt Dir et mat verschiddene KI-Modeller an TypingMind benotzen, amplaz et fir all Modell separat anzeriichten. Dës MCP-Integratioun leeft lokal iwwer den TypingMind-MCP-Connector op Ärem Apparat.

Ariichtungsuleedung fir de lokale Connector ze benotzen

Benotzt dës Optioun, wann den MCP-Server Zougrëff op lokal Fichieren, Appen oder privat Ressourcen op Ärem Computer brauch.

1

D'MCP-Astellungen opmaachen

Gitt an TypingMind op „Astellungen“, „Erweidert Astellungen“, dann op „Model Context Protocol“ a wielt „Connector ariichten“.

  1. Maacht TypingMind an Ärem Browser op.
  2. Klickt op d'Astellungssymbol.
  3. Gitt op „Erweidert Astellungen“.
  4. Maacht d'Sektioun „Model Context Protocol“ op.
  5. Klickt op „Connector ariichten“ a wielt „Dësen Apparat“.
Ariichtungsbildschierm vum TypingMind-MCP-Connector mat „Dësen Apparat“ ausgewielt
2

De Connector-Befeel ausféieren

Wielt „Dësen Apparat“, kopéiert de Befeel aus TypingMind a féiert en am Terminal aus. Loosst de Prozess lafen, wärend Dir MCP benotzt.

  1. Kopéiert den Ariichtungsbefeel, deen TypingMind uweist.
  2. Maacht Terminal op macOS oder Windows Terminal op Windows op.
  3. Pescht de Befeel an a féiert en aus.
  4. Bestätegt d'Installatioun vum Package, wann den Terminal Iech freet, ob Dir weiderfuere wëllt.
  5. Loosst den Terminal an de Prozess doranner lafen, wärend Dir MCP-Tools benotzt.
3

AST MCP Server als Server derbäisetzen

Wann de Connector-Status „Prett“ ass, klickt op „Serveren änneren“ a pescht d'MCP-Serverkonfiguratioun an.

  1. Waart, bis de Connector-Status „Prett“ weist.
  2. Klickt op „Serveren änneren“.
  3. Pescht d'MCP-Serverkonfiguratioun vu AST MCP Server an.
  4. Späichert d'Serverlëscht.
  5. Aktualiséiert, wann Dir kontrolléiere wëllt, ob de Connector nach ëmmer prett ass.
MCP-Astellunge vun TypingMind mat aktivem Server an dem Knäppchen „Serveren änneren“
{
  "mcpServers": {
    "angrysky56-ast-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "ast-mcp-server"
      ]
    }
  }
}
4

D'Verbindung mat verschiddene Modeller benotzen

Späichert d'Serverlëscht, maacht „Plugins“ op an aktivéiert d'MCP-Tools vu AST MCP Server. Wielt dann e belibegen ënnerstëtzte KI-Modell an TypingMind a benotzt d'Tools am Chat oder weist se engem KI-Agent zou.

  1. Maacht d'Säit „Plugins“ an TypingMind op.
  2. Aktivéiert d'MCP-Tools vu AST MCP Server.
  3. Start e Chat a wielt de KI-Modell, deen Dir benotze wëllt.
  4. Benotzt d'MCP-Tools am Chat oder weist se engem KI-Agent zou.
  5. Wiesselt bei Bedarf op en anere KI-Modell, ouni MCP nei ze verbannen.
TypingMind-Chat mat aktivéierte MCP-Tools an engem ausgewielte KI-Modell
Hëlleft Dir mir bei dëser Aufgab mat AST MCP Server?
AST MCP Server
Jo. Ech hunn et gelies.
Dat hunn ech mat AST MCP Server fonnt.

Heefeg gestallte Froen

Fir wat gëtt de MCP-Server AST MCP Server benotzt?

AST MCP Server ass e MCP-Server, deen et kompatibele KI-Clienten erlaabt, sech mat externen Tools a Kontext ze verbannen. An TypingMind kënnt Dir dëse MCP-Server eemol derbäisetzen a seng Tools an Ärem KI-Aarbechtsberäich zur Verfügung stellen.

Kann ech AST MCP Server MCP mat méi KI-Modeller an TypingMind benotzen?

Jo. TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Sou kënnt Dir AST MCP Server mat verschiddene KI-Modeller wéi Claude, ChatGPT, Gemini oder anere Modeller benotzen, déi Dir an TypingMind konfiguréiert hutt, ouni de MCP-Server fir all Modell separat anzeriichten.

Firwat AST MCP Server MCP mat TypingMind benotzen?

TypingMind ass eng vun de beschte Benotzeruewerfläche fir LLM-Chat, well et méi KI-Modeller, Prompts, Plugins, KI-Agenten, API-Schlësselen a MCP-Tools an engem Aarbechtsberäich zesummebréngt. Wann AST MCP Server verbonnen ass, kënnt Dir seng MCP-Tools mat Äre bevorzugte Modeller benotzen a gläichzäiteg Är Chataarbecht an TypingMind organiséieren.

Wéi verbannen ech AST MCP Server MCP mat TypingMind?

AST MCP Server leeft iwwer de lokale MCP-Connector vun TypingMind. Dat eegent sech am beschten, wann de MCP-Server Zougrëff op lokal Fichieren, Desktop-Apps, Kommandozeilen-Tools oder privat Ressourcen op Ärem Computer brauch.

Wéi eng Tools stellt AST MCP Server MCP an TypingMind zur Verfügung?

AST MCP Server stellt MCP-Funktiounen zur Verfügung, déi Dir op der Plugins-Säit vun TypingMind aktivéiere kënnt, fir se am Chat ze benotzen oder KI-Agenten zouzeweisen.

Muss ech meng API-Schlëssele mat TypingMind deelen, fir AST MCP Server MCP ze benotzen?

Nee. TypingMind setzt op lokal Veraarbechtung a léisst Iech d'Kontroll iwwer Är Modellubidder, API-Schlësselen, Prompts a MCP-Konfiguratioun. Wann AST MCP Server eng Authentifizéierung verlaangt, setzt déi néideg Headeren, OAuth-Astellungen oder lokal Konfiguratioun fir dee MCP-Server derbäi, wann Dir d'Verbindung erstallt.

Änlech MCP-Serveren

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇