MCP server for querying cocoindex code embeddings database
Project description
cocoindex-mcp
Semantic code search for Model Context Protocol clients, powered by cocoindex flows and a Postgres + pgvector backend.
At a glance
- 🔍 Semantic search over the embeddings produced by the cocoindex
CodeEmbeddingflow. - 🤝 MCP-native stdio server that drops straight into Claude Desktop, Cursor, and other MCP hosts.
- ⚙️ Zero-surprise configuration via a single
COCOINDEX_DATABASE_URLenvironment variable (with.envsupport). - 🚀 Packaged for uv – run it instantly with
uvx --from yalattas/cocoindex-mcp cocoindex-mcp.
Table of contents
- At a glance
- How it works
- Prerequisites
- Quick start
- Configuration
- Running the server
- Available MCP tools
- Troubleshooting
- Local development
- Contributing
- License
How it works
The server wraps a cocoindex flow that embeds local source files into a Postgres table called code_embeddings. Every query is transformed with the same SentenceTransformer model and matched against the stored vectors using cosine similarity via pgvector. Results are streamed back to the MCP client with file paths, the matched snippet, score, and optional line numbers.
Internally the server is built with:
mcp.server.fastmcpto expose stdio-based MCP tools.cocoindexfor defining and running the embedding flow.psycopg_poolandpgvectorfor high-throughput vector queries.python-dotenvto honor environment files automatically.
Prerequisites
- Python ≥ 3.11 (only needed for local installs;
uvxships its own runtime). - PostgreSQL with the
pgvectorextension enabled. - A
code_embeddingstable populated by running theCodeEmbeddingcocoindex flow (seesrc/cocoindex_mcp/search.py). - Credentials with read access to the embeddings table.
If you're starting from scratch, run the cocoindex flow once to generate the embeddings. The flow definition lives in this repository and targets the code_embeddings table by default.
Quick start
Run without installing (recommended)
uvx --from cocoindex-mcp cocoindex-mcp --help
Pass any CLI options after cocoindex-mcp. Use --env (or a .env file) to supply the Postgres URL when launching via uvx.
Install into an existing environment
uv pip install cocoindex-mcp
or with plain pip:
pip install cocoindex-mcp
Verify the installation:
cocoindex-mcp --version
Configuration
Set the database connection string before starting the server:
export COCOINDEX_DATABASE_URL="postgres://user:password@localhost:5432/cocoindex"
Environment variables are loaded from a .env file automatically:
echo 'COCOINDEX_DATABASE_URL=postgres://user:password@localhost:5432/cocoindex' >> .env
Minimum database requirements
CREATE EXTENSION IF NOT EXISTS vector;- A
code_embeddingstable with columns:filename,code,embedding vector,start,end. - A compatible cocoindex-generated vector index (cosine similarity).
If the connection fails, the CLI surfaces descriptive errors that include the masked Postgres host/DB to help with debugging.
Running the server
The server communicates over stdio, which is the preferred transport for MCP clients.
Choose the entrypoint that best fits your workflow:
uvx --from cocoindex-mcp cocoindex-mcpcocoindex-mcp(console script exposed after installation)python -m cocoindex_mcppython main.py
All of these entrypoints share the same FastMCP runtime configured in src/cocoindex_mcp/cli.py.
Example Claude Desktop configuration
{
"mcpServers": {
"cocoindex": {
"command": "uvx",
"args": [
"--from",
"cocoindex-mcp",
"cocoindex-mcp"
],
"env": {
"COCOINDEX_DATABASE_URL": "postgres://user:password@localhost:5432/cocoindex"
}
}
}
}
Example for local cloned repo
{
"mcpServers": {
"cocoindex-local": {
"command": "uv",
"args": [
"run",
"-m",
"cocoindex_mcp"
],
"cwd": "/path/to/project/cocoindex-mcp",
"env": {
"PYTHONPATH": "src",
"COCOINDEX_DATABASE_URL": "postgres://yasser:@localhost/cocoindex"
}
}
}
}
CLI options
cocoindex-mcp [--log-level LEVEL] [--version]
--log-level CRITICAL | ERROR | WARNING | INFO | DEBUG (default: INFO)
--version Print the installed version and exit
Use --log-level DEBUG while integrating to see the Postgres readiness checks and tool invocations.
Available MCP tools
| Tool | Description | Parameters |
|---|---|---|
cocoindex_search |
Perform a semantic search and return filename, snippet, similarity score, and optional line range. | query (str, required) · limit (int, default 10, range 1–50) |
cocoindex_info |
Inspect the server's metadata, environment requirements, and exposed tools. | None |
Errors raised by the underlying database connectivity (missing URL, connection refused, etc.) are surfaced as structured error messages in the tool response.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
COCOINDEX_DATABASE_URL is not set |
Environment variable missing. | Export the variable or add it to .env before launching. |
Could not connect to Postgres ... |
Credentials, host, or pgvector extension not available. | Confirm the URL, ensure the database is reachable, enable the vector extension. |
| Empty search results | Embeddings table not populated or query too specific. | Run the cocoindex CodeEmbedding flow; try a broader query or higher limit. |
Enable debug logging (--log-level DEBUG) to display stack traces and raw SQL queries if you need deeper insight.
Local development
Clone the repository and install dependencies using uv:
uv sync
Run the server locally:
uv run python -m cocoindex_mcp --no-banner --log-level DEBUG
Useful entrypoints:
src/cocoindex_mcp/search.py– cocoindex flow and search helpers.src/cocoindex_mcp/db.py– connection pooling and diagnostics.src/cocoindex_mcp/config.py– FastMCP server wiring and tool definitions.
License
This project is licensed under the terms of the CNCF License.
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_mcp-0.0.2.tar.gz.
File metadata
- Download URL: cocoindex_mcp-0.0.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85b305e9382f1383d01d8635481b2b587aa607b754c94699db7e4d7c2b262096
|
|
| MD5 |
7e23455e501fb21e60307564126677d6
|
|
| BLAKE2b-256 |
8dc8cfe173751597e5ecd528f3275d2a65a52c32b16c3e10affa98d2de58a16a
|
File details
Details for the file cocoindex_mcp-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cocoindex_mcp-0.0.2-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25e0731a5a3f9e1998c2ff8d8efff201392c2c36aa402a0cbc7b73d9d8929399
|
|
| MD5 |
48fcda6647c742af7d5e9962ab1626ab
|
|
| BLAKE2b-256 |
5d9362c96d38133251a73174522c210d19273aed9db5c366864f7625943b8040
|