Local code context indexer and retriever with:
- A CLI for indexing/search/lookup/snippets/summarization
- A FastMCP server exposing those capabilities as MCP tools
This project is inspired by Context7.
Credit to the Context7 project and contributors for the original concept and direction.
context6 scans a Python codebase, stores entities in SQLite, and lets you:
- Find symbols by name (
lookup) - Search by text (
search) - Pull exact source snippets (
snippet) - Generate compact summaries (
summarize) - Evaluate recall against qrels (
eval-recall)
- Python 3.10+
pip(or another Python package installer)
Optional (only needed for summarization modes):
- Ollama running locally for
ollama/automode - OpenAI Codex CLI binary for
codexmode fallback/direct use
From repo root:
python -m pip install -e .This installs the package and the context6 CLI entrypoint from pyproject.toml.
If your shell cannot find context6, use module form: python -m context6.cli ....
- Build an index for a source tree:
python -m context6.cli index --source /path/to/your/python/project --out ./arcThis creates ./arc/context6.db.
- Search for relevant entities:
python -m context6.cli search --db ./arc/context6.db "database connection pooling"- Lookup by symbol:
python -m context6.cli lookup --db ./arc/context6.db --source /path/to/your/python/project MyClass- Get a snippet:
python -m context6.cli snippet --db ./arc/context6.db mypkg.module.MyClass.method_nameShow all commands:
python -m context6.cli --helpAvailable subcommands:
index: build an index and ingest into SQLitelookup: find best symbol matchsearch: FTS search over fqname/signature/docstring/summarysnippet: retrieve source text for a fully-qualified namesummarize: fill missing summaries for indexed entitieseval-recall: evaluate retrieval against qrels data
Filter by kinds:
python -m context6.cli search --db ./arc/context6.db "ARC execute" --kinds class,methodRun summarization:
python -m context6.cli summarize --db ./arc/context6.db --limit 100 --summarizer autoEvaluate recall:
python -m context6.cli eval-recall --db ./arc/context6.db --qrels ./qrels.json --k 10 --retriever searchThese are used by CLI and/or MCP tools:
CONTEXT6_SOURCE_ROOT: source root used when loading snippetsCONTEXT6_DB: default DB path for MCP server (default:~/code/context6/arc/context6.db)CONTEXT6_SUMMARIZER:auto,ollama, orcodexfor MCP summarize toolCONTEXT6_CODEX_BIN: path/name for codex binary (default:codex)CONTEXT6_MODEL: Ollama model (default:qwen2.5:7b)OLLAMA_HOST: Ollama endpoint (default:http://localhost:11434)CONTEXT6_NUM_CTX: Ollama context size override (default:6144)
Run the server over stdio:
python -m context6.mcp.context6_serverBefore launching, set at least:
export CONTEXT6_DB=/absolute/path/to/context6.db
export CONTEXT6_SOURCE_ROOT=/absolute/path/to/source/rootThe server exposes tools including:
context6_healthcontext6_lookupcontext6_searchcontext6_snippetcontext6_pretty_lookupcontext6_summarize_entitycontext6_resolve
Run tests:
python -m pytest -q