目录
MCP服务器:代码到树
树服务器目标的代码是:
- 赋予LLM以下能力 准确地 将源代码转换为
AST(抽象语法树),无论语言如何。
- 一 独立 二进制文件应该是MCP客户端所需的一切。
这些目标意味着:
- 底层语法分析器应该是 多才多艺的 够了。在这里我们
选择 树保姆,语言有:C、C++、Rust、Ruby、Go、Java、Python。
- 服务器应该能够承载其中的所有功能
本身,令人印象深刻 最小 软件对最终用户的依赖性 机器。在这里我们选择 多用途计算程序设计.
屏幕截图:
以上截图是通过询问指定问题获得的 在 q.md.
(重要提示:LLM不负责生成相同的 对于同一个问题,你可能会得到一个完全不同的结果 风格或内容。此处提供的截图或问题仅供参考)
使用代码树
在做任何事情之前,你需要有代码在你的 机器(code-to-tree.exe 对于Windows, code-to-tree 对于macOS), 你可以在GitHub上下载 页 或者自己建造。曾经 下载后,您可以配置MCP客户端来安装它,请查看部分 *“配置MCP客户端”* 了解更多详情。
配置MCP客户端
这里我们以克劳德为例。
视窗
在您的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" }
}
}建筑(窗户)
1.准备环境
- 下载并安装MSYS2。
- 开放式应用程序“MSYS2 MINGW64”
- 跑
pacman -S make gcc git
2.准备树木看护图书馆
在这里,我们需要编译和安装树保姆和所有相关语法。
克隆它们:
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 install3.构建代码树
安装mcpc:
git clone https://github.com/micl2e2/mcpc
cd mcpc && make install将代码编译成树:
cd mcpc/example/code-to-tree
CFLAGS="-I/usr/local/include -L/usr/local/lib" make
# Check the binary
file code-to-tree.exe
# Remember the binary's location
pwd
# Assume the output is: /c/path/to/code-to-tree.exe建筑(macOS)
1.准备环境
- Xcode 命令行工具
2.准备树木看护图书馆
在这里,我们需要编译和安装树保姆和所有相关语法。
克隆它们:
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 install3.构建代码树
安装mcpc:
git clone https://github.com/micl2e2/mcpc
cd mcpc && make install将代码编译成树:
cd mcpc/example/code-to-tree
make
# Check the binary
file ./code-to-tree
# Remember the binary's location
pwd
# Assume the output is: /path/to/code-to-tree