README
🚀 MCP Server: code-to-tree
MCP Server: code-to-tree 项目致力于为大语言模型(LLMs)提供将源代码准确转换为抽象语法树(AST)的能力,并且只需一个独立的二进制文件就能满足 MCP 客户端的所有需求。
📚 目录
✨ 主要特性
项目目标
- 赋予大语言模型(LLMs)准确将源代码转换为抽象语法树(AST)的能力,且不受编程语言的限制。
- 让 MCP 客户端仅依赖一个独立的二进制文件。
实现方式
- 选择多功能的语法解析器:选用 tree-sitter 作为底层语法解析器,支持的语言包括 C、C++、Rust、Ruby、Go、Java 和 Python。
- 减少软件依赖:选择 mcpc,使服务器自身具备所有功能,将最终用户机器上的软件依赖降至最低。
截图展示
上述截图是通过询问 q.md 中指定的问题获得的。
⚠️ 重要提示
大语言模型(LLMs)对于相同问题不一定会生成完全相同的结果,你很可能会得到风格或内容完全不同的输出。这里提供的截图或问题仅作参考。
🚀 快速开始
在使用之前,你需要在本地机器上准备好 code-to-tree 可执行文件(Windows 系统为 code-to-tree.exe,macOS 系统为 code-to-tree)。你可以从 GitHub 发布 页面 下载,也可以自行构建。下载完成后,你需要配置 MCP 客户端以安装该文件,具体配置方法请参考 "配置 MCP 客户端" 部分。
🔧 配置 MCP 客户端
这里以 Claude 为例进行说明。
Windows 系统
在你的 Claude 配置文件(C:\Users\YOUR_NAME\AppData\Roaming\Claude\claude_desktop_config.json)中,指定 code-to-tree.exe 的位置:
{
"mcpServers": {
"code-to-tree": { "command": "C:\\path\\to\\code-to-tree.exe" }
}
}
macOS 系统
在你的 Claude 配置文件(~/Library/Application Support/Claude/claude_desktop_config.json)中,指定 code-to-tree 的位置:
{
"mcpServers": {
"code-to-tree": { "command": "/path/to/code-to-tree" }
}
}
📦 安装指南(Windows)
1. 准备环境
- 下载并安装 MSYS2。
- 打开 "MSYS2 MINGW64" 应用程序。
- 运行以下命令安装必要的工具:
pacman -S make gcc git
2. 准备 tree-sitter 库
克隆所需的仓库:
git clone https://github.com/tree-sitter/tree-sitter
git clone https://github.com/tree-sitter/tree-sitter-c
git clone https://github.com/tree-sitter/tree-sitter-cpp
git clone https://github.com/tree-sitter/tree-sitter-rust
git clone https://github.com/tree-sitter/tree-sitter-ruby
git clone https://github.com/tree-sitter/tree-sitter-go
git clone https://github.com/tree-sitter/tree-sitter-java
编译并安装这些库:
cd tree-sitter && OS=1 make install
cd tree-sitter-c && OS=1 make install
cd tree-sitter-cpp && OS=1 make install
cd tree-sitter-rust && OS=1 make install
cd tree-sitter-ruby && OS=1 make install
cd tree-sitter-go && OS=1 make install
cd tree-sitter-java && OS=1 make install
3. 构建 code-to-tree
安装 mcpc:
git clone https://github.com/micl2e2/mcpc
cd mcpc && make install
编译 code-to-tree:
cd mcpc/example/code-to-tree
CFLAGS="-I/usr/local/include -L/usr/local/lib" make
# 检查二进制文件
file code-to-tree.exe
# 记录二进制文件的位置
pwd
# 假设输出为:/c/path/to/code-to-tree.exe
📦 安装指南(macOS)
1. 准备环境
安装 Xcode Command Line Tools。
2. 准备 tree-sitter 库
克隆所需的仓库:
git clone https://github.com/tree-sitter/tree-sitter
git clone https://github.com/tree-sitter/tree-sitter-c
git clone https://github.com/tree-sitter/tree-sitter-cpp
git clone https://github.com/tree-sitter/tree-sitter-rust
git clone https://github.com/tree-sitter/tree-sitter-ruby
git clone https://github.com/tree-sitter/tree-sitter-go
git clone https://github.com/tree-sitter/tree-sitter-java
编译并安装这些库:
cd tree-sitter && make install
cd tree-sitter-c && make install
cd tree-sitter-cpp && make install
cd tree-sitter-rust && make install
cd tree-sitter-ruby && make install
cd tree-sitter-go && make install
cd tree-sitter-java && make install
3. 构建 code-to-tree
安装 mcpc:
git clone https://github.com/micl2e2/mcpc
cd mcpc && make install
编译 code-to-tree:
cd mcpc/example/code-to-tree
make
# 检查二进制文件
file ./code-to-tree
# 记录二进制文件的位置
pwd
# 假设输出为:/path/to/code-to-tree
Scan to join WeChat group