
通过将源代码转换为可查询语义图和结构化AST图,该工具弥合了“阅读文本”与“理解结构”之间的鸿沟。
概览
一个MCP(模型上下文协议)服务器,通过抽象语法树(AST)和抽象语义图(ASG)提供代码结构和语义分析能力。 - 将代码解析为抽象语法树(AST) - 从代码生成抽象语义图(ASG) - 分析代码结构和复杂性 - 支持多种编程语言(Python、JavaScript、TypeScript、Go、Rust、C/C++、Java) - 兼容 Claude Desktop 及其他 MCP 客户端 - 增量解析以加快大文件处理速度 - 增强范围处理和更完整的语义分析 - AST 差异化以识别代码版本间的变化 - 资源缓存以提升性能 - Python 3.9 或更高版本 - UV 包管理器(推荐)或 PIP 2. 安装项目及其依赖: 1. 通过编辑配置文件配置Claude Desktop以使用服务器: - macOS:~/Library/Application Support/claude-desktop/claude_desktop_config.json- Linux:~/。
概述(AI 翻译)
一个MCP(模型上下文协议)服务器,通过抽象语法树(AST)和抽象语义图(ASG)提供代码结构和语义分析能力。
特色
- 解析代码为抽象语法树(AST)
- 从代码生成抽象语义图(ASG)
- 分析代码结构和复杂性
- 支持多种编程语言(Python、JavaScript、TypeScript、Go、Rust、C/C++、Java)
- 兼容 Claude Desktop 及其他 MCP 客户端
- 增量解析以加快大文件处理速度
- 增强范围处理和更完整的语义分析
- AST 差分以识别代码版本间的变更
- 资源缓存以提升性能
安装
先决条件
- Python 3.9 或更高版本
- UV包管理器(推荐)或PIP
使用紫外线(推荐)
-
克隆此仓库:
-
安装项目及其依赖:
-
构建树置解析器:
使用点数(替代)
使用 Claude Desktop
- 通过编辑配置文件配置Claude Desktop以使用服务器:
配置文件位置:
- macOS:
~/Library/Application Support/claude-desktop/claude_desktop_config.json
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 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, 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:
git clone https://github.com/angrysky56/ast-mcp-server.git
cd ast-mcp-server
- Install the project and dependencies:
# 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
- Build the tree-sitter parsers:
uv run build-parsers
Using pip (Alternative)
# 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
- 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
- Add the AST MCP server configuration:
{
"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.
-
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
# 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:
# Using uv
uv run --extra dev -- -m mcp dev server.py
# Or using the development script
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"AstAnalyzer": {
"command": "uv",
"args": [
"--directory",
"/home/ty/Repositories/ai_workspace/ast-mcp-server/ast_mcp_server",
"run",
"server.py"
]
}
}
}