Skip to main content

MCP server for indexing and querying codebases using CocoIndex

Project description

cocoindex code

light weight MCP for code that just works

A super light-weight, effective embedded MCP (AST-based) that understand and searches your codebase that just works! Using CocoIndex - an Rust-based ultra performant data transformation engine. No blackbox. Works for Claude, Codex, Cursor - any coding agent.

  • Instant token saving by 70%.
  • 1 min setup - Just claude/codex mcp add works!

Discord GitHub Documentation License

PyPI Downloads CI release

🌟 Please help star CocoIndex if you like this project!

Deutsch | English | Español | français | 日本語 | 한국어 | Português | Русский | 中文

Get Started - zero config, let's go!!

Requires Python 3 (pip3 comes pre-installed with Python).

pip3 install -U cocoindex-code

Claude

claude mcp add cocoindex-code -- cocoindex-code

Codex

codex mcp add cocoindex-code -- cocoindex-code

OpenCode

opencode mcp add

Enter MCP server name: cocoindex-code Select MCP server type: local Enter command to run: cocoindex-code

Or use opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "cocoindex-code": {
      "type": "local",
      "command": [
        "cocoindex-code"
      ]
    }
  }
}

Optionally, you can run cocoindex-code index to create or update the index. Without running it, the MCP server will automatically build and keep the index up-to-date in the background.

Features

  • Semantic Code Search: Find relevant code using natural language queries when grep doesn't work well, and save tokens immediately.
  • Ultra Performant to code changes:⚡ Built on top of ultra performant Rust indexing engine. Only re-indexes changed files for fast updates.
  • Multi-Language Support: Python, JavaScript/TypeScript, Rust, Go, Java, C/C++, C#, SQL, Shell
  • Embedded: Portable and just works, no database setup required!
  • Flexible Embeddings: By default, no API key required with Local SentenceTransformers - totally free! You can customize 100+ cloud providers.

Configuration

Variable Description Default
COCOINDEX_CODE_ROOT_PATH Root path of the codebase Auto-discovered (see below)
COCOINDEX_CODE_EMBEDDING_MODEL Embedding model (see below) sbert/sentence-transformers/all-MiniLM-L6-v2
COCOINDEX_CODE_BATCH_SIZE Max batch size for local embedding model 16

Root Path Discovery

If COCOINDEX_CODE_ROOT_PATH is not set, the codebase root is discovered by:

  1. Finding the nearest parent directory containing .cocoindex_code/
  2. Finding the nearest parent directory containing .git/
  3. Falling back to the current working directory

Embedding model

By default - this project use a local SentenceTransformers model (sentence-transformers/all-MiniLM-L6-v2). No API key required and completely free!

Use a code specific embedding model can achieve better semantic understanding for your results, this project supports all models on Ollama and 100+ cloud providers.

Set COCOINDEX_CODE_EMBEDDING_MODEL to any LiteLLM-supported model, along with the provider's API key:

Ollama (Local)
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=ollama/nomic-embed-text \
  -- cocoindex-code

Set OLLAMA_API_BASE if your Ollama server is not at http://localhost:11434.

OpenAI
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=text-embedding-3-small \
  -e OPENAI_API_KEY=your-api-key \
  -- cocoindex-code
Azure OpenAI
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=azure/your-deployment-name \
  -e AZURE_API_KEY=your-api-key \
  -e AZURE_API_BASE=https://your-resource.openai.azure.com \
  -e AZURE_API_VERSION=2024-06-01 \
  -- cocoindex-code
Gemini
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=gemini/text-embedding-004 \
  -e GEMINI_API_KEY=your-api-key \
  -- cocoindex-code
Mistral
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=mistral/mistral-embed \
  -e MISTRAL_API_KEY=your-api-key \
  -- cocoindex-code
Voyage (Code-Optimized)
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=voyage/voyage-code-3 \
  -e VOYAGE_API_KEY=your-api-key \
  -- cocoindex-code
Cohere
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=cohere/embed-english-v3.0 \
  -e COHERE_API_KEY=your-api-key \
  -- cocoindex-code
