Token-light local memory with SQLite hybrid retrieval for MCP agents.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste into ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
Context that fits your local LLMs.
TinyContext is a token-light local memory layer for AI agents. It stores concise memories and their embeddings in SQLite, ranks them with hybrid BM25 and dense retrieval, and returns only the context that fits the requested token budget.
No hosted account. No giant context dumps. No required vector database.
| Tier | Use it when | Entry point |
|---|---|---|
| Python library | You are building an agent or Python application | pip install tinysuite-context |
| One-command MCP | An MCP client should launch TinyContext for you | uvx --python 3.12 --from "tinysuite-context[server]" tinycontext |
| Docker | You want persistent self-hosted storage and HTTP MCP | docker compose ... up -d |
The Python library contains the memory engine. MCP, FastAPI, and Docker are
adapters around the same save_memories and recall_memories operations.
Add TinyContext to any stdio MCP client:
The no-argument tinycontext command runs stdio MCP. On its first launch,
TinyContext downloads the selected ONNX embedding bundle into its per-user data
directory. The database is created lazily on the first save or recall. Later
launches reuse both local assets.
Check the resolved configuration and storage readiness with:
TinyContext exposes two tools:
save_memories for durable facts, preferences, decisions, and research notes.recall_memories before answering when previous context may help.MCP recall returns prompt-ready context with explicit memory boundaries:
Python and FastAPI recall remain structured and include the current UTC time plus
each memory's creation timestamp, rank, high/medium/low relevance, and
normalized RRF, dense cosine, and BM25 scores.
Install only the transport-independent core:
Programmatic configuration does not read environment variables or depend on the
checkout. Passing no config uses the per-user data directory returned by
platformdirs.
Run the published image as an MCP server over Streamable HTTP:
Connect an MCP client to:
The data volume persists /data/memories.db and /data/models.
compose.quickstart.yaml is deliberately a local, single-user example. Do
not expose it directly to multiple users. For an authenticated hosted service,
use compose.hosted.yaml behind a reverse proxy:
The proxy is the only component on tinycontext-proxy that may reach the
container. It must authenticate the caller, strip any incoming
X-TinyContext-User-Id header, and inject that header with a stable verified
user ID. Set TINYCONTEXT_TRUSTED_PROXY_CIDRS to the proxy's direct Docker or
private-network CIDR. TinyContext rejects requests from other peers and never
accepts a user ID in an MCP tool or API request body.
Hosted tenancy stores each user in a separate SQLite file under
TINYCONTEXT_TENANT_STORE_DIR; filenames are HMAC-derived and do not expose
the source user ID. Existing /data/memories.db data is not migrated, because
it has no safe ownership attribution. session_id remains an optional scope
inside a single user's store.
Stop the service with:
For a local image build:
The optional FastAPI profile uses the same image:
http://localhost:8000/mcphttp://localhost:8001session_id, rank lexical matches with BM25, and calculate cosine
similarity in SQLite through sqlite-vec.0..1 using the same scoring convention as TinySearch.Relevance labels summarize the normalized hybrid score: high is at least
0.90, medium is at least 0.75, and lower admitted results are low.
Existing TinyContext databases are upgraded in place with nullable embedding columns. The first recall backfills embeddings for legacy rows; no database migration command or separate vector service is required.
Numbers below come from scripts/benchmark_index_recall_speed.py and
scripts/benchmark_token_savings.py, run against an isolated, throwaway
SQLite store (never a real database) with the default fast ONNX embedding
model. Reproduce them yourself:
| Corpus size | Write throughput | Recall p50 | Recall p95 |
|---|---|---|---|
| 100 | 32.0 mem/s | 55.4ms | 131.1ms |
| 500 | 52.5 mem/s | 27.7ms | 30.2ms |
| 2,000 | 30.9 mem/s | 113.8ms | 238.0ms |
| 5,000 | 52.3 mem/s | 146.4ms | 182.6ms |
Recall latency trends upward with corpus size β recall scans candidates rather than using an ANN index, so it's not flat past a few thousand memories. Write throughput holds steady regardless of corpus size.
Against 300 synthetic memories and 8 queries: 96.7% fewer tokens than concatenating every stored memory raw, or roughly $16.42 saved per 1,000 recalls at $3/MTok input pricing (Claude Sonnet 5).
Published numbers from Mem0 (~90%+ token reduction, ~200ms p95 latency) and Zep (~65β200ms p95 latency) put TinyContext at or ahead on token compaction, and competitive on latency at the corpus sizes tested here. That's not an apples-to-apples claim, though β those figures come from real conversational benchmarks (LoCoMo, LongMemEval) with retrieval-accuracy grading in the loop, run at larger scale than tested above.
scripts/benchmark_recall_accuracy.py plants 15 distinct facts inside a
growing pool of filler memories and queries each with a paraphrase, checking
whether hybrid recall returns the right memory id. Locally this comes back
at 100% recall@k and MRR 1.00 from 100 up to 5,000 filler memories β but
the planted facts are semantically distinct from the filler, so this mostly
shows the mechanism works, not that it holds up against confusable,
near-duplicate memories or a real labeled benchmark like LoCoMo/LongMemEval.
This is the one number here we're not standing behind as-is. If you run a harder or larger-scale accuracy eval against TinyContext β adversarial near-duplicates, a real conversational dataset, whatever β we'd genuinely like to see it, good or bad. Open an issue or a PR with what you found.
The optional HTTP API mirrors the two MCP tools.
| Method | Path | Purpose |
|---|---|---|
| GET | /health | Liveness |
| POST/GET | /save_memories | Persist one or more memories |
| POST/GET | /recall_memories | Recall ranked memories within a token budget |
Install and run it directly:
When TINYCONTEXT_TENANCY=proxy-header is enabled, these endpoints require
the same trusted-proxy identity as hosted MCP. The health endpoint remains
available for liveness checks.
| Code | HTTP | Meaning |
|---|---|---|
empty_memory | 400 | Missing or blank memory content/query |
session_not_found | 404 | No memories exist for the requested session |
recall_budget | 400 | Invalid recall budget parameters |
unauthorized | 401 | Hosted request lacks a valid trusted-proxy identity |
internal_error | 500 | Unexpected server error |
The core defaults are:
| Key | Default | Description |
|---|---|---|
memory_db_path | Per-user TinyContext data directory | SQLite database |
recall_top_k | 10 | Maximum memories returned after score filtering |
recall_max_tokens | 2000 | Default recall token budget |
encoding_name | o200k_base | Tokenizer used for budgeting |
models_dir | Per-user TinyContext data directory | Downloaded ONNX bundles |
embedding_model | fast | fast, balanced, quality, or a Hugging Face repository |
embedding_batch_size | 32 | Local ONNX inference batch size |
recall_rrf_cutoff | 0.0 | Minimum normalized hybrid RRF score; zero disables filtering |
recall_dense_weight | 0.5 | Dense contribution to weighted RRF |
recall_rrf_k | 60 | RRF rank constant |
dense_query_prefix | empty | Optional text prepended before embedding queries |
dense_document_prefix | empty | Optional text prepended before embedding memories |
Server processes look for context_config.json in the per-user TinyContext
configuration directory. A relative memory_db_path inside a JSON config is
resolved relative to that file.
Changing embedding_model (or its dimensions) after memories already exist
doesn't require a manual re-embed: save_memories/recall_memories detect
the mismatch and start a background re-embed job automatically. While it's
running, tool responses include a notice field with progress and an ETA
instead of blocking the call until the whole store is caught up.
Environment overrides:
| Variable | Purpose |
|---|---|
TINYCONTEXT_CONFIG_PATH | Use an explicit JSON configuration file |
TINYCONTEXT_MEMORY_DB_PATH | Override the SQLite database path |
TINYCONTEXT_RECALL_TOP_K | Override the default candidate count |
TINYCONTEXT_RECALL_MAX_TOKENS | Override the default token budget |
TINYCONTEXT_ENCODING_NAME | Override the tokenizer |
TINYCONTEXT_MODELS_DIR | Override the ONNX bundle directory |
TINYCONTEXT_EMBEDDING_MODEL | Override the embedding model |
TINYCONTEXT_EMBEDDING_BATCH_SIZE | Override inference batch size |
TINYCONTEXT_RECALL_RRF_CUTOFF | Override the normalized hybrid RRF cutoff |
TINYCONTEXT_RECALL_DENSE_WEIGHT | Override the dense RRF weight |
TINYCONTEXT_RECALL_RRF_K | Override the RRF rank constant |
TINYCONTEXT_DENSE_QUERY_PREFIX | Override the dense query prefix |
TINYCONTEXT_DENSE_DOCUMENT_PREFIX | Override the dense document prefix |
TINYCONTEXT_VERSION | Set the FastAPI/container version |
MCP_TRANSPORT | stdio, sse, or streamable-http |
MCP_HOST | MCP HTTP bind host |
MCP_PORT | MCP HTTP bind port |
MCP_CORS_ORIGINS | Comma-separated CORS origins |
TINYCONTEXT_TENANCY | Set to proxy-header for hosted multi-user isolation |
TINYCONTEXT_TRUSTED_USER_HEADER | Proxy-injected user-ID header; defaults to X-TinyContext-User-Id |
TINYCONTEXT_TENANT_STORE_DIR | Required root directory for per-user SQLite files in hosted mode |
TINYCONTEXT_TENANT_SECRET | Required stable secret (at least 32 bytes) for opaque tenant filenames |
TINYCONTEXT_TRUSTED_PROXY_CIDRS | Required direct proxy CIDR list in hosted mode |
An existing checkout-local database remains usable:
TinyContext supports Python 3.12 and newer. CI tests Python 3.12, 3.13, and 3.14 across Linux, macOS, and Windows.
Source-checkout compatibility shims remain available:
tinycontext.save_memories and tinycontext.recall_memories: Python APItinycontext / tinycontext mcp: stdio MCPtinycontext serve: Streamable HTTP MCPtinycontext doctor: configuration and storage readinesstinycontext.servers.fastapi_server:app: optional FastAPI applicationRelease images are scanned with Trivy, run as a non-root user, and signed with Cosign. See SECURITY.md for details and how to report a vulnerability.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/tinycontext)<a href="https://allmcps.com/mcp/tinycontext"><img src="https://allmcps.com/api/badge/tinycontext?style=directory" alt="Tinycontext on AllMCPs" /></a>