|
| 1 | + |
| 2 | +# Table of Contents |
| 3 | + |
| 4 | +- [MCP Server: code-to-tree](#orgf5248dc) |
| 5 | +- [Using code-to-tree](#orgcf66e47) |
| 6 | +- [Configure MCP Clients](#orgcd08e07) |
| 7 | +- [Building (Windows)](#org2850757) |
| 8 | +- [Building (macOS)](#org7635de0) |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +<a id="orgf5248dc"></a> |
| 13 | + |
| 14 | +# MCP Server: code-to-tree |
| 15 | + |
| 16 | +The code-to-tree server's goals are: |
| 17 | + |
| 18 | +1. Give LLMs the capability of **accurately** converting source code into |
| 19 | + AST(Abstract Syntax Tree), regardless of language. |
| 20 | +2. One **standalone** binary should be everything the MCP client needs. |
| 21 | + |
| 22 | +These goals imply: |
| 23 | + |
| 24 | +1. The underlying syntax parser should be **versatile** enough. Here we |
| 25 | + choose [tree-sitter](https://github.com/tree-sitter/tree-sitter), and languages are: C, C++, Rust, Ruby, Go, Java, Python. |
| 26 | +2. The server should be able to carry all capabilities within |
| 27 | + itself, imposing **minimum** software dependencies on the end user's |
| 28 | + machine. Here we choose [mcpc](https://github.com/micl2e2/mcpc). |
| 29 | + |
| 30 | +**Screenshots:** |
| 31 | + |
| 32 | +<img src="./chathistory.png" width="450px" /><img src="./wholeast.png" width="200px" /> |
| 33 | + |
| 34 | +The above screenshots are obtained by asking the question specified |
| 35 | +in `q.md`. |
| 36 | + |
| 37 | +(**IMPORTANT NOTE**: LLMs have no responsibility of generating the identical |
| 38 | +result for the same question, you will likely get a completely different |
| 39 | +style or content. The screenshots or questions provided here are just for the reference) |
| 40 | + |
| 41 | + |
| 42 | +<a id="orgcf66e47"></a> |
| 43 | + |
| 44 | +# Using code-to-tree |
| 45 | + |
| 46 | +Before everthing, you need to have the code-to-tree executable on your |
| 47 | +machine (`code-to-tree.exe` for Windows, `code-to-tree` for macOS), |
| 48 | +you can download from Github release page or build it yourself. Once |
| 49 | +downloaded, you configure your MCP clients to install it, check the section |
| 50 | +*"Configure MCP Clients"* for more details. |
| 51 | + |
| 52 | + |
| 53 | +<a id="orgcd08e07"></a> |
| 54 | + |
| 55 | +# Configure MCP Clients |
| 56 | + |
| 57 | +Here we use Claude as the example. |
| 58 | + |
| 59 | + |
| 60 | +## Windows |
| 61 | + |
| 62 | +In your Claude configuration |
| 63 | +(`C:\Users\YOUR_NAME\AppData\Roaming\Claude\claude_desktop_config.json`), |
| 64 | +specify the location of `code-to-tree.exe`: |
| 65 | + |
| 66 | + { |
| 67 | + "mcpServers": { |
| 68 | + "code-to-tree": { "command": "C:\\path\\to\\code-to-tree.exe" } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | +## macOS |
| 74 | + |
| 75 | +In your Claude configuration, |
| 76 | +(`~/Library/Application Support/Claude/claude_desktop_config.json`) |
| 77 | +specify the location of `code-to-tree` |
| 78 | + |
| 79 | + { |
| 80 | + "mcpServers": { |
| 81 | + "code-to-tree": { "command": "/path/to/code-to-tree" } |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | +<a id="org2850757"></a> |
| 87 | + |
| 88 | +# Building (Windows) |
| 89 | + |
| 90 | + |
| 91 | +## 1. Prepare environment |
| 92 | + |
| 93 | +1. download & install MSYS2. |
| 94 | +2. open application "MSYS2 MINGW64" |
| 95 | +3. run `pacman -S make gcc git` |
| 96 | + |
| 97 | + |
| 98 | +## 2. Prepare tree-sitter libraries |
| 99 | + |
| 100 | +Here we need to compile and install tree-sitter and all related grammars. |
| 101 | + |
| 102 | +Clone them: |
| 103 | + |
| 104 | + git clone https://github.com/tree-sitter/tree-sitter |
| 105 | + |
| 106 | + git clone https://github.com/tree-sitter/tree-sitter-c |
| 107 | + |
| 108 | + git clone https://github.com/tree-sitter/tree-sitter-cpp |
| 109 | + |
| 110 | + git clone https://github.com/tree-sitter/tree-sitter-rust |
| 111 | + |
| 112 | + git clone https://github.com/tree-sitter/tree-sitter-ruby |
| 113 | + |
| 114 | + git clone https://github.com/tree-sitter/tree-sitter-go |
| 115 | + |
| 116 | + git clone https://github.com/tree-sitter/tree-sitter-java |
| 117 | + |
| 118 | +Compile and install them: |
| 119 | + |
| 120 | + cd tree-sitter && OS=1 make install |
| 121 | + |
| 122 | + cd tree-sitter-c && OS=1 make install |
| 123 | + |
| 124 | + cd tree-sitter-cpp && OS=1 make install |
| 125 | + |
| 126 | + cd tree-sitter-rust && OS=1 make install |
| 127 | + |
| 128 | + cd tree-sitter-ruby && OS=1 make install |
| 129 | + |
| 130 | + cd tree-sitter-go && OS=1 make install |
| 131 | + |
| 132 | + cd tree-sitter-java && OS=1 make install |
| 133 | + |
| 134 | + |
| 135 | +## 3. Build code-to-tree |
| 136 | + |
| 137 | +Install mcpc: |
| 138 | + |
| 139 | + git clone https://github.com/micl2e2/mcpc |
| 140 | + cd mcpc && make install |
| 141 | + |
| 142 | +Compile code-to-tree: |
| 143 | + |
| 144 | + cd mcpc/example/code-to-tree |
| 145 | + |
| 146 | + CFLAGS="-I/usr/local/include -L/usr/local/lib" make |
| 147 | + |
| 148 | + # Check the binary |
| 149 | + file code-to-tree.exe |
| 150 | + |
| 151 | + # Remember the binary's location |
| 152 | + pwd |
| 153 | + # Assume the output is: /c/path/to/code-to-tree.exe |
| 154 | + |
| 155 | + |
| 156 | +<a id="org7635de0"></a> |
| 157 | + |
| 158 | +# Building (macOS) |
| 159 | + |
| 160 | + |
| 161 | +## 1. Prepare environment |
| 162 | + |
| 163 | +1. Xcode Command Line Tools |
| 164 | + |
| 165 | + |
| 166 | +## 2. Prepare tree-sitter libraries |
| 167 | + |
| 168 | +Here we need to compile and install tree-sitter and all related grammars. |
| 169 | + |
| 170 | +Clone them: |
| 171 | + |
| 172 | + git clone https://github.com/tree-sitter/tree-sitter |
| 173 | + |
| 174 | + git clone https://github.com/tree-sitter/tree-sitter-c |
| 175 | + |
| 176 | + git clone https://github.com/tree-sitter/tree-sitter-cpp |
| 177 | + |
| 178 | + git clone https://github.com/tree-sitter/tree-sitter-rust |
| 179 | + |
| 180 | + git clone https://github.com/tree-sitter/tree-sitter-ruby |
| 181 | + |
| 182 | + git clone https://github.com/tree-sitter/tree-sitter-go |
| 183 | + |
| 184 | + git clone https://github.com/tree-sitter/tree-sitter-java |
| 185 | + |
| 186 | +Compile and install them: |
| 187 | + |
| 188 | + cd tree-sitter && make install |
| 189 | + |
| 190 | + cd tree-sitter-c && make install |
| 191 | + |
| 192 | + cd tree-sitter-cpp && make install |
| 193 | + |
| 194 | + cd tree-sitter-rust && make install |
| 195 | + |
| 196 | + cd tree-sitter-ruby && make install |
| 197 | + |
| 198 | + cd tree-sitter-go && make install |
| 199 | + |
| 200 | + cd tree-sitter-java && make install |
| 201 | + |
| 202 | + |
| 203 | +## 3. Build code-to-tree |
| 204 | + |
| 205 | +Install mcpc: |
| 206 | + |
| 207 | + git clone https://github.com/micl2e2/mcpc |
| 208 | + cd mcpc && make install |
| 209 | + |
| 210 | +Compile code-to-tree: |
| 211 | + |
| 212 | + cd mcpc/example/code-to-tree |
| 213 | + |
| 214 | + make |
| 215 | + |
| 216 | + # Check the binary |
| 217 | + file ./code-to-tree |
| 218 | + |
| 219 | + # Remember the binary's location |
| 220 | + pwd |
| 221 | + # Assume the output is: /path/to/code-to-tree |
| 222 | + |
0 commit comments