AWS Bedrock
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=bedrock/amazon.titan-embed-text-v2:0 \
  -e AWS_ACCESS_KEY_ID=your-access-key \
  -e AWS_SECRET_ACCESS_KEY=your-secret-key \
  -e AWS_REGION_NAME=us-east-1 \
  -- cocoindex-code
Nebius
claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=nebius/BAAI/bge-en-icl \
  -e NEBIUS_API_KEY=your-api-key \
  -- cocoindex-code

Any model supported by LiteLLM works — see the full list of embedding providers.

GPU-optimised local model

If you have a GPU, nomic-ai/CodeRankEmbed delivers significantly better code retrieval than the default model. It is 137M parameters, requires ~1 GB VRAM, and has an 8192-token context window.

claude mcp add cocoindex-code \
  -e COCOINDEX_CODE_EMBEDDING_MODEL=sbert/nomic-ai/CodeRankEmbed \
  -e COCOINDEX_CODE_BATCH_SIZE=16 \
  -- cocoindex-code

Note: Switching models requires re-indexing your codebase (the vector dimensions differ).

MCP Tools

search

Search the codebase using semantic similarity.

search(
    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 changes
  • False: Skip refresh for faster consecutive queries

Returns matching code chunks with:

  • File path
  • Language
  • Code content
  • Line numbers (start/end)
  • Similarity score

Supported Languages

Language Aliases File Extensions
c .c
cpp c++ .cpp, .cc, .cxx, .h, .hpp
csharp csharp, cs .cs
css .css, .scss
dtd .dtd
fortran f, f90, f95, f03 .f, .f90, .f95, .f03
go golang .go
html .html, .htm
java .java
javascript js .js
json .json
kotlin .kt, .kts
markdown md .md, .mdx
pascal pas, dpr, delphi .pas, .dpr
php .php
python .py
r .r
ruby .rb
rust rs .rs
scala .scala
solidity .sol
sql .sql
swift .swift
toml .toml
tsx .tsx
typescript ts .ts
xml .xml
yaml .yaml, .yml

Common generated directories are automatically excluded:

  • __pycache__/
  • node_modules/
  • target/
  • dist/
  • vendor/ (Go vendored dependencies, matched by domain-based child paths)

Troubleshooting

sqlite3.Connection object has no attribute enable_load_extension

Some Python installations (e.g. the one pre-installed on macOS) ship with a SQLite library that doesn't enable extensions.

macOS fix: Install Python through Homebrew:

brew install python3

Then re-install cocoindex-code with the Homebrew Python:

pip3 install -U cocoindex-code

Large codebase / Enterprise

CocoIndex is an ultra effecient indexing engine that also works on large codebase at scale on XXX G for enterprises. In enterprise scenarios it is a lot more effecient to do index share with teammates when there are large repo or many repos. We also have advanced features like branch dedupe etc designed for enterprise users.

If you need help with remote setup, please email our maintainer linghua@cocoindex.io, happy to help!!

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cocoindex_code-0.1.7.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cocoindex_code-0.1.7-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file cocoindex_code-0.1.7.tar.gz.

File metadata

  • Download URL: cocoindex_code-0.1.7.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cocoindex_code-0.1.7.tar.gz
Algorithm Hash digest
SHA256 128b17ad624585488dd53f0b7c2e10a6fdacf3b4ebda48e18213493b256ed9a8
MD5 58aad0db9badedfe090d158c6aed2d4c
BLAKE2b-256 01da6b528b43770d75d553165031412eef756972e649e3822db649949f034df5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cocoindex_code-0.1.7.tar.gz:

Publisher: release.yml on cocoindex-io/cocoindex-code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cocoindex_code-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: cocoindex_code-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cocoindex_code-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6aac79fb91d395ef1d01dffc2097aaf09f8578f5fde1e005d70a2675692ccd6c
MD5 2661da79279959d7222762aefa963493
BLAKE2b-256 1bf3e406562cf9e96b813a0e2df21787507796bfa30c27d80ec7f3c111bb341c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cocoindex_code-0.1.7-py3-none-any.whl:

Publisher: release.yml on cocoindex-io/cocoindex-code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page