code-search-mcp 0.2.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.
- code_search_mcp-0.2.0/PKG-INFO +224 -0
- code_search_mcp-0.2.0/README.md +213 -0
- code_search_mcp-0.2.0/code_index_mcp/__init__.py +1 -0
- code_search_mcp-0.2.0/code_index_mcp/__main__.py +13 -0
- code_search_mcp-0.2.0/code_index_mcp/cli.py +340 -0
- code_search_mcp-0.2.0/code_index_mcp/database.py +407 -0
- code_search_mcp-0.2.0/code_index_mcp/indexer.py +267 -0
- code_search_mcp-0.2.0/code_index_mcp/logger.py +265 -0
- code_search_mcp-0.2.0/code_index_mcp/server.py +423 -0
- code_search_mcp-0.2.0/code_index_mcp/strategies.py +298 -0
- code_search_mcp-0.2.0/code_search_mcp.egg-info/PKG-INFO +224 -0
- code_search_mcp-0.2.0/code_search_mcp.egg-info/SOURCES.txt +22 -0
- code_search_mcp-0.2.0/code_search_mcp.egg-info/dependency_links.txt +1 -0
- code_search_mcp-0.2.0/code_search_mcp.egg-info/entry_points.txt +3 -0
- code_search_mcp-0.2.0/code_search_mcp.egg-info/requires.txt +5 -0
- code_search_mcp-0.2.0/code_search_mcp.egg-info/top_level.txt +1 -0
- code_search_mcp-0.2.0/pyproject.toml +34 -0
- code_search_mcp-0.2.0/setup.cfg +4 -0
- code_search_mcp-0.2.0/tests/test_benchmark.py +120 -0
- code_search_mcp-0.2.0/tests/test_indexer.py +81 -0
- code_search_mcp-0.2.0/tests/test_logger.py +187 -0
- code_search_mcp-0.2.0/tests/test_performance.py +178 -0
- code_search_mcp-0.2.0/tests/test_search.py +267 -0
- code_search_mcp-0.2.0/tests/test_sourcegraph_comparison.py +420 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code-search-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MCP server for indexing code repositories with SQLite
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: mcp>=1.0.0
|
|
8
|
+
Provides-Extra: dev
|
|
9
|
+
Requires-Dist: pytest; extra == "dev"
|
|
10
|
+
Requires-Dist: ruff; extra == "dev"
|
|
11
|
+
|
|
12
|
+
# Code Index MCP
|
|
13
|
+
|
|
14
|
+
基于 SQLite 的代码仓库索引 MCP 服务器
|
|
15
|
+
|
|
16
|
+
## 概述
|
|
17
|
+
|
|
18
|
+
Code Index MCP 是一个 MCP(Model Context Protocol)服务器,用于对代码仓库建立索引并提供强大的搜索能力。它使用 SQLite 存储索引数据,支持全文搜索(FTS5)、符号搜索和结构分析。
|
|
19
|
+
|
|
20
|
+
### 核心功能
|
|
21
|
+
|
|
22
|
+
- **代码索引**: 自动扫描代码仓库,提取文件、符号(函数、类、方法)和代码内容
|
|
23
|
+
- **全文搜索**: 基于 SQLite FTS5 的高速全文搜索
|
|
24
|
+
- **符号搜索**: 按名称搜索函数、类、方法等符号
|
|
25
|
+
- **可观测性**: 内置日志系统,记录所有工具调用和性能指标
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
### 安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install code-search-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 使用 MCP 客户端
|
|
36
|
+
|
|
37
|
+
配置你的 MCP 客户端(如 Claude Code):
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"code-index": {
|
|
43
|
+
"command": "python",
|
|
44
|
+
"args": ["-m", "code_index_mcp"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 基本使用
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from code_index_mcp import CodeIndexServer
|
|
54
|
+
|
|
55
|
+
server = CodeIndexServer()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## MCP 工具
|
|
59
|
+
|
|
60
|
+
本服务提供 8 个 MCP 工具:
|
|
61
|
+
|
|
62
|
+
### 1. index_repository
|
|
63
|
+
|
|
64
|
+
索引整个代码仓库。
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
{
|
|
68
|
+
"name": "index_repository",
|
|
69
|
+
"arguments": {
|
|
70
|
+
"repo_path": "/path/to/repo",
|
|
71
|
+
"force_rebuild": false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**参数**:
|
|
77
|
+
- `repo_path` (必填): 代码仓库路径
|
|
78
|
+
- `force_rebuild` (可选): 是否强制重建索引,默认 false
|
|
79
|
+
|
|
80
|
+
**返回**:
|
|
81
|
+
```python
|
|
82
|
+
{
|
|
83
|
+
"success": true,
|
|
84
|
+
"stats": {
|
|
85
|
+
"files_indexed": 150,
|
|
86
|
+
"symbols": 1200,
|
|
87
|
+
"content_blocks": 5000,
|
|
88
|
+
"elapsed_seconds": 2.5
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. find_files
|
|
94
|
+
|
|
95
|
+
按文件名或路径搜索文件。
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
{
|
|
99
|
+
"name": "find_files",
|
|
100
|
+
"arguments": {
|
|
101
|
+
"query": "test",
|
|
102
|
+
"extensions": [".py", ".js"],
|
|
103
|
+
"limit": 20
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 3. find_symbols
|
|
109
|
+
|
|
110
|
+
搜索代码符号(函数、类、方法等)。
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
{
|
|
114
|
+
"name": "find_symbols",
|
|
115
|
+
"arguments": {
|
|
116
|
+
"query": "calculate",
|
|
117
|
+
"kind": "function",
|
|
118
|
+
"limit": 20
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 4. find_content
|
|
124
|
+
|
|
125
|
+
在代码内容中进行全文搜索。
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
{
|
|
129
|
+
"name": "find_content",
|
|
130
|
+
"arguments": {
|
|
131
|
+
"query": "def.*main",
|
|
132
|
+
"regex": true,
|
|
133
|
+
"file_pattern": "*.py",
|
|
134
|
+
"limit": 20
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 5. get_structure
|
|
140
|
+
|
|
141
|
+
获取单个文件的结构信息。
|
|
142
|
+
|
|
143
|
+
### 6. get_stats
|
|
144
|
+
|
|
145
|
+
获取索引统计信息。
|
|
146
|
+
|
|
147
|
+
### 7. get_logs
|
|
148
|
+
|
|
149
|
+
查询工具调用日志(可观测性)。
|
|
150
|
+
|
|
151
|
+
### 8. get_call_stats
|
|
152
|
+
|
|
153
|
+
获取工具调用统计信息。
|
|
154
|
+
|
|
155
|
+
## 支持的语言
|
|
156
|
+
|
|
157
|
+
- Python (.py)
|
|
158
|
+
- JavaScript (.js, .jsx)
|
|
159
|
+
- TypeScript (.ts, .tsx)
|
|
160
|
+
- Go (.go)
|
|
161
|
+
- Rust (.rs)
|
|
162
|
+
- Java (.java)
|
|
163
|
+
- C/C++ (.c, .cpp, .h, .hpp)
|
|
164
|
+
- Ruby (.rb)
|
|
165
|
+
- PHP (.php)
|
|
166
|
+
- Swift (.swift)
|
|
167
|
+
- Kotlin (.kt)
|
|
168
|
+
- Scala (.scala)
|
|
169
|
+
- Vue (.vue)
|
|
170
|
+
- Svelte (.svelte)
|
|
171
|
+
|
|
172
|
+
## CLI 命令
|
|
173
|
+
|
|
174
|
+
安装后可以使用 CLI 工具:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# 索引代码仓库
|
|
178
|
+
code-index index /path/to/repo
|
|
179
|
+
|
|
180
|
+
# 重建索引
|
|
181
|
+
code-index rebuild /path/to/repo
|
|
182
|
+
|
|
183
|
+
# 综合搜索
|
|
184
|
+
code-index search "query"
|
|
185
|
+
|
|
186
|
+
# 搜索文件
|
|
187
|
+
code-index files "query"
|
|
188
|
+
|
|
189
|
+
# 搜索符号
|
|
190
|
+
code-index symbols "query"
|
|
191
|
+
|
|
192
|
+
# 搜索内容
|
|
193
|
+
code-index content "query"
|
|
194
|
+
|
|
195
|
+
# 查看日志
|
|
196
|
+
code-index logs
|
|
197
|
+
|
|
198
|
+
# 查看统计
|
|
199
|
+
code-index stats
|
|
200
|
+
|
|
201
|
+
# 查看状态
|
|
202
|
+
code-index status
|
|
203
|
+
|
|
204
|
+
# 清理数据
|
|
205
|
+
code-index clean --all
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 开发
|
|
209
|
+
|
|
210
|
+
### 运行测试
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
pytest tests/ -v
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 代码检查
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
ruff check code_index_mcp/
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## 许可证
|
|
223
|
+
|
|
224
|
+
MIT
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Code Index MCP
|
|
2
|
+
|
|
3
|
+
基于 SQLite 的代码仓库索引 MCP 服务器
|
|
4
|
+
|
|
5
|
+
## 概述
|
|
6
|
+
|
|
7
|
+
Code Index MCP 是一个 MCP(Model Context Protocol)服务器,用于对代码仓库建立索引并提供强大的搜索能力。它使用 SQLite 存储索引数据,支持全文搜索(FTS5)、符号搜索和结构分析。
|
|
8
|
+
|
|
9
|
+
### 核心功能
|
|
10
|
+
|
|
11
|
+
- **代码索引**: 自动扫描代码仓库,提取文件、符号(函数、类、方法)和代码内容
|
|
12
|
+
- **全文搜索**: 基于 SQLite FTS5 的高速全文搜索
|
|
13
|
+
- **符号搜索**: 按名称搜索函数、类、方法等符号
|
|
14
|
+
- **可观测性**: 内置日志系统,记录所有工具调用和性能指标
|
|
15
|
+
|
|
16
|
+
## 快速开始
|
|
17
|
+
|
|
18
|
+
### 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install code-search-mcp
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 使用 MCP 客户端
|
|
25
|
+
|
|
26
|
+
配置你的 MCP 客户端(如 Claude Code):
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"code-index": {
|
|
32
|
+
"command": "python",
|
|
33
|
+
"args": ["-m", "code_index_mcp"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 基本使用
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from code_index_mcp import CodeIndexServer
|
|
43
|
+
|
|
44
|
+
server = CodeIndexServer()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## MCP 工具
|
|
48
|
+
|
|
49
|
+
本服务提供 8 个 MCP 工具:
|
|
50
|
+
|
|
51
|
+
### 1. index_repository
|
|
52
|
+
|
|
53
|
+
索引整个代码仓库。
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
{
|
|
57
|
+
"name": "index_repository",
|
|
58
|
+
"arguments": {
|
|
59
|
+
"repo_path": "/path/to/repo",
|
|
60
|
+
"force_rebuild": false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**参数**:
|
|
66
|
+
- `repo_path` (必填): 代码仓库路径
|
|
67
|
+
- `force_rebuild` (可选): 是否强制重建索引,默认 false
|
|
68
|
+
|
|
69
|
+
**返回**:
|
|
70
|
+
```python
|
|
71
|
+
{
|
|
72
|
+
"success": true,
|
|
73
|
+
"stats": {
|
|
74
|
+
"files_indexed": 150,
|
|
75
|
+
"symbols": 1200,
|
|
76
|
+
"content_blocks": 5000,
|
|
77
|
+
"elapsed_seconds": 2.5
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 2. find_files
|
|
83
|
+
|
|
84
|
+
按文件名或路径搜索文件。
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
{
|
|
88
|
+
"name": "find_files",
|
|
89
|
+
"arguments": {
|
|
90
|
+
"query": "test",
|
|
91
|
+
"extensions": [".py", ".js"],
|
|
92
|
+
"limit": 20
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 3. find_symbols
|
|
98
|
+
|
|
99
|
+
搜索代码符号(函数、类、方法等)。
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
{
|
|
103
|
+
"name": "find_symbols",
|
|
104
|
+
"arguments": {
|
|
105
|
+
"query": "calculate",
|
|
106
|
+
"kind": "function",
|
|
107
|
+
"limit": 20
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 4. find_content
|
|
113
|
+
|
|
114
|
+
在代码内容中进行全文搜索。
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
{
|
|
118
|
+
"name": "find_content",
|
|
119
|
+
"arguments": {
|
|
120
|
+
"query": "def.*main",
|
|
121
|
+
"regex": true,
|
|
122
|
+
"file_pattern": "*.py",
|
|
123
|
+
"limit": 20
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 5. get_structure
|
|
129
|
+
|
|
130
|
+
获取单个文件的结构信息。
|
|
131
|
+
|
|
132
|
+
### 6. get_stats
|
|
133
|
+
|
|
134
|
+
获取索引统计信息。
|
|
135
|
+
|
|
136
|
+
### 7. get_logs
|
|
137
|
+
|
|
138
|
+
查询工具调用日志(可观测性)。
|
|
139
|
+
|
|
140
|
+
### 8. get_call_stats
|
|
141
|
+
|
|
142
|
+
获取工具调用统计信息。
|
|
143
|
+
|
|
144
|
+
## 支持的语言
|
|
145
|
+
|
|
146
|
+
- Python (.py)
|
|
147
|
+
- JavaScript (.js, .jsx)
|
|
148
|
+
- TypeScript (.ts, .tsx)
|
|
149
|
+
- Go (.go)
|
|
150
|
+
- Rust (.rs)
|
|
151
|
+
- Java (.java)
|
|
152
|
+
- C/C++ (.c, .cpp, .h, .hpp)
|
|
153
|
+
- Ruby (.rb)
|
|
154
|
+
- PHP (.php)
|
|
155
|
+
- Swift (.swift)
|
|
156
|
+
- Kotlin (.kt)
|
|
157
|
+
- Scala (.scala)
|
|
158
|
+
- Vue (.vue)
|
|
159
|
+
- Svelte (.svelte)
|
|
160
|
+
|
|
161
|
+
## CLI 命令
|
|
162
|
+
|
|
163
|
+
安装后可以使用 CLI 工具:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# 索引代码仓库
|
|
167
|
+
code-index index /path/to/repo
|
|
168
|
+
|
|
169
|
+
# 重建索引
|
|
170
|
+
code-index rebuild /path/to/repo
|
|
171
|
+
|
|
172
|
+
# 综合搜索
|
|
173
|
+
code-index search "query"
|
|
174
|
+
|
|
175
|
+
# 搜索文件
|
|
176
|
+
code-index files "query"
|
|
177
|
+
|
|
178
|
+
# 搜索符号
|
|
179
|
+
code-index symbols "query"
|
|
180
|
+
|
|
181
|
+
# 搜索内容
|
|
182
|
+
code-index content "query"
|
|
183
|
+
|
|
184
|
+
# 查看日志
|
|
185
|
+
code-index logs
|
|
186
|
+
|
|
187
|
+
# 查看统计
|
|
188
|
+
code-index stats
|
|
189
|
+
|
|
190
|
+
# 查看状态
|
|
191
|
+
code-index status
|
|
192
|
+
|
|
193
|
+
# 清理数据
|
|
194
|
+
code-index clean --all
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## 开发
|
|
198
|
+
|
|
199
|
+
### 运行测试
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
pytest tests/ -v
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 代码检查
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
ruff check code_index_mcp/
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 许可证
|
|
212
|
+
|
|
213
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Code Index MCP - 将本地代码库转换为SQLite索引,提供高效的混合搜索能力"""
|