Get the FREE Ultimate OpenClaw Setup Guide →

cocoindex-code

An RAG for code development, implemented as MCP server with cocoindex

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio aanno-cocoindex-code-mcp-server python -m cocoindex_code_mcp_server.main_mcp_server --rescan --port 3033 <path_to_code_directory> \
  --env COCOINDEX_DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"

How to use

CocoIndex Code MCP Server provides a Retrieval-Augmented Generation (RAG) access point for code. It indexes your codebase, stores embeddings in a PostgreSQL + pgvector backend, and serves HTTP requests to retrieve relevant code snippets with a hybrid search that combines semantic similarity and keyword metadata. You can run it as a streaming MCP server and query it from an MCP client or an integration that supports the MCP protocol. To use it, start the server with the path to your code directory, then connect to http://localhost:3033/mcp or the configured port. The server exposes handlers for language-aware code retrieval, leveraging CocoIndex’s incremental indexing, tree-sitter chunking, and smart embeddings to return precise results for code-related queries, code completion, and generation prompts. Example usage for a client like Claude Code demonstrates constructing an mcpServers entry that points to the local server, enabling real-time retrieval during conversations with an LLM.

How to install

Prerequisites:

  • Python 3.11+ and a compatible Rust toolchain if building from source
  • PostgreSQL with pgvector extension available and accessible
  • Network access to install Python packages (PyPI)

Install from PyPI (stable path):

pip install cocoindex-code-mcp-server

If you prefer building from source (recommended if you need the latest features):

# Optional: clone repository (if provided)
git clone --recursive https://github.com/aanno/cocoindex-code-mcp-server.git
cd cocoindex-code-mcp-server

# Build from source with maturin (requires Rust tooling)
uv sync
uv sync --all-extras
maturin develop

Configure the database connection (example):

cp .env.template .env
# Edit .env to set COCOINDEX_DATABASE_URL=postgresql://USER:PASSWORD@HOST:PORT/DATABASE

Start a PostgreSQL+pgvector instance if you don’t have one:

./scripts/cocoindex-postgresql.sh
python3 ./scripts/install-pgvector.py

Run the MCP server (from project root):

python -m cocoindex_code_mcp_server.main_mcp_server --rescan --port 3033 <path_to_code_directory>

Additional notes

Notes and tips:

  • The server expects a running PostgreSQL + pgvector backend. Ensure COCOINDEX_DATABASE_URL is set in your environment or in a .env file.
  • The --rescan flag clears and rebuilds the index; omit for incremental updates.
  • If you run into port conflicts, choose a different port with --port.
  • The embedded APIs support streaming HTTP MCP responses by default; you can enable JSON responses with --json-response if desired.
  • The mcpServers entry in your client configuration should point to http://localhost:3033/mcp (or your configured host/port).
  • For large codebases, indexing may take significant time; monitor the console output for progress indicators like CodeEmbedding.files (batch update).

Related MCP Servers

Sponsor this space

Reach thousands of developers