codetree-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codetree_mcp-0.1.0/LICENSE +21 -0
- codetree_mcp-0.1.0/PKG-INFO +81 -0
- codetree_mcp-0.1.0/README.md +60 -0
- codetree_mcp-0.1.0/pyproject.toml +36 -0
- codetree_mcp-0.1.0/setup.cfg +4 -0
- codetree_mcp-0.1.0/src/codetree_mcp/__init__.py +6 -0
- codetree_mcp-0.1.0/src/codetree_mcp/server.py +360 -0
- codetree_mcp-0.1.0/src/codetree_mcp.egg-info/PKG-INFO +81 -0
- codetree_mcp-0.1.0/src/codetree_mcp.egg-info/SOURCES.txt +11 -0
- codetree_mcp-0.1.0/src/codetree_mcp.egg-info/dependency_links.txt +1 -0
- codetree_mcp-0.1.0/src/codetree_mcp.egg-info/entry_points.txt +2 -0
- codetree_mcp-0.1.0/src/codetree_mcp.egg-info/requires.txt +1 -0
- codetree_mcp-0.1.0/src/codetree_mcp.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tony
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codetree-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP Server for CodeTree - Query code repositories from Claude Desktop and other MCP clients
|
|
5
|
+
Author-email: Tony <1094086026@qq.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/toller892/Oh-Code-Rag
|
|
8
|
+
Project-URL: Repository, https://github.com/toller892/Oh-Code-Rag
|
|
9
|
+
Keywords: mcp,codetree,rag,code,claude,llm
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: codetree-rag>=0.1.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# CodeTree MCP Server
|
|
23
|
+
|
|
24
|
+
MCP (Model Context Protocol) server for CodeTree. Query code repositories using natural language from Claude Desktop, Cline, Continue, and other MCP-compatible clients.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install codetree-mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Setup for Claude Desktop
|
|
33
|
+
|
|
34
|
+
Add to your Claude Desktop config:
|
|
35
|
+
|
|
36
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
37
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"codetree": {
|
|
43
|
+
"command": "codetree-mcp",
|
|
44
|
+
"env": {
|
|
45
|
+
"OPENAI_API_KEY": "sk-your-key-here"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Restart Claude Desktop after configuration.
|
|
53
|
+
|
|
54
|
+
## Available Tools
|
|
55
|
+
|
|
56
|
+
| Tool | Description |
|
|
57
|
+
|------|-------------|
|
|
58
|
+
| `codetree_index` | Index a repository (required before other operations) |
|
|
59
|
+
| `codetree_query` | Ask natural language questions about code |
|
|
60
|
+
| `codetree_tree` | Show the hierarchical code structure |
|
|
61
|
+
| `codetree_find` | Find all references to a symbol |
|
|
62
|
+
| `codetree_stats` | Get repository statistics |
|
|
63
|
+
|
|
64
|
+
## Usage in Claude
|
|
65
|
+
|
|
66
|
+
Once configured, ask Claude:
|
|
67
|
+
|
|
68
|
+
- "Use codetree to index /path/to/my/project"
|
|
69
|
+
- "Query the codebase: how does authentication work?"
|
|
70
|
+
- "Show me the code structure"
|
|
71
|
+
- "Find all references to UserService"
|
|
72
|
+
|
|
73
|
+
## Requirements
|
|
74
|
+
|
|
75
|
+
- Python 3.10+
|
|
76
|
+
- OpenAI or Anthropic API key (for LLM queries)
|
|
77
|
+
|
|
78
|
+
## Links
|
|
79
|
+
|
|
80
|
+
- [CodeTree Main Package](https://pypi.org/project/codetree-rag/)
|
|
81
|
+
- [GitHub Repository](https://github.com/toller892/Oh-Code-Rag)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# CodeTree MCP Server
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) server for CodeTree. Query code repositories using natural language from Claude Desktop, Cline, Continue, and other MCP-compatible clients.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install codetree-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup for Claude Desktop
|
|
12
|
+
|
|
13
|
+
Add to your Claude Desktop config:
|
|
14
|
+
|
|
15
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
16
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"mcpServers": {
|
|
21
|
+
"codetree": {
|
|
22
|
+
"command": "codetree-mcp",
|
|
23
|
+
"env": {
|
|
24
|
+
"OPENAI_API_KEY": "sk-your-key-here"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Restart Claude Desktop after configuration.
|
|
32
|
+
|
|
33
|
+
## Available Tools
|
|
34
|
+
|
|
35
|
+
| Tool | Description |
|
|
36
|
+
|------|-------------|
|
|
37
|
+
| `codetree_index` | Index a repository (required before other operations) |
|
|
38
|
+
| `codetree_query` | Ask natural language questions about code |
|
|
39
|
+
| `codetree_tree` | Show the hierarchical code structure |
|
|
40
|
+
| `codetree_find` | Find all references to a symbol |
|
|
41
|
+
| `codetree_stats` | Get repository statistics |
|
|
42
|
+
|
|
43
|
+
## Usage in Claude
|
|
44
|
+
|
|
45
|
+
Once configured, ask Claude:
|
|
46
|
+
|
|
47
|
+
- "Use codetree to index /path/to/my/project"
|
|
48
|
+
- "Query the codebase: how does authentication work?"
|
|
49
|
+
- "Show me the code structure"
|
|
50
|
+
- "Find all references to UserService"
|
|
51
|
+
|
|
52
|
+
## Requirements
|
|
53
|
+
|
|
54
|
+
- Python 3.10+
|
|
55
|
+
- OpenAI or Anthropic API key (for LLM queries)
|
|
56
|
+
|
|
57
|
+
## Links
|
|
58
|
+
|
|
59
|
+
- [CodeTree Main Package](https://pypi.org/project/codetree-rag/)
|
|
60
|
+
- [GitHub Repository](https://github.com/toller892/Oh-Code-Rag)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "codetree-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MCP Server for CodeTree - Query code repositories from Claude Desktop and other MCP clients"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Tony", email = "1094086026@qq.com"}
|
|
13
|
+
]
|
|
14
|
+
keywords = ["mcp", "codetree", "rag", "code", "claude", "llm"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
]
|
|
23
|
+
requires-python = ">=3.10"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"codetree-rag>=0.1.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
codetree-mcp = "codetree_mcp.server:main"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/toller892/Oh-Code-Rag"
|
|
33
|
+
Repository = "https://github.com/toller892/Oh-Code-Rag"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
CodeTree MCP Server
|
|
4
|
+
|
|
5
|
+
Model Context Protocol server for CodeTree - enables any MCP-compatible
|
|
6
|
+
AI assistant (Claude Desktop, etc.) to query code repositories.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import sys
|
|
11
|
+
import asyncio
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, Optional
|
|
14
|
+
|
|
15
|
+
# MCP Protocol Implementation
|
|
16
|
+
class MCPServer:
|
|
17
|
+
"""Simple MCP Server implementation for CodeTree."""
|
|
18
|
+
|
|
19
|
+
def __init__(self):
|
|
20
|
+
self.codetree_instances = {} # repo_path -> CodeTree instance
|
|
21
|
+
|
|
22
|
+
async def handle_request(self, request: dict) -> dict:
|
|
23
|
+
"""Handle incoming MCP request."""
|
|
24
|
+
method = request.get("method", "")
|
|
25
|
+
params = request.get("params", {})
|
|
26
|
+
request_id = request.get("id")
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
if method == "initialize":
|
|
30
|
+
result = await self.handle_initialize(params)
|
|
31
|
+
elif method == "tools/list":
|
|
32
|
+
result = await self.handle_tools_list()
|
|
33
|
+
elif method == "tools/call":
|
|
34
|
+
result = await self.handle_tools_call(params)
|
|
35
|
+
elif method == "shutdown":
|
|
36
|
+
result = {}
|
|
37
|
+
else:
|
|
38
|
+
return self.error_response(request_id, -32601, f"Unknown method: {method}")
|
|
39
|
+
|
|
40
|
+
return self.success_response(request_id, result)
|
|
41
|
+
except Exception as e:
|
|
42
|
+
return self.error_response(request_id, -32603, str(e))
|
|
43
|
+
|
|
44
|
+
async def handle_initialize(self, params: dict) -> dict:
|
|
45
|
+
"""Handle initialize request."""
|
|
46
|
+
return {
|
|
47
|
+
"protocolVersion": "2024-11-05",
|
|
48
|
+
"capabilities": {
|
|
49
|
+
"tools": {}
|
|
50
|
+
},
|
|
51
|
+
"serverInfo": {
|
|
52
|
+
"name": "codetree-mcp",
|
|
53
|
+
"version": "0.1.0"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async def handle_tools_list(self) -> dict:
|
|
58
|
+
"""Return list of available tools."""
|
|
59
|
+
return {
|
|
60
|
+
"tools": [
|
|
61
|
+
{
|
|
62
|
+
"name": "codetree_index",
|
|
63
|
+
"description": "Index a code repository for querying. Must be called before other operations on a new repo.",
|
|
64
|
+
"inputSchema": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"properties": {
|
|
67
|
+
"repo_path": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "Absolute path to the repository to index"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"required": ["repo_path"]
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "codetree_query",
|
|
77
|
+
"description": "Ask a natural language question about a code repository. The repo must be indexed first.",
|
|
78
|
+
"inputSchema": {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"properties": {
|
|
81
|
+
"repo_path": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"description": "Absolute path to the repository"
|
|
84
|
+
},
|
|
85
|
+
"question": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"description": "Natural language question about the code"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"required": ["repo_path", "question"]
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "codetree_tree",
|
|
95
|
+
"description": "Show the hierarchical structure of a code repository.",
|
|
96
|
+
"inputSchema": {
|
|
97
|
+
"type": "object",
|
|
98
|
+
"properties": {
|
|
99
|
+
"repo_path": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"description": "Absolute path to the repository"
|
|
102
|
+
},
|
|
103
|
+
"max_depth": {
|
|
104
|
+
"type": "integer",
|
|
105
|
+
"description": "Maximum depth to display (default: 3)",
|
|
106
|
+
"default": 3
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"required": ["repo_path"]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "codetree_find",
|
|
114
|
+
"description": "Find all references to a symbol (function, class, variable) in the codebase.",
|
|
115
|
+
"inputSchema": {
|
|
116
|
+
"type": "object",
|
|
117
|
+
"properties": {
|
|
118
|
+
"repo_path": {
|
|
119
|
+
"type": "string",
|
|
120
|
+
"description": "Absolute path to the repository"
|
|
121
|
+
},
|
|
122
|
+
"symbol": {
|
|
123
|
+
"type": "string",
|
|
124
|
+
"description": "Symbol name to search for"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"required": ["repo_path", "symbol"]
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"name": "codetree_stats",
|
|
132
|
+
"description": "Get statistics about an indexed repository.",
|
|
133
|
+
"inputSchema": {
|
|
134
|
+
"type": "object",
|
|
135
|
+
"properties": {
|
|
136
|
+
"repo_path": {
|
|
137
|
+
"type": "string",
|
|
138
|
+
"description": "Absolute path to the repository"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"required": ["repo_path"]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async def handle_tools_call(self, params: dict) -> dict:
|
|
148
|
+
"""Handle tool invocation."""
|
|
149
|
+
tool_name = params.get("name", "")
|
|
150
|
+
arguments = params.get("arguments", {})
|
|
151
|
+
|
|
152
|
+
# Lazy import to avoid startup overhead
|
|
153
|
+
from codetree import CodeTree
|
|
154
|
+
|
|
155
|
+
repo_path = arguments.get("repo_path", "")
|
|
156
|
+
|
|
157
|
+
if tool_name == "codetree_index":
|
|
158
|
+
return await self.tool_index(repo_path)
|
|
159
|
+
elif tool_name == "codetree_query":
|
|
160
|
+
question = arguments.get("question", "")
|
|
161
|
+
return await self.tool_query(repo_path, question)
|
|
162
|
+
elif tool_name == "codetree_tree":
|
|
163
|
+
max_depth = arguments.get("max_depth", 3)
|
|
164
|
+
return await self.tool_tree(repo_path, max_depth)
|
|
165
|
+
elif tool_name == "codetree_find":
|
|
166
|
+
symbol = arguments.get("symbol", "")
|
|
167
|
+
return await self.tool_find(repo_path, symbol)
|
|
168
|
+
elif tool_name == "codetree_stats":
|
|
169
|
+
return await self.tool_stats(repo_path)
|
|
170
|
+
else:
|
|
171
|
+
raise ValueError(f"Unknown tool: {tool_name}")
|
|
172
|
+
|
|
173
|
+
def get_codetree(self, repo_path: str):
|
|
174
|
+
"""Get or create CodeTree instance for a repo."""
|
|
175
|
+
from codetree import CodeTree
|
|
176
|
+
|
|
177
|
+
repo_path = str(Path(repo_path).resolve())
|
|
178
|
+
|
|
179
|
+
if repo_path not in self.codetree_instances:
|
|
180
|
+
self.codetree_instances[repo_path] = CodeTree(repo_path)
|
|
181
|
+
|
|
182
|
+
return self.codetree_instances[repo_path]
|
|
183
|
+
|
|
184
|
+
async def tool_index(self, repo_path: str) -> dict:
|
|
185
|
+
"""Index a repository."""
|
|
186
|
+
tree = self.get_codetree(repo_path)
|
|
187
|
+
index = tree.build_index()
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
"content": [
|
|
191
|
+
{
|
|
192
|
+
"type": "text",
|
|
193
|
+
"text": f"✅ Indexed repository: {repo_path}\n\n"
|
|
194
|
+
f"- Files: {index.total_files}\n"
|
|
195
|
+
f"- Lines: {index.total_lines:,}\n"
|
|
196
|
+
f"- Languages: {', '.join(index.languages.keys())}"
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async def tool_query(self, repo_path: str, question: str) -> dict:
|
|
202
|
+
"""Query a repository."""
|
|
203
|
+
tree = self.get_codetree(repo_path)
|
|
204
|
+
|
|
205
|
+
# Auto-index if needed
|
|
206
|
+
if tree.index is None:
|
|
207
|
+
tree.build_index()
|
|
208
|
+
|
|
209
|
+
answer = tree.query(question)
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
"content": [
|
|
213
|
+
{
|
|
214
|
+
"type": "text",
|
|
215
|
+
"text": answer
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async def tool_tree(self, repo_path: str, max_depth: int = 3) -> dict:
|
|
221
|
+
"""Show repository tree."""
|
|
222
|
+
tree = self.get_codetree(repo_path)
|
|
223
|
+
|
|
224
|
+
if tree.index is None:
|
|
225
|
+
tree.build_index()
|
|
226
|
+
|
|
227
|
+
tree_str = tree.tree(max_depth=max_depth)
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
"content": [
|
|
231
|
+
{
|
|
232
|
+
"type": "text",
|
|
233
|
+
"text": f"🌲 Code Tree: {Path(repo_path).name}\n\n{tree_str}"
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async def tool_find(self, repo_path: str, symbol: str) -> dict:
|
|
239
|
+
"""Find symbol references."""
|
|
240
|
+
tree = self.get_codetree(repo_path)
|
|
241
|
+
|
|
242
|
+
if tree.index is None:
|
|
243
|
+
tree.build_index()
|
|
244
|
+
|
|
245
|
+
refs = tree.find(symbol)
|
|
246
|
+
|
|
247
|
+
if not refs:
|
|
248
|
+
text = f"No references found for '{symbol}'"
|
|
249
|
+
else:
|
|
250
|
+
lines = [f"📍 Found {len(refs)} references to '{symbol}':\n"]
|
|
251
|
+
for ref in refs:
|
|
252
|
+
if ref["type"] == "import":
|
|
253
|
+
lines.append(f" [import] {ref['file']}: {ref['statement']}")
|
|
254
|
+
else:
|
|
255
|
+
line_info = f":{ref['line']}" if ref.get('line') else ""
|
|
256
|
+
lines.append(f" [{ref['type']:8}] {ref['file']}{line_info} → {ref['name']}")
|
|
257
|
+
text = "\n".join(lines)
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
"content": [
|
|
261
|
+
{
|
|
262
|
+
"type": "text",
|
|
263
|
+
"text": text
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async def tool_stats(self, repo_path: str) -> dict:
|
|
269
|
+
"""Get repository stats."""
|
|
270
|
+
tree = self.get_codetree(repo_path)
|
|
271
|
+
|
|
272
|
+
if tree.index is None:
|
|
273
|
+
tree.build_index()
|
|
274
|
+
|
|
275
|
+
stats = tree.stats()
|
|
276
|
+
|
|
277
|
+
lang_lines = "\n".join(f" - {lang}: {count} files"
|
|
278
|
+
for lang, count in stats['languages'].items())
|
|
279
|
+
|
|
280
|
+
text = (f"📊 Repository Statistics\n\n"
|
|
281
|
+
f"Path: {stats['repo_path']}\n"
|
|
282
|
+
f"Files: {stats['total_files']}\n"
|
|
283
|
+
f"Lines: {stats['total_lines']:,}\n\n"
|
|
284
|
+
f"Languages:\n{lang_lines}")
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
"content": [
|
|
288
|
+
{
|
|
289
|
+
"type": "text",
|
|
290
|
+
"text": text
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
def success_response(self, request_id: Any, result: dict) -> dict:
|
|
296
|
+
"""Create success response."""
|
|
297
|
+
return {
|
|
298
|
+
"jsonrpc": "2.0",
|
|
299
|
+
"id": request_id,
|
|
300
|
+
"result": result
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
def error_response(self, request_id: Any, code: int, message: str) -> dict:
|
|
304
|
+
"""Create error response."""
|
|
305
|
+
return {
|
|
306
|
+
"jsonrpc": "2.0",
|
|
307
|
+
"id": request_id,
|
|
308
|
+
"error": {
|
|
309
|
+
"code": code,
|
|
310
|
+
"message": message
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def main():
|
|
316
|
+
"""Entry point for codetree-mcp command."""
|
|
317
|
+
asyncio.run(_async_main())
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
async def _async_main():
|
|
321
|
+
"""Async main entry point - runs MCP server over stdio."""
|
|
322
|
+
server = MCPServer()
|
|
323
|
+
|
|
324
|
+
# Read from stdin, write to stdout
|
|
325
|
+
reader = asyncio.StreamReader()
|
|
326
|
+
protocol = asyncio.StreamReaderProtocol(reader)
|
|
327
|
+
await asyncio.get_event_loop().connect_read_pipe(lambda: protocol, sys.stdin)
|
|
328
|
+
|
|
329
|
+
writer_transport, writer_protocol = await asyncio.get_event_loop().connect_write_pipe(
|
|
330
|
+
asyncio.streams.FlowControlMixin, sys.stdout
|
|
331
|
+
)
|
|
332
|
+
writer = asyncio.StreamWriter(writer_transport, writer_protocol, reader, asyncio.get_event_loop())
|
|
333
|
+
|
|
334
|
+
while True:
|
|
335
|
+
try:
|
|
336
|
+
header = await reader.readline()
|
|
337
|
+
if not header:
|
|
338
|
+
break
|
|
339
|
+
|
|
340
|
+
if header.strip() == b"":
|
|
341
|
+
continue
|
|
342
|
+
|
|
343
|
+
if header.startswith(b"Content-Length:"):
|
|
344
|
+
content_length = int(header.decode().split(":")[1].strip())
|
|
345
|
+
await reader.readline()
|
|
346
|
+
content = await reader.read(content_length)
|
|
347
|
+
request = json.loads(content.decode())
|
|
348
|
+
response = await server.handle_request(request)
|
|
349
|
+
response_bytes = json.dumps(response).encode()
|
|
350
|
+
writer.write(f"Content-Length: {len(response_bytes)}\r\n\r\n".encode())
|
|
351
|
+
writer.write(response_bytes)
|
|
352
|
+
await writer.drain()
|
|
353
|
+
|
|
354
|
+
except Exception as e:
|
|
355
|
+
sys.stderr.write(f"Error: {e}\n")
|
|
356
|
+
break
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
if __name__ == "__main__":
|
|
360
|
+
main()
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codetree-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP Server for CodeTree - Query code repositories from Claude Desktop and other MCP clients
|
|
5
|
+
Author-email: Tony <1094086026@qq.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/toller892/Oh-Code-Rag
|
|
8
|
+
Project-URL: Repository, https://github.com/toller892/Oh-Code-Rag
|
|
9
|
+
Keywords: mcp,codetree,rag,code,claude,llm
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: codetree-rag>=0.1.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# CodeTree MCP Server
|
|
23
|
+
|
|
24
|
+
MCP (Model Context Protocol) server for CodeTree. Query code repositories using natural language from Claude Desktop, Cline, Continue, and other MCP-compatible clients.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install codetree-mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Setup for Claude Desktop
|
|
33
|
+
|
|
34
|
+
Add to your Claude Desktop config:
|
|
35
|
+
|
|
36
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
37
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"codetree": {
|
|
43
|
+
"command": "codetree-mcp",
|
|
44
|
+
"env": {
|
|
45
|
+
"OPENAI_API_KEY": "sk-your-key-here"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Restart Claude Desktop after configuration.
|
|
53
|
+
|
|
54
|
+
## Available Tools
|
|
55
|
+
|
|
56
|
+
| Tool | Description |
|
|
57
|
+
|------|-------------|
|
|
58
|
+
| `codetree_index` | Index a repository (required before other operations) |
|
|
59
|
+
| `codetree_query` | Ask natural language questions about code |
|
|
60
|
+
| `codetree_tree` | Show the hierarchical code structure |
|
|
61
|
+
| `codetree_find` | Find all references to a symbol |
|
|
62
|
+
| `codetree_stats` | Get repository statistics |
|
|
63
|
+
|
|
64
|
+
## Usage in Claude
|
|
65
|
+
|
|
66
|
+
Once configured, ask Claude:
|
|
67
|
+
|
|
68
|
+
- "Use codetree to index /path/to/my/project"
|
|
69
|
+
- "Query the codebase: how does authentication work?"
|
|
70
|
+
- "Show me the code structure"
|
|
71
|
+
- "Find all references to UserService"
|
|
72
|
+
|
|
73
|
+
## Requirements
|
|
74
|
+
|
|
75
|
+
- Python 3.10+
|
|
76
|
+
- OpenAI or Anthropic API key (for LLM queries)
|
|
77
|
+
|
|
78
|
+
## Links
|
|
79
|
+
|
|
80
|
+
- [CodeTree Main Package](https://pypi.org/project/codetree-rag/)
|
|
81
|
+
- [GitHub Repository](https://github.com/toller892/Oh-Code-Rag)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/codetree_mcp/__init__.py
|
|
5
|
+
src/codetree_mcp/server.py
|
|
6
|
+
src/codetree_mcp.egg-info/PKG-INFO
|
|
7
|
+
src/codetree_mcp.egg-info/SOURCES.txt
|
|
8
|
+
src/codetree_mcp.egg-info/dependency_links.txt
|
|
9
|
+
src/codetree_mcp.egg-info/entry_points.txt
|
|
10
|
+
src/codetree_mcp.egg-info/requires.txt
|
|
11
|
+
src/codetree_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
codetree-rag>=0.1.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
codetree_mcp
|