code-index-mcp
A self-hosted, hybrid code search MCP server for local codebases, enabling AI agents to search and explore code using multiple layers:
search_text— Exact full-text search (FTS5) for known strings, identifiers, config keys, or error messages.search_symbol— Find definitions of functions, classes, methods, etc. by name (exact or substring match).file_symbols— Get a full outline of all symbols in a specific file, ordered by line number.search_semantic— Fuzzy, meaning-based vector similarity search via Qdrant (e.g. "where do we validate refunds").search_hybrid— Combined search across all three layers simultaneously — best when unsure which layer fits.list_services— List all registered microservice indexes (name, ID, path).reindex— Trigger incremental or full index rebuilds for a service.index_stats— View indexed file/symbol counts and semantic layer health for a service.
Additional capabilities include: filtering results by path using path_glob/exclude_glob, reading specific code spans from indexed files, managing per-project ignore rules (including .gitignore integration), auto-reindexing via a background daemon on filesystem events, monitoring indexing progress via web or CLI dashboards, and graceful degradation if components like Qdrant or tree-sitter are unavailable.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@code-index-mcp find the definition of 'handleError' function"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
code-index-mcp
Self-hosted hybrid code search as an MCP server for Kilo CLI / OpenCode. Everything runs locally on your machine — no third-party MCP servers, no LSP, no SaaS.
Three search layers, one server:
Layer | Engine | Good for |
text | SQLite FTS5 | exact strings, identifiers, config keys, errors |
symbols | tree-sitter | "where is |
semantic | fastembed (local) → Qdrant | fuzzy "where do we do Y" |
Don't want to configure this yourself? Let your agent do it
You don't need to learn the env vars, registry file, or Qdrant. Just tell your coding agent (Kilo CLI / OpenCode) to set it up from the runbook:
"Set up code-index for me, following the instructions at https://github.com/Krat12/mcp-code-index/blob/main/docs/AGENT_SETUP.md"
The agent reads docs/AGENT_SETUP.md, checks your
environment, asks you only the few things it can't decide (which repos, your
embeddings API key, whether to honor each repo's .gitignore, what else to
ignore), wires everything up, builds the index, optionally installs the
code-search skill so sub-agents can use the CLI
fallback, and tells you where everything lives — without writing anything into
your repos. The rest of this README is the manual reference for those who prefer
to do it by hand.
Related MCP server: codesteer-atlas
Requirements
Python 3.10+
Qdrant running locally (you already have it) at
http://localhost:6333The rest is pip-installed (tree-sitter grammars + fastembed are local; the embedding model downloads once and then runs offline).
Install
# from the project folder
uv venv
uv pip install -e .
# or: pip install -e .Nothing is written into your repos
All state lives outside the indexed repositories:
SQLite index →
~/.cache/code-index/<service-id>.sqlite3Qdrant collection →
code_<service-id>(derived from the repo's absolute path)Project registry →
~/.config/code-index/projects.toml
So you never commit anything, never edit .gitignore, and never add git hooks
inside the service repos — no PR noise.
Single project
code-index index # incremental index of CWD (or --path DIR)
code-index index --full # full rebuild
code-index statsMicroservices (many repos)
Register services in the external registry (no files in the repos):
# Register each service explicitly...
code-index add C:\work\billing --name billing
code-index add C:\work\payments --name payments
# ...or point at a parent folder and auto-discover every git repo inside:
code-index add-workspace C:\work --depth 1
code-index list # show resolved services
code-index index-all # (re)index every service (per-service index)
code-index stats-allThe registry file (~/.config/code-index/projects.toml) looks like:
[[service]]
name = "billing"
path = "C:/work/billing"
[[workspace]]
path = "C:/work"
depth = 1Per-project ignore (no files in the repo)
Each [[service]] (and [[workspace]]) can declare what to skip — all in the
external registry, so nothing is written into the service repo:
[[service]]
name = "billing"
path = "C:/work/billing"
ignore = ["**/generated/**", "*.pb.go", "docs/legacy/**"] # extra ignore globs
use_gitignore = true # ALSO skip whatever the repo-root .gitignore listsignoreis a list of glob patterns matched against repo-relative POSIX paths. Supported glob/.gitignore-like syntax:*(no/),**(any depth),?, a trailing/(directories only), and a leading/embedded/(anchored to the repo root). These are layered on top of the built-in ignores (build dirs, lock files, minified bundles, etc.).use_gitignore = trueadditionally reads the repo's top-level.gitignore(read-only — never written). Negation rules (!pattern) and nested per-directory.gitignorefiles are intentionally not supported, to keep the matcher tiny and predictable.For a
[[workspace]],ignore/use_gitignoreare inherited by every auto-discovered repo under it.
Watch indexing progress
code-index index # shows a live rich progress bar (TTY)
code-index index --plain # plain stderr logging instead
code-index status # one-shot table: phase / progress / files / symbols
code-index status --watch # live dashboard, refreshes ~1/s (Ctrl+C to stop)
code-index web # tiny local web dashboard at http://127.0.0.1:8765
code-index web --port 9000 # pick another portProgress is shared across processes via tiny JSON files in
~/.cache/code-index/status/<id>.json (atomic writes). So you can run
code-index status --watch (or open the web page) in one terminal and watch the
background code-index-watch daemon — or an index-all running elsewhere —
make progress in real time. The web UI is opt-in (started only by code-index web), single-threaded, and does work only when the browser polls — deliberately
light for a low-power machine.
Auto re-index (no git hooks)
A background daemon keeps every registered service fresh using filesystem events (watchdog) plus a periodic safety sweep — all outside the repos:
code-index-watch # FS events + sweep every 600s
code-index-watch --interval 300 # sweep every 5 min
code-index-watch --no-periodic # FS events onlyLeave it running (e.g. as a startup task / Windows service). It does an initial incremental index of each service, then re-indexes only what changes.
Wire it into Kilo CLI / OpenCode
Add a local MCP server to your config
(~/.config/kilo/opencode.json for Kilo CLI, or ~/.config/opencode/opencode.json
for OpenCode; a per-project opencode.json works too):
One MCP server can serve all your microservices — the agent picks the
service per call (or uses the default CWD service). Put this in the global
config (~/.config/kilo/opencode.json for Kilo, ~/.config/opencode/opencode.json
for OpenCode):
{
"$schema": "https://app.kilo.ai/config.json",
"mcp": {
"code-index": {
"type": "local",
"command": ["code-index-mcp"],
"enabled": true,
"environment": {
"CODE_INDEX_ROOT": "${cwd}",
"QDRANT_URL": "http://localhost:6333",
"CODE_INDEX_EMBED_MODEL": "BAAI/bge-small-en-v1.5",
"CODE_INDEX_SEMANTIC": "1"
}
}
}
}If
code-index-mcpisn't on PATH, use the absolute path to the venv script, e.g.["C:/Users/you/PycharmProjects/code-index-mcp/.venv/Scripts/code-index-mcp.exe"], or["python", "-m", "code_index.server"]with the venv's python.
Restart the CLI. The agent now sees tools:
search_text, search_symbol, file_symbols, read_span, search_semantic,
search_hybrid, list_services, reindex, index_stats. Every search tool
takes an optional service (name or id from list_services).
read_span(path, start_line, end_line, context=0, service=...)returns the actual source at a location — the natural follow-up to a search hit, so the agent can read code without a separate file tool (path is confined to the repo; falls back to the index if the file changed/vanished on disk).search_text/search_symbol/search_semantic/search_hybridacceptpath_globandexclude_glob(globs, comma-separated or a list) to narrow results by repo-relative path, e.g.path_glob="backend/**",exclude_glob="**/tests/**".search_textalso degrades gracefully on malformed FTS5 input (it retries the query as a literal phrase).
Keeping the index fresh
Background daemon (recommended):
code-index-watch(see above).On demand from the agent: it can call the
reindextool.Manual:
code-index index/code-index index-all.At server start: set
CODE_INDEX_REINDEX_ON_START=1for a quick background incremental of the default service when the MCP server launches.
Environment variables
Var | Default | Meaning |
|
| default project root (single-project / fallback) |
|
| where |
|
| where SQLite indexes live |
|
| Qdrant endpoint |
| – | optional Qdrant key |
|
| fastembed model |
|
| set |
|
|
|
Live indexing status is written to
~/.cache/code-index/status/<id>.json(underCODE_INDEX_CACHE_HOME). Inspect it withcode-index status/code-index status --watch, or thecode-index webdashboard.
Graceful degradation
No tree-sitter? → symbols layer off, text + semantic still work.
Qdrant down / fastembed missing? → semantic off, text + symbols still work.
The text (FTS5) layer always works as long as the SQLite index exists.
Degradation is visible, not silent:
index_statsreports the semantic layer's health:ok (points=N),disabled(turned off), orunavailable(API/Qdrant unreachable).search_semantic/search_hybriddistinguish disabled vs unavailable vs "no matches", so the agent knows to fall back to text/symbols instead of treating a down layer as an empty result.Indexing counts what it couldn't store — chunks that failed to embed and vectors that failed to upsert — and surfaces the totals in the run log, in
status.json, and in thestatus/ web dashboards (a ⚠ marker).
Available Tools
8 toolsfile_symbolsA
List all symbols (outline) of a single file, ordered by line.
Inputs: path (required), service. Returns: result
index_statsB
Show how many files and symbols are currently indexed for a service.
Inputs: service. Returns: result
list_servicesA
List indexable microservices from the external registry.
Returns name, id and path for each. Pass a name or id as the service
argument of the search tools to target a specific microservice.
Inputs: no named parameters. Returns: result
reindexA
Rebuild the index from disk for one service. Use after large changes.
full=true forces a complete re-index; otherwise only changed files are updated.
Inputs: full, service. Returns: result
search_hybridA
Best-effort combined search: symbols + text + semantic for one service.
Prefer this when you're not sure which layer fits. service selects the
index (name or id); omit for the default service.
Inputs: query (required), limit, service. Returns: result
search_semanticA
Fuzzy meaning-based search (vector similarity via Qdrant).
Use for conceptual queries like "where do we validate refunds" when you
don't know exact identifiers. service selects the index.
Inputs: query (required), limit, service. Returns: result
search_symbolB
Find symbol definitions (function/class/method/record/...) by name.
Use to jump to where something is DEFINED. Set exact=true for an exact name
match, otherwise substring matching is used. service selects the index.
Inputs: name (required), limit, exact, service. Returns: result
search_textA
Exact full-text search across a service (FTS5). Returns path:line: content.
Use for known strings, identifiers, config keys, error messages. Supports
FTS5 syntax, e.g. "foo AND bar", "exact phrase", prefix*.
service selects which microservice index to search (name or id); omit for
the default service.
Inputs: query (required), limit, service. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool has a distinct purpose: file_symbols for file outline, index_stats for statistics, list_services for service listing, reindex for rebuilding, and four differentiated search tools (hybrid, semantic, symbol, text) with clear guidance on when to use each.
All tool names follow a consistent snake_case verb_noun pattern (e.g., search_hybrid, file_symbols, list_services), making the set predictable and easy to navigate.
With 8 tools, the surface is well-scoped for a code index server: listing, stats, rebuilding, and four search variants cover the core functionality without bloat.
The tool set covers essential operations (list services, rebuild index, search, show file symbols) but lacks granular index management (e.g., individual file add/remove) and cross-service search, limiting flexibility in some workflows.
Maintenance
Related MCP Connectors
Self-hosted AI workspace: semantic RAG document search, long-term memory, and AI chat via MCP.
Shared context for your codebase: a hosted code knowledge graph over MCP. Free plan, OAuth sign-up.
Repository knowledge graph MCP server for codebase understanding and debugging.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceSelf-hosted MCP server for indexing and searching code repositories via hybrid search and deep code understanding.5 npm19MIT
- AlicenseAqualityBmaintenanceLocal MCP server for semantic code search using Tree-sitter AST parsing, local embeddings, and hybrid search; enables indexing and querying codebases entirely offline.7MIT
- AlicenseAqualityDmaintenanceLocal-first MCP server for semantic + keyword hybrid code search. Zero external services, no API keys required.2MIT
- AlicenseAqualityBmaintenanceMCP server for semantic code search with AST-aware chunking, hybrid vectors, and query syntax.121Apache 2.0