cocoindex-code 0.1.0__tar.gz → 0.1.2__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.
- cocoindex_code-0.1.2/PKG-INFO +331 -0
- cocoindex_code-0.1.2/README.md +298 -0
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/pyproject.toml +6 -3
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/src/cocoindex_code/config.py +2 -1
- cocoindex_code-0.1.2/src/cocoindex_code/indexer.py +145 -0
- cocoindex_code-0.1.2/src/cocoindex_code/server.py +208 -0
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/src/cocoindex_code/shared.py +19 -4
- cocoindex_code-0.1.0/PKG-INFO +0 -203
- cocoindex_code-0.1.0/README.md +0 -170
- cocoindex_code-0.1.0/src/cocoindex_code/indexer.py +0 -164
- cocoindex_code-0.1.0/src/cocoindex_code/server.py +0 -150
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/.gitignore +0 -0
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/src/cocoindex_code/__init__.py +0 -0
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/src/cocoindex_code/__main__.py +0 -0
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/src/cocoindex_code/query.py +0 -0
- {cocoindex_code-0.1.0 → cocoindex_code-0.1.2}/src/cocoindex_code/schema.py +0 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cocoindex-code
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: MCP server for indexing and querying codebases using CocoIndex
|
|
5
|
+
Project-URL: Homepage, https://github.com/cocoindex-io/cocoindex-code
|
|
6
|
+
Project-URL: Repository, https://github.com/cocoindex-io/cocoindex-code
|
|
7
|
+
Project-URL: Issues, https://github.com/cocoindex-io/cocoindex-code/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Keywords: cocoindex,codebase,indexing,mcp,vector-search
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: cocoindex[litellm]>=1.0.0a14
|
|
20
|
+
Requires-Dist: mcp>=1.0.0
|
|
21
|
+
Requires-Dist: numpy>=1.24.0
|
|
22
|
+
Requires-Dist: pydantic>=2.0.0
|
|
23
|
+
Requires-Dist: sentence-transformers>=2.2.0
|
|
24
|
+
Requires-Dist: sqlite-vec>=0.1.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: prek>=0.1.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# CocoIndex Code
|
|
35
|
+
|
|
36
|
+
An MCP (Model Context Protocol) server for indexing and querying codebases using [CocoIndex](https://cocoindex.io).
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Semantic Code Search**: Find relevant code using natural language queries
|
|
41
|
+
- **Incremental Indexing**: Only re-indexes changed files for fast updates
|
|
42
|
+
- **Multi-Language Support**: Python, JavaScript/TypeScript, Rust, Go, Java, C/C++, C#, SQL, Shell
|
|
43
|
+
- **Flexible Embeddings**: Local SentenceTransformers (default) or 100+ cloud providers via [LiteLLM](https://docs.litellm.ai/docs/embedding/supported_embedding)
|
|
44
|
+
- **SQLite Storage**: Portable, no external database required
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) (which provides `uvx`):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage with Claude Code
|
|
55
|
+
|
|
56
|
+
No installation needed — `uvx` runs it directly.
|
|
57
|
+
|
|
58
|
+
### Default (Local Embeddings)
|
|
59
|
+
|
|
60
|
+
Uses a local SentenceTransformers model (`sentence-transformers/all-MiniLM-L6-v2`). No API key required:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
claude mcp add cocoindex-code \
|
|
64
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### With a Cloud or Custom Embedding Model
|
|
68
|
+
|
|
69
|
+
Set `COCOINDEX_CODE_EMBEDDING_MODEL` to any [LiteLLM-supported model](https://docs.litellm.ai/docs/embedding/supported_embedding), along with the provider's API key:
|
|
70
|
+
|
|
71
|
+
<details>
|
|
72
|
+
<summary>Ollama (Local)</summary>
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
claude mcp add cocoindex-code \
|
|
76
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=ollama/nomic-embed-text \
|
|
77
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Set `OLLAMA_API_BASE` if your Ollama server is not at `http://localhost:11434`.
|
|
81
|
+
|
|
82
|
+
</details>
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary>OpenAI</summary>
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
claude mcp add cocoindex-code \
|
|
89
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=text-embedding-3-small \
|
|
90
|
+
-e OPENAI_API_KEY=your-api-key \
|
|
91
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
</details>
|
|
95
|
+
|
|
96
|
+
<details>
|
|
97
|
+
<summary>Azure OpenAI</summary>
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
claude mcp add cocoindex-code \
|
|
101
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=azure/your-deployment-name \
|
|
102
|
+
-e AZURE_API_KEY=your-api-key \
|
|
103
|
+
-e AZURE_API_BASE=https://your-resource.openai.azure.com \
|
|
104
|
+
-e AZURE_API_VERSION=2024-06-01 \
|
|
105
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
</details>
|
|
109
|
+
|
|
110
|
+
<details>
|
|
111
|
+
<summary>Gemini</summary>
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
claude mcp add cocoindex-code \
|
|
115
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=gemini/text-embedding-004 \
|
|
116
|
+
-e GEMINI_API_KEY=your-api-key \
|
|
117
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
</details>
|
|
121
|
+
|
|
122
|
+
<details>
|
|
123
|
+
<summary>Mistral</summary>
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
claude mcp add cocoindex-code \
|
|
127
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=mistral/mistral-embed \
|
|
128
|
+
-e MISTRAL_API_KEY=your-api-key \
|
|
129
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
</details>
|
|
133
|
+
|
|
134
|
+
<details>
|
|
135
|
+
<summary>Voyage (Code-Optimized)</summary>
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
claude mcp add cocoindex-code \
|
|
139
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=voyage/voyage-code-3 \
|
|
140
|
+
-e VOYAGE_API_KEY=your-api-key \
|
|
141
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary>Cohere</summary>
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
claude mcp add cocoindex-code \
|
|
151
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=cohere/embed-english-v3.0 \
|
|
152
|
+
-e COHERE_API_KEY=your-api-key \
|
|
153
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
</details>
|
|
157
|
+
|
|
158
|
+
<details>
|
|
159
|
+
<summary>AWS Bedrock</summary>
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
claude mcp add cocoindex-code \
|
|
163
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=bedrock/amazon.titan-embed-text-v2:0 \
|
|
164
|
+
-e AWS_ACCESS_KEY_ID=your-access-key \
|
|
165
|
+
-e AWS_SECRET_ACCESS_KEY=your-secret-key \
|
|
166
|
+
-e AWS_REGION_NAME=us-east-1 \
|
|
167
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
</details>
|
|
171
|
+
|
|
172
|
+
<details>
|
|
173
|
+
<summary>Nebius</summary>
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
claude mcp add cocoindex-code \
|
|
177
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=nebius/BAAI/bge-en-icl \
|
|
178
|
+
-e NEBIUS_API_KEY=your-api-key \
|
|
179
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
Any model supported by LiteLLM works — see the [full list of embedding providers](https://docs.litellm.ai/docs/embedding/supported_embedding).
|
|
185
|
+
|
|
186
|
+
### Setup `.gitignore`
|
|
187
|
+
|
|
188
|
+
Add the index directory to your `.gitignore` so it isn't committed:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
echo .cocoindex_code >> .gitignore
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Uninstall
|
|
195
|
+
|
|
196
|
+
Remove the MCP server and delete the local index:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
claude mcp remove cocoindex-code
|
|
200
|
+
rm -rf .cocoindex_code
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Configuration
|
|
204
|
+
|
|
205
|
+
| Variable | Description | Default |
|
|
206
|
+
|----------|-------------|---------|
|
|
207
|
+
| `COCOINDEX_CODE_ROOT_PATH` | Root path of the codebase | Auto-discovered (see below) |
|
|
208
|
+
| `COCOINDEX_CODE_EMBEDDING_MODEL` | Embedding model (see below) | `sbert/sentence-transformers/all-MiniLM-L6-v2` |
|
|
209
|
+
|
|
210
|
+
### Embedding Model
|
|
211
|
+
|
|
212
|
+
The `COCOINDEX_CODE_EMBEDDING_MODEL` variable uses a prefix to select the embedding backend:
|
|
213
|
+
|
|
214
|
+
- **`sbert/`** prefix — uses [SentenceTransformers](https://www.sbert.net/) (runs locally, no API key needed). Example: `sbert/sentence-transformers/all-MiniLM-L6-v2`
|
|
215
|
+
- **Otherwise** — uses [LiteLLM](https://docs.litellm.ai/docs/embedding/supported_embedding) (supports 100+ providers). Example: `text-embedding-3-small`
|
|
216
|
+
|
|
217
|
+
### Root Path Discovery
|
|
218
|
+
|
|
219
|
+
If `COCOINDEX_CODE_ROOT_PATH` is not set, the codebase root is discovered by:
|
|
220
|
+
|
|
221
|
+
1. Finding the nearest parent directory containing `.cocoindex_code/`
|
|
222
|
+
2. Finding the nearest parent directory containing `.git/`
|
|
223
|
+
3. Falling back to the current working directory
|
|
224
|
+
|
|
225
|
+
## MCP Tools
|
|
226
|
+
|
|
227
|
+
### `search`
|
|
228
|
+
|
|
229
|
+
Search the codebase using semantic similarity.
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
search(
|
|
233
|
+
query: str, # Natural language query or code snippet
|
|
234
|
+
limit: int = 10, # Maximum results (1-100)
|
|
235
|
+
offset: int = 0, # Pagination offset
|
|
236
|
+
refresh_index: bool = True # Refresh index before querying
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The `refresh_index` parameter controls whether the index is refreshed before searching:
|
|
241
|
+
|
|
242
|
+
- `True` (default): Refreshes the index to include any recent changes
|
|
243
|
+
- `False`: Skip refresh for faster consecutive queries
|
|
244
|
+
|
|
245
|
+
Returns matching code chunks with:
|
|
246
|
+
|
|
247
|
+
- File path
|
|
248
|
+
- Language
|
|
249
|
+
- Code content
|
|
250
|
+
- Line numbers (start/end)
|
|
251
|
+
- Similarity score
|
|
252
|
+
|
|
253
|
+
## Index Storage
|
|
254
|
+
|
|
255
|
+
The index is stored in `.cocoindex_code/` under your codebase root:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
your-project/
|
|
259
|
+
├── .cocoindex_code/
|
|
260
|
+
│ ├── target_sqlite.db # Vector index (SQLite + sqlite-vec)
|
|
261
|
+
│ └── cocoindex.db/ # CocoIndex state
|
|
262
|
+
├── src/
|
|
263
|
+
│ └── ...
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Add `.cocoindex_code/` to your `.gitignore`.
|
|
267
|
+
|
|
268
|
+
## Supported File Types
|
|
269
|
+
|
|
270
|
+
- **Python**: `.py`, `.pyi`
|
|
271
|
+
- **JavaScript**: `.js`, `.jsx`, `.mjs`, `.cjs`
|
|
272
|
+
- **TypeScript**: `.ts`, `.tsx`
|
|
273
|
+
- **Rust**: `.rs`
|
|
274
|
+
- **Go**: `.go`
|
|
275
|
+
- **Java**: `.java`
|
|
276
|
+
- **C**: `.c`, `.h`
|
|
277
|
+
- **C++**: `.cpp`, `.hpp`, `.cc`, `.cxx`, `.hxx`, `.hh`
|
|
278
|
+
- **C#**: `.cs`
|
|
279
|
+
- **SQL**: `.sql`
|
|
280
|
+
- **Shell**: `.sh`, `.bash`, `.zsh`
|
|
281
|
+
- **Markdown**: `.md`, `.mdx`
|
|
282
|
+
- **Plain Text**: `.txt`, `.rst`
|
|
283
|
+
|
|
284
|
+
Common generated directories are automatically excluded:
|
|
285
|
+
|
|
286
|
+
- `__pycache__/`
|
|
287
|
+
- `node_modules/`
|
|
288
|
+
- `target/`
|
|
289
|
+
- `dist/`
|
|
290
|
+
- `vendor/` (Go vendored dependencies, matched by domain-based child paths)
|
|
291
|
+
|
|
292
|
+
## Development
|
|
293
|
+
|
|
294
|
+
### Local Testing with Claude Code
|
|
295
|
+
|
|
296
|
+
To test locally without installing the package, use the Claude Code CLI:
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
claude mcp add cocoindex-code \
|
|
300
|
+
-- uv run --project /path/to/cocoindex-code cocoindex-code
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Or add to `.mcp.json` in your project root:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"mcpServers": {
|
|
308
|
+
"cocoindex-code": {
|
|
309
|
+
"command": "uv",
|
|
310
|
+
"args": ["run", "--project", "/path/to/cocoindex-code", "cocoindex-code"]
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Running Tests
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
# Install dev dependencies
|
|
320
|
+
uv sync --group dev
|
|
321
|
+
|
|
322
|
+
# Run tests
|
|
323
|
+
uv run pytest tests/ -v
|
|
324
|
+
|
|
325
|
+
# Run pre-commit hooks
|
|
326
|
+
uv run pre-commit run --all-files
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## License
|
|
330
|
+
|
|
331
|
+
MIT
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# CocoIndex Code
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server for indexing and querying codebases using [CocoIndex](https://cocoindex.io).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Semantic Code Search**: Find relevant code using natural language queries
|
|
8
|
+
- **Incremental Indexing**: Only re-indexes changed files for fast updates
|
|
9
|
+
- **Multi-Language Support**: Python, JavaScript/TypeScript, Rust, Go, Java, C/C++, C#, SQL, Shell
|
|
10
|
+
- **Flexible Embeddings**: Local SentenceTransformers (default) or 100+ cloud providers via [LiteLLM](https://docs.litellm.ai/docs/embedding/supported_embedding)
|
|
11
|
+
- **SQLite Storage**: Portable, no external database required
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) (which provides `uvx`):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage with Claude Code
|
|
22
|
+
|
|
23
|
+
No installation needed — `uvx` runs it directly.
|
|
24
|
+
|
|
25
|
+
### Default (Local Embeddings)
|
|
26
|
+
|
|
27
|
+
Uses a local SentenceTransformers model (`sentence-transformers/all-MiniLM-L6-v2`). No API key required:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
claude mcp add cocoindex-code \
|
|
31
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### With a Cloud or Custom Embedding Model
|
|
35
|
+
|
|
36
|
+
Set `COCOINDEX_CODE_EMBEDDING_MODEL` to any [LiteLLM-supported model](https://docs.litellm.ai/docs/embedding/supported_embedding), along with the provider's API key:
|
|
37
|
+
|
|
38
|
+
<details>
|
|
39
|
+
<summary>Ollama (Local)</summary>
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
claude mcp add cocoindex-code \
|
|
43
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=ollama/nomic-embed-text \
|
|
44
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Set `OLLAMA_API_BASE` if your Ollama server is not at `http://localhost:11434`.
|
|
48
|
+
|
|
49
|
+
</details>
|
|
50
|
+
|
|
51
|
+
<details>
|
|
52
|
+
<summary>OpenAI</summary>
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
claude mcp add cocoindex-code \
|
|
56
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=text-embedding-3-small \
|
|
57
|
+
-e OPENAI_API_KEY=your-api-key \
|
|
58
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
</details>
|
|
62
|
+
|
|
63
|
+
<details>
|
|
64
|
+
<summary>Azure OpenAI</summary>
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
claude mcp add cocoindex-code \
|
|
68
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=azure/your-deployment-name \
|
|
69
|
+
-e AZURE_API_KEY=your-api-key \
|
|
70
|
+
-e AZURE_API_BASE=https://your-resource.openai.azure.com \
|
|
71
|
+
-e AZURE_API_VERSION=2024-06-01 \
|
|
72
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
</details>
|
|
76
|
+
|
|
77
|
+
<details>
|
|
78
|
+
<summary>Gemini</summary>
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
claude mcp add cocoindex-code \
|
|
82
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=gemini/text-embedding-004 \
|
|
83
|
+
-e GEMINI_API_KEY=your-api-key \
|
|
84
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
</details>
|
|
88
|
+
|
|
89
|
+
<details>
|
|
90
|
+
<summary>Mistral</summary>
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
claude mcp add cocoindex-code \
|
|
94
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=mistral/mistral-embed \
|
|
95
|
+
-e MISTRAL_API_KEY=your-api-key \
|
|
96
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
</details>
|
|
100
|
+
|
|
101
|
+
<details>
|
|
102
|
+
<summary>Voyage (Code-Optimized)</summary>
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
claude mcp add cocoindex-code \
|
|
106
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=voyage/voyage-code-3 \
|
|
107
|
+
-e VOYAGE_API_KEY=your-api-key \
|
|
108
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
</details>
|
|
112
|
+
|
|
113
|
+
<details>
|
|
114
|
+
<summary>Cohere</summary>
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
claude mcp add cocoindex-code \
|
|
118
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=cohere/embed-english-v3.0 \
|
|
119
|
+
-e COHERE_API_KEY=your-api-key \
|
|
120
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
</details>
|
|
124
|
+
|
|
125
|
+
<details>
|
|
126
|
+
<summary>AWS Bedrock</summary>
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
claude mcp add cocoindex-code \
|
|
130
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=bedrock/amazon.titan-embed-text-v2:0 \
|
|
131
|
+
-e AWS_ACCESS_KEY_ID=your-access-key \
|
|
132
|
+
-e AWS_SECRET_ACCESS_KEY=your-secret-key \
|
|
133
|
+
-e AWS_REGION_NAME=us-east-1 \
|
|
134
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
</details>
|
|
138
|
+
|
|
139
|
+
<details>
|
|
140
|
+
<summary>Nebius</summary>
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
claude mcp add cocoindex-code \
|
|
144
|
+
-e COCOINDEX_CODE_EMBEDDING_MODEL=nebius/BAAI/bge-en-icl \
|
|
145
|
+
-e NEBIUS_API_KEY=your-api-key \
|
|
146
|
+
-- uvx --prerelease=explicit --with "cocoindex>=1.0.0a13" cocoindex-code@latest
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
Any model supported by LiteLLM works — see the [full list of embedding providers](https://docs.litellm.ai/docs/embedding/supported_embedding).
|
|
152
|
+
|
|
153
|
+
### Setup `.gitignore`
|
|
154
|
+
|
|
155
|
+
Add the index directory to your `.gitignore` so it isn't committed:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
echo .cocoindex_code >> .gitignore
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Uninstall
|
|
162
|
+
|
|
163
|
+
Remove the MCP server and delete the local index:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
claude mcp remove cocoindex-code
|
|
167
|
+
rm -rf .cocoindex_code
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Configuration
|
|
171
|
+
|
|
172
|
+
| Variable | Description | Default |
|
|
173
|
+
|----------|-------------|---------|
|
|
174
|
+
| `COCOINDEX_CODE_ROOT_PATH` | Root path of the codebase | Auto-discovered (see below) |
|
|
175
|
+
| `COCOINDEX_CODE_EMBEDDING_MODEL` | Embedding model (see below) | `sbert/sentence-transformers/all-MiniLM-L6-v2` |
|
|
176
|
+
|
|
177
|
+
### Embedding Model
|
|
178
|
+
|
|
179
|
+
The `COCOINDEX_CODE_EMBEDDING_MODEL` variable uses a prefix to select the embedding backend:
|
|
180
|
+
|
|
181
|
+
- **`sbert/`** prefix — uses [SentenceTransformers](https://www.sbert.net/) (runs locally, no API key needed). Example: `sbert/sentence-transformers/all-MiniLM-L6-v2`
|
|
182
|
+
- **Otherwise** — uses [LiteLLM](https://docs.litellm.ai/docs/embedding/supported_embedding) (supports 100+ providers). Example: `text-embedding-3-small`
|
|
183
|
+
|
|
184
|
+
### Root Path Discovery
|
|
185
|
+
|
|
186
|
+
If `COCOINDEX_CODE_ROOT_PATH` is not set, the codebase root is discovered by:
|
|
187
|
+
|
|
188
|
+
1. Finding the nearest parent directory containing `.cocoindex_code/`
|
|
189
|
+
2. Finding the nearest parent directory containing `.git/`
|
|
190
|
+
3. Falling back to the current working directory
|
|
191
|
+
|
|
192
|
+
## MCP Tools
|
|
193
|
+
|
|
194
|
+
### `search`
|
|
195
|
+
|
|
196
|
+
Search the codebase using semantic similarity.
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
search(
|
|
200
|
+
query: str, # Natural language query or code snippet
|
|
201
|
+
limit: int = 10, # Maximum results (1-100)
|
|
202
|
+
offset: int = 0, # Pagination offset
|
|
203
|
+
refresh_index: bool = True # Refresh index before querying
|
|
204
|
+
)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The `refresh_index` parameter controls whether the index is refreshed before searching:
|
|
208
|
+
|
|
209
|
+
- `True` (default): Refreshes the index to include any recent changes
|
|
210
|
+
- `False`: Skip refresh for faster consecutive queries
|
|
211
|
+
|
|
212
|
+
Returns matching code chunks with:
|
|
213
|
+
|
|
214
|
+
- File path
|
|
215
|
+
- Language
|
|
216
|
+
- Code content
|
|
217
|
+
- Line numbers (start/end)
|
|
218
|
+
- Similarity score
|
|
219
|
+
|
|
220
|
+
## Index Storage
|
|
221
|
+
|
|
222
|
+
The index is stored in `.cocoindex_code/` under your codebase root:
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
your-project/
|
|
226
|
+
├── .cocoindex_code/
|
|
227
|
+
│ ├── target_sqlite.db # Vector index (SQLite + sqlite-vec)
|
|
228
|
+
│ └── cocoindex.db/ # CocoIndex state
|
|
229
|
+
├── src/
|
|
230
|
+
│ └── ...
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Add `.cocoindex_code/` to your `.gitignore`.
|
|
234
|
+
|
|
235
|
+
## Supported File Types
|
|
236
|
+
|
|
237
|
+
- **Python**: `.py`, `.pyi`
|
|
238
|
+
- **JavaScript**: `.js`, `.jsx`, `.mjs`, `.cjs`
|
|
239
|
+
- **TypeScript**: `.ts`, `.tsx`
|
|
240
|
+
- **Rust**: `.rs`
|
|
241
|
+
- **Go**: `.go`
|
|
242
|
+
- **Java**: `.java`
|
|
243
|
+
- **C**: `.c`, `.h`
|
|
244
|
+
- **C++**: `.cpp`, `.hpp`, `.cc`, `.cxx`, `.hxx`, `.hh`
|
|
245
|
+
- **C#**: `.cs`
|
|
246
|
+
- **SQL**: `.sql`
|
|
247
|
+
- **Shell**: `.sh`, `.bash`, `.zsh`
|
|
248
|
+
- **Markdown**: `.md`, `.mdx`
|
|
249
|
+
- **Plain Text**: `.txt`, `.rst`
|
|
250
|
+
|
|
251
|
+
Common generated directories are automatically excluded:
|
|
252
|
+
|
|
253
|
+
- `__pycache__/`
|
|
254
|
+
- `node_modules/`
|
|
255
|
+
- `target/`
|
|
256
|
+
- `dist/`
|
|
257
|
+
- `vendor/` (Go vendored dependencies, matched by domain-based child paths)
|
|
258
|
+
|
|
259
|
+
## Development
|
|
260
|
+
|
|
261
|
+
### Local Testing with Claude Code
|
|
262
|
+
|
|
263
|
+
To test locally without installing the package, use the Claude Code CLI:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
claude mcp add cocoindex-code \
|
|
267
|
+
-- uv run --project /path/to/cocoindex-code cocoindex-code
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Or add to `.mcp.json` in your project root:
|
|
271
|
+
|
|
272
|
+
```json
|
|
273
|
+
{
|
|
274
|
+
"mcpServers": {
|
|
275
|
+
"cocoindex-code": {
|
|
276
|
+
"command": "uv",
|
|
277
|
+
"args": ["run", "--project", "/path/to/cocoindex-code", "cocoindex-code"]
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Running Tests
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# Install dev dependencies
|
|
287
|
+
uv sync --group dev
|
|
288
|
+
|
|
289
|
+
# Run tests
|
|
290
|
+
uv run pytest tests/ -v
|
|
291
|
+
|
|
292
|
+
# Run pre-commit hooks
|
|
293
|
+
uv run pre-commit run --all-files
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
MIT
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cocoindex-code"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
8
|
description = "MCP server for indexing and querying codebases using CocoIndex"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -23,7 +23,7 @@ classifiers = [
|
|
|
23
23
|
|
|
24
24
|
dependencies = [
|
|
25
25
|
"mcp>=1.0.0",
|
|
26
|
-
"cocoindex
|
|
26
|
+
"cocoindex[litellm]>=1.0.0a14",
|
|
27
27
|
"sentence-transformers>=2.2.0",
|
|
28
28
|
"sqlite-vec>=0.1.0",
|
|
29
29
|
"pydantic>=2.0.0",
|
|
@@ -48,6 +48,9 @@ Homepage = "https://github.com/cocoindex-io/cocoindex-code"
|
|
|
48
48
|
Repository = "https://github.com/cocoindex-io/cocoindex-code"
|
|
49
49
|
Issues = "https://github.com/cocoindex-io/cocoindex-code/issues"
|
|
50
50
|
|
|
51
|
+
[tool.hatch.version]
|
|
52
|
+
source = "vcs"
|
|
53
|
+
|
|
51
54
|
[tool.hatch.build.targets.wheel]
|
|
52
55
|
packages = ["src/cocoindex_code"]
|
|
53
56
|
|
|
@@ -62,9 +62,10 @@ class Config:
|
|
|
62
62
|
root = _discover_codebase_root()
|
|
63
63
|
|
|
64
64
|
# Get embedding model
|
|
65
|
+
# Prefix "sbert/" for SentenceTransformers models, otherwise LiteLLM.
|
|
65
66
|
embedding_model = os.environ.get(
|
|
66
67
|
"COCOINDEX_CODE_EMBEDDING_MODEL",
|
|
67
|
-
"sentence-transformers/all-MiniLM-L6-v2",
|
|
68
|
+
"sbert/sentence-transformers/all-MiniLM-L6-v2",
|
|
68
69
|
)
|
|
69
70
|
|
|
70
71
|
# Index directory is always under the root
|