Skip to content

Commit fbc752d

Browse files
committed
doc: add readme
1 parent 19fe5fe commit fbc752d

13 files changed

+1084
-0
lines changed

.github/workflows/code-to-tree.yml

Whitespace-only changes.

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
unameall = $(shell uname -a)
3+
is_mingw = $(or $(findstring MINGW,$(unameall)))
4+
is_darwin = $(or $(findstring Darwin,$(unameall)))
5+
6+
ifneq (,$(is_mingw))
7+
CFLAGS += -I/usr/local/include
8+
CFLAGS += -L/usr/local/lib
9+
CFLAGS += -std=c23
10+
CFLAGS += -DMCPC_C23PTCH_UCHAR2
11+
endif
12+
ifneq (,$(is_darwin))
13+
CFLAGS += -std=c17
14+
CFLAGS += -DMCPC_C23PTCH_KW1
15+
CFLAGS += -DMCPC_C23PTCH_CKD1
16+
CFLAGS += -DMCPC_C23PTCH_UCHAR1
17+
endif
18+
19+
ifneq (,$(is_mingw))
20+
LDFLAGS += -Wl,-Bstatic
21+
LDFLAGS += -lmcpc
22+
LDFLAGS += -lws2_32
23+
LDFLAGS += -ltree-sitter
24+
LDFLAGS += -ltree-sitter-c
25+
LDFLAGS += -ltree-sitter-cpp
26+
LDFLAGS += -ltree-sitter-rust
27+
LDFLAGS += -ltree-sitter-go
28+
LDFLAGS += -ltree-sitter-python
29+
LDFLAGS += -ltree-sitter-ruby
30+
LDFLAGS += -ltree-sitter-java
31+
LDFLAGS += -Wl,-Bdynamic
32+
endif
33+
34+
ifneq (,$(is_darwin))
35+
LDFLAGS += /usr/local/lib/libmcpc.a
36+
LDFLAGS += /usr/local/lib/libtree-sitter.a
37+
LDFLAGS += /usr/local/lib/libtree-sitter-c.a
38+
LDFLAGS += /usr/local/lib/libtree-sitter-cpp.a
39+
LDFLAGS += /usr/local/lib/libtree-sitter-rust.a
40+
LDFLAGS += /usr/local/lib/libtree-sitter-go.a
41+
LDFLAGS += /usr/local/lib/libtree-sitter-python.a
42+
LDFLAGS += /usr/local/lib/libtree-sitter-ruby.a
43+
LDFLAGS += /usr/local/lib/libtree-sitter-java.a
44+
endif
45+
46+
.PHONY: code-to-tree
47+
48+
all: code-to-tree
49+
50+
code-to-tree:
51+
$(CC) $(CFLAGS) code-to-tree.c $(LDFLAGS) -o $@
52+

README.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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

Comments
 (0)