MCP server for indexing and querying codebases using CocoIndex
Project description
CocoIndex Code
An MCP (Model Context Protocol) server for indexing and querying codebases using CocoIndex.
Features
- Semantic Code Search: Find relevant code using natural language queries
- Incremental Indexing: Only re-indexes changed files for fast updates
- Multi-Language Support: Python, JavaScript/TypeScript, Rust, Go
- Vector Embeddings: Uses sentence-transformers for semantic similarity
- SQLite Storage: Portable, no external database required
Installation
pip install cocoindex-code
Or with uv:
uv pip install cocoindex-code
Usage with Claude Code
Add to your Claude Code MCP configuration (.claude/mcp_config.json):
{
"mcpServers": {
"cocoindex-code": {
"command": "cocoindex-code",
"env": {
"COCOINDEX_CODE_ROOT_PATH": "/path/to/your/codebase"
}
}
}
}
Or without explicit path (auto-discovers from current directory):
{
"mcpServers": {
"cocoindex-code": {
"command": "cocoindex-code"
}
}
}
Configuration
Environment variables:
| Variable | Description | Default |
|---|---|---|
COCOINDEX_CODE_ROOT_PATH |
Root path of the codebase | Auto-discovered (see below) |
COCOINDEX_CODE_EMBEDDING_MODEL |
Embedding model to use | sentence-transformers/all-MiniLM-L6-v2 |
Root Path Discovery
If COCOINDEX_CODE_ROOT_PATH is not set, the codebase root is discovered by:
- Finding the nearest parent directory containing
.cocoindex_code/ - Finding the nearest parent directory containing
.git/ - Falling back to the current working directory
MCP Tools
query
Search the codebase using semantic similarity.
query(
query: str, # Natural language query or code snippet
limit: int = 10, # Maximum results (1-100)
offset: int = 0, # Pagination offset
refresh_index: bool = True # Refresh index before querying
)
The refresh_index parameter controls whether the index is refreshed before searching:
True(default): Refreshes the index to include any recent changesFalse: Skip refresh for faster consecutive queries
Returns matching code chunks with:
- File path
- Language
- Code content
- Line numbers (start/end)
- Similarity score
Index Storage
The index is stored in .cocoindex_code/ under your codebase root:
your-project/
├── .cocoindex_code/
│ ├── target_sqlite.db # Vector index (SQLite + sqlite-vec)
│ └── cocoindex.db/ # CocoIndex state
├── src/
│ └── ...
Add .cocoindex_code/ to your .gitignore.
Supported File Types
- Python:
.py,.pyi - JavaScript:
.js,.jsx,.mjs,.cjs - TypeScript:
.ts,.tsx - Rust:
.rs - Go:
.go
Common generated directories are automatically excluded:
__pycache__/node_modules/target/dist/build/.git/
Development
Local Testing with Claude Code
To test locally without installing the package, use the Claude Code CLI:
claude mcp add cocoindex-code \
-- uv run --project /path/to/cocoindex-code cocoindex-code
Or add to .mcp.json in your project root:
{
"mcpServers": {
"cocoindex-code": {
"command": "uv",
"args": ["run", "--project", "/path/to/cocoindex-code", "cocoindex-code"]
}
}
}
Running Tests
# Install dev dependencies
uv sync --group dev
# Run tests
uv run pytest tests/ -v
# Run pre-commit hooks
uv run pre-commit run --all-files
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cocoindex_code-0.1.0.tar.gz.
File metadata
- Download URL: cocoindex_code-0.1.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf99e749df65284136fe452adc77975fddfc06e507e0ae2f031df582135a1f92
|
|
| MD5 |
22732f4488dd1c0b78845c2a2ae6cca6
|
|
| BLAKE2b-256 |
645e98fab499a64040678075d5c66c93d413728c64a9e9f811fe4374afd899c6
|
Provenance
The following attestation bundles were made for cocoindex_code-0.1.0.tar.gz:
Publisher:
release.yml on cocoindex-io/cocoindex-code
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cocoindex_code-0.1.0.tar.gz -
Subject digest:
cf99e749df65284136fe452adc77975fddfc06e507e0ae2f031df582135a1f92 - Sigstore transparency entry: 927902254
- Sigstore integration time:
-
Permalink:
cocoindex-io/cocoindex-code@41fad0bccf6c2c9883fca79a613dead72bef54d8 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/cocoindex-io
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@41fad0bccf6c2c9883fca79a613dead72bef54d8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file cocoindex_code-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cocoindex_code-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
774b0ddb20d5936e732af3fdfe2ec9e8d4905b8732a7db69123bab51abe4dffc
|
|
| MD5 |
52559673e488430f904ab7481320b487
|
|
| BLAKE2b-256 |
fa7b780837a95942a5114f5c3b0e36c6a1269aad70ce474dee997466920e868a
|
Provenance
The following attestation bundles were made for cocoindex_code-0.1.0-py3-none-any.whl:
Publisher:
release.yml on cocoindex-io/cocoindex-code
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cocoindex_code-0.1.0-py3-none-any.whl -
Subject digest:
774b0ddb20d5936e732af3fdfe2ec9e8d4905b8732a7db69123bab51abe4dffc - Sigstore transparency entry: 927902304
- Sigstore integration time:
-
Permalink:
cocoindex-io/cocoindex-code@41fad0bccf6c2c9883fca79a613dead72bef54d8 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/cocoindex-io
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@41fad0bccf6c2c9883fca79a613dead72bef54d8 -
Trigger Event:
release
-
Statement type: