【技术文档摘要】
<a id="orgf542482"></a>
code-to-tree 服务器的目标是:
这些目标意味着:
截图:
<img src="./chathistory.png" width="450px" /><img src="./wholeast.png" width="200px" />
以上截图是通过在 q.md 中指定的问题获得的。
(重要提示:LLMs 对于相同问题生成完全相同的答案没有责任,你可能会得到完全不同风格或内容的结果。这里提供的截图或问题是仅供参考)
<a id="org862e7dc"></a>
首先,你需要在你的机器上安装 code-to-tree 可执行文件(Windows 上为 code-to-tree.exe,macOS 上为 code-to-tree),你可以从 GitHub 发布页面下载或自行编译。下载后,配置你的 MCP 客户端来安装它,详情请参阅“配置 MCP 客户端”部分。
<a id="orge54fa87"></a>
这里我们以 Claude 为例。
在你的 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" }
}
}
在你的 Claude 配置文件中(~/Library/Application Support/Claude/claude_desktop_config.json),指定 code-to-tree 的位置:
{
"mcpServers": {
"code-to-tree": { "command": "/path/to/code-to-tree" }
}
}
<a id="org48a8180"></a>
pacman -S make gcc git。这里我们需要编译并安装 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-s[...]
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
安装 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
<a id="orgbaa740e"></a>
这里我们需要编译并安装 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
安装 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