llm_context is a local-first MCP retrieval server for technical context from code and documents.
It is built for RAG-style lookup over repositories and technical document sets, with explicit project boundaries, incremental ingest, and retrieval surfaces aimed at agent workflows. It is not a persistent operational memory system; that role belongs to llm-memory.
- indexes code and documents into a local vector-backed retrieval store
- supports technical retrieval through MCP tools such as
rag_context,rag_search, andsymbol_search - separates read-plane retrieval from write-plane ingest
- supports project discovery through a registry and explicit project selection
- keeps retrieval focused on local infrastructure and local embeddings
Agents often need precise technical context without loading an entire repository into a prompt.
llm_context is meant to provide:
- local retrieval over source code and technical docs
- explicit project scoping instead of implicit workspace leakage
- incremental ingest instead of full reindex every time
- a retrieval-oriented MCP surface that stays separate from operational memory
This project started from a real codebase where a single-project SQLite setup was still barely workable, but sustained indexing and retrieval were already close to the point where an embedded store stopped being comfortable.
The main architectural tradeoff was to prioritize ingestion throughput, retrieval performance, concurrency, and multi-project growth over the simplicity and portability of SQLite.
That led to PostgreSQL with pgvector:
- metadata and vector storage stay in one operational stack
- multi-project indexing has a more credible persistence model
- retrieval can scale beyond the limits of a single embedded local file
- the storage layer is better aligned with sustained ingest workloads
The cost is deliberate:
- the project is less portable than an all-SQLite setup
- local setup is heavier
- the runtime depends on a database that is worth operating only if the retrieval surface is large enough to justify it
In other words, this repository trades some simplicity for a storage model that better matches real indexing pressure and multi-project retrieval.
- Read-plane vs write-plane: retrieval is exposed through MCP; ingest remains an operational capability
- Explicit project registry: every ingest and retrieval operation is project-scoped
- Incremental ingest: only changed files need to be reprocessed
- Local embeddings: the intended path is local embedding generation, not hosted inference
Retrieval tools:
rag_contextrag_searchrag_full_contextsymbol_searchmap_work_item_to_codebase
Project and runtime tools:
list_projectsget_project_infoget_project_snapshotcontext_info
The ingest path is intentionally not exposed as a standard always-on MCP tool surface.
Main runtime areas:
rag_indexer/: scanning, chunking, embedding, storage, and retrieval logicmcp_server.py: MCP stdio transportmcp_server_http.py: local HTTP transportrag_indexer/cli.py(llm-context, alsocli.py): server launcher and operational ingest and maintenance CLIconfig.example.yaml: example configuration for local setupprojects.example.yaml: project registry example for multi-project mode
files and documents
|
v
scanner -> chunking -> embeddings -> store
|
v
retrieval + filtering + project scope
|
v
MCP context tools
Requirements:
- Python 3.10 or newer
- PostgreSQL with the
pgvectorextension - local embedding runtime support (
sentence-transformers, installed as a dependency)
Install:
pip install -e .Optional symbol extraction (tree-sitter):
pip install -e ".[symbols]"The package installs an llm-context command; python cli.py ... is equivalent.
Create the schema, then ingest a project:
cp projects.example.yaml projects.yaml
llm-context --config config.yaml init-db-v2 --dsn <dsn>
LLM_CONTEXT_INGEST_ENABLED=true llm-context --config config.yaml ingest --dsn <dsn> --project-id <project_id>ingest and query default to the local-st embedder.
Run the MCP server (stdio):
llm-context serve # or: python mcp_server.pyThe stdio transport follows the MCP specification: one JSON-RPC message per line (newline-delimited JSON). Clients that still use LSP-style Content-Length framing can opt in with llm-context serve --legacy-content-length (or python mcp_server.py --legacy-content-length, or MCP_STDIO_FRAMING=content-length).
Run the local HTTP server (binds to 127.0.0.1:8765 by default; /mcp, /rpc and /health):
llm-context serve --transport http # or: python mcp_server_http.pyTool calls run in a worker thread, so a slow query does not block other requests. Only one instance per checkout can run (file lock); a running instance is never killed automatically.
Other CLI commands: list-projects, query, context, export-snapshot. Use llm-context <command> --help for options.
The scripts/ directory contains a few Windows .bat wrappers (init_db, ingest, start_http_server, start_stdio_server, status, stop_http_server) and smoke_test_http.py. reingest_full.bat runs a full re-ingest of this repository with config.ingest.yaml.
Key files:
config.yaml: tracked, neutral runtime defaults. Do not put machine-specific values here.config.example.yaml: a commented example for a fictional repository. Copy it toconfig.local.yaml(untracked, starts withextends: config.yaml) and pointLLM_CONTEXT_CONFIG_PATHor--configat it.projects.example.yaml: project registry template. Copy it toprojects.yaml, which is git-ignored because it describes local paths..env.example: environment variables (DSN, embedder, limits, transport security, model cache)
Runtime state (projects.state.json and project_manifests/) is written under .local/runtime/ by default and is git-ignored. config.rework.yaml and config.ingest.yaml describe the self-indexing setup of this repository (projects.rework.yaml).
Important settings:
projects_registry_pathprojects_state_pathingest_enabled(defaultfalse)write_enabled(defaultfalse)fts_config(defaultsimple)- explicit
project_idon every ingest and MCP retrieval call
Configuration files can extend one another with extends:. Values are coerced to the declared types, so ingest_enabled: "false" is a boolean false. Environment variables such as LLM_CONTEXT_CONFIG_PATH, LLM_CONTEXT_INGEST_ENABLED and LLM_CONTEXT_WRITE_ENABLED override file values.
The embedder (LLM_CONTEXT_EMBEDDER), model (LLM_CONTEXT_LOCAL_MODEL) and dimension (LLM_CONTEXT_EMBEDDING_DIM, default embedding_dim) are server-side settings. MCP tools no longer accept embedder, local_model or embedding_dim from clients: a value equal to the server setting is ignored, any other value is rejected.
Client-controlled sizes are capped: top_k (LLM_CONTEXT_MAX_TOP_K, default 50), symbol limit (LLM_CONTEXT_MAX_SYMBOL_LIMIT, default 200), max_chars (LLM_CONTEXT_MAX_CHARS_LIMIT, default 100000) and query_text length (LLM_CONTEXT_MAX_QUERY_CHARS, default 8000).
Domain-specific behavior lives in configuration, with empty defaults. Each mapping can be set globally in the config file or per project in the registry; a non-empty project value wins.
scope_map: query keywords that narrow retrieval to a path prefixpath_aliases: path fragments rewritten in queries ({from: to})product_targetsandproduct_aliases: used bymap_work_item_to_codebaseto infer the product touched by a work item. Without themproduct_targetisunknown.
projects:
- project_id: shop
root_path: ../acme-shop
scope_map:
src/billing/: [billing, invoice]
product_targets:
storefront: [storefront, web]The project registry is reloaded automatically when projects.yaml, the state file or a manifest changes on disk (checked on /health, list_projects, get_project_info, context_info and on every project-scoped tool call).
Indexed paths and path prefixes use forward slashes (src/api/Controller.cs) on every platform. Existing indexes with backslash paths keep working for path-prefix filters; a full re-ingest rewrites them in posix form.
Keyword search uses the PostgreSQL text search configuration named by fts_config (default simple, which works for any language; english and the other built-in configurations are also valid). The value is used both when chunks are written and when they are queried, so re-ingest after changing it.
For Italian with accent folding, set fts_config: italian_unaccent. init-db-v2 creates it when that value is configured; to create it manually:
CREATE EXTENSION IF NOT EXISTS unaccent;
CREATE TEXT SEARCH CONFIGURATION italian_unaccent (COPY = italian);
ALTER TEXT SEARCH CONFIGURATION italian_unaccent
ALTER MAPPING FOR hword, hword_part, word WITH unaccent, italian_stem;A full ingest (without --incremental) no longer deletes the project index up front. Every file is re-indexed and each document is replaced in a single transaction, so queries keep seeing the previous version until the new one is committed. Documents that disappeared from the source tree are removed at the end of the run.
The HTTP server binds to localhost by default and checks Host and Origin headers against allowlists. Set MCP_AUTH_TOKEN to require Authorization: Bearer <token> on every HTTP endpoint; the server refuses to bind to a non-loopback MCP_HOST without it. mcp_proxy.py and scripts/smoke_test_http.py send the token when MCP_AUTH_TOKEN is set. See SECURITY.md for the threat model and reporting instructions.
pip install -e ".[dev]"
ruff check .
python -m pytest -qTests do not require a running database; tests that need one are skipped. See CONTRIBUTING.md and CHANGELOG.md.
This repository is in active development. The current runtime already supports real local retrieval workflows, but the repo is still evolving toward a cleaner public-facing shape and stronger multi-project ergonomics.
Built with AI-assisted workflows, while architecture, tradeoffs, integration, review, and validation were directed by the author.
llm-memory: persistent operational memory layermcp-dashboard: local control plane and observability surface
MIT. See LICENSE.