kerchunk
by flipk
README.md
# kerchunk
**kerchunk** is an AST-aware semantic code search [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server built for [OpenCode](https://opencode.ai/).
It indexes your repository locally using Tree-sitter and DuckDB, watches for file changes in the background, and exposes fast hybrid code search and multi-hop architectural research tools to AI coding agents.
## What It Does
- **AST-Aware Chunking:** Uses `tree-sitter` and `tree-sitter-language-pack` to split source files along semantic syntax boundaries (functions, classes, methods, blocks) rather than arbitrary line counts.
- **Supported languages:** Python, JavaScript, TypeScript / TSX, Rust, Go, C, C++, Java, C#, and Bash.
- **Local Vector & Hybrid Search:** Stores embeddings and chunk metadata in a per-repository DuckDB database (`.kerchunk/index.duckdb`). Automatically adds `.kerchunk/` to `.git/info/exclude` so your repository stays clean.
- **Live File Watching:** Runs a background `watchdog` observer to incrementally re-index files as they are created, modified, or deleted, while respecting `.gitignore` rules and skipping common build/dependency directories.
- **Optional Reranking:** Supports an OpenAI-compatible reranker endpoint to re-score top hybrid search candidates for higher precision.
- **Multi-Hop Code Research:** When a chat model is configured, enables iterative, multi-hop architectural research that decomposes complex questions into multiple searches and synthesizes answers with exact `file_path:start_line-end_line` citations.
### MCP Tools Exposed
| Tool | Description |
| --- | --- |
| `search_code` | Hybrid semantic + lexical AST-aware search over the repository, with optional `language`, `path_prefix`, and `limit` filters. |
| `code_research` | Deep multi-hop architectural research across the codebase (enabled when `KERCHUNK_CHAT_MODEL` is set). |
| `index_status` | Reports indexing progress, file/chunk counts, database path, and active model configuration. |
## Prerequisites
- **Python 3.11+**
- An OpenAI-compatible **embedding** endpoint (e.g., Ollama, vLLM, llama.cpp, or a hosted API).
- *(Optional)* An OpenAI-compatible **reranker** endpoint for improved search ranking.
- *(Optional)* An OpenAI-compatible **chat** endpoint (e.g., Gemini, OpenAI, or a local LLM) to enable `code_research`.
## Build and Install
Clone the repository and install `kerchunk` into a Python virtual environment:
```bash
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -e .
```
For a standard (non-editable) install:
```bash
pip install .
```
This installs the `kerchunk` console script (`./venv/bin/kerchunk`), which runs the MCP server over stdio for the current working directory.
## Configuration
`kerchunk` is configured via environment variables:
| Variable | Default | Description |
| --- | --- | --- |
| `KERCHUNK_BASE_URL` | `http://localhost:8000/v1` | Fallback base URL for embed, rerank, and chat endpoints. |
| `KERCHUNK_API_KEY` | `not-needed` | Fallback API key for all endpoints. |
| `KERCHUNK_EMBED_URL` | `KERCHUNK_BASE_URL` | Embedding API base URL. |
| `KERCHUNK_EMBED_MODEL` | `qwen3-embedding:4b` | Embedding model name. |
| `KERCHUNK_EMBED_API_KEY` | `KERCHUNK_API_KEY` | API key for the embedding endpoint. |
| `KERCHUNK_RERANK_URL` | `KERCHUNK_BASE_URL` | Reranker API base URL. |
| `KERCHUNK_RERANK_MODEL` | *(disabled)* | Reranker model name. Leave unset to skip reranking. |
| `KERCHUNK_RERANK_API_KEY` | `KERCHUNK_API_KEY` | API key for the reranker endpoint. |
| `KERCHUNK_CHAT_URL` | `KERCHUNK_BASE_URL` | Chat API base URL for `code_research`. |
| `KERCHUNK_CHAT_MODEL` | *(disabled)* | Chat model name. Leave unset to disable `code_research`. |
| `KERCHUNK_CHAT_API_KEY` | `KERCHUNK_API_KEY` | API key for the chat endpoint. |
| `KERCHUNK_LOG_FILE` | `false` | Set to `true`/`1`/`yes`/`on` to also write logs to `.kerchunk/kerchunk.log`. |
| `KERCHUNK_MAX_CHUNK_CHARS` | `2400` | Maximum character size per AST chunk. |
| `KERCHUNK_MIN_CHUNK_CHARS` | `300` | Minimum character size per AST chunk. |
## Sample Files
This repository includes two sample files to help you integrate `kerchunk` with OpenCode:
- **`sample_opencode_json.txt`** — A ready-to-adapt `opencode.json` configuration showing how to register `kerchunk` as a local MCP server in OpenCode, with example environment variables for local embedding/reranker services and a Gemini chat model. Copy its contents into your project's `opencode.json` and update the command path, model names, and API keys as needed.
- **`sample_AGENTS_md.md`** — A recommended snippet to add to your project's `AGENTS.md`. It guides coding agents on when to use `kerchunk_code_research` vs. `kerchunk_search_code`, how to use returned line-range citations for narrow file reads, and when to fall back to `grep`/`glob`.
## License
This project is released into the public domain under the [Unlicense](LICENSE.md).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues