Skip to main content
Glama

kerchunk

kerchunk is an AST-aware semantic code search Model Context Protocol (MCP) server built for OpenCode.

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.

Related MCP server: semantic-code-intelligence

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:

python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -e .

For a standard (non-editable) install:

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.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents and IDEs to ingest and search code repositories using hybrid retrieval (dense + sparse) with exact line-level citations for precise code analysis.
      1
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables coding agents to search a locally indexed codebase with hybrid dense, lexical, and symbol-graph retrieval, returning ranked passages with exact file:line-line citations plus graph context and index status. It keeps its index in sync via a file watcher and runs as a local sidecar with no hosted service to deploy.
      2
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to index local code repositories and perform hybrid BM25 and vector search over AST-aware code chunks, with incremental updates and optional cross-encoder re-ranking.
      1
      MIT