slimctx-token-optimizer
Provides an MCP server that integrates with GitHub Copilot to compress context before sending to the LLM, reducing token usage while preserving reversible access to original content.
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., "@slimctx-token-optimizer Compress the last 10,000 lines of logs keeping errors verbatim"
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.
slimctx — the token optimizer for AI agents
Zero-dependency, fully-reversible context compression for AI agents.
slimctx compresses what your agent reads — tool outputs, logs, JSON, source files, prose — before it reaches the LLM. Same answers, fraction of the tokens. Pure Python stdlib: no ML models, no downloads, no network calls, ever. Auditable end to end in ~1,600 lines.
from slimctx import Pipeline, Config
pipe = Pipeline(Config(target_tokens=32_000))
result = pipe.compress(messages) # OpenAI/Anthropic-style dicts
print(result.savings_ratio) # e.g. 0.82
original = pipe.retrieve("a1b2c3d4...") # byte-exact original, any timeResults (synthetic workloads modeled on real agent traffic)
Workload | Before | After | Savings | Key facts kept |
Code search (100 results) | 5,557 | 916 | 84% | ✓ |
SRE incident debugging | 61,699 | 298 | 100% | ✓ |
GitHub issue triage | 12,836 | 975 | 92% | ✓ |
Codebase exploration | 5,734 | 2,760 | 52% | ✓ |
Every run also verifies that each planted "needle" (the FIXME, the OOMKill,
the outlier) survives compression, and that every lossy transform is
byte-exact reversible. Reproduce with python3 benchmarks/bench.py.
Related MCP server: claw-tsaver
How it works
messages ──► ContentRouter ──► one of:
├─ JSON : lossless tabularization (repeated keys → header,
│ constant columns → legend), then relevance-ranked
│ row selection only if still over budget
├─ LOG : Drain-style template mining — repeated lines
│ collapse to `pattern [x1432]`; errors verbatim
├─ CODE : AST skeleton — signatures + docstrings kept,
│ bodies elided EXCEPT those relevant to the query
└─ TEXT : extractive sentence selection (BM25 + salience
+ position), verbatim, never paraphrasedThe four guarantees
Universal reversibility. Before any lossy transform, the original goes into a content-addressed store (memory / SQLite / bring-your-own cipher) and the output carries a
[slimctx-ref <hash> ...]marker. The model — or you — can always get the byte-exact original back.Errors are never dropped. Every compressor pins error/warning content: log errors pass verbatim, salient JSON rows are kept, salient sentences outrank filler.
Deterministic output. Same input → byte-identical output, across runs and processes. Compressed prefixes stay stable, so provider prompt-caches (Anthropic/OpenAI) keep hitting.
Net gain or no-op. If a transform doesn't save enough tokens to pay for its marker, the original is kept untouched. The live zone (system prompt + last N messages) is never modified at all.
Why not just use Headroom?
Headroom is the established project in this space and is more featureful today (provider proxy with SSE streaming, agent wrappers, cross-agent memory, an ML compression model). slimctx makes a different set of trade-offs, aimed at locked-down / client-site deployments:
Headroom | slimctx | |
Reversibility | JSON only (CCR); dropped text is gone | every lossy transform |
Log handling | generic text scoring | template mining ( |
Code handling | AST skeleton | AST skeleton + query-relevant bodies kept |
Dependencies | Rust core, ONNX runtime, 261MB HF model | stdlib only |
Network egress | HuggingFace pull on first run | none, ever |
Store encryption | none (plaintext SQLite) | cipher hook (bring your own) |
Determinism | cache-aligner component | by construction (pure functions + memo) |
Audit surface | ~10s of KLOC across 3 languages | ~1,200 lines of Python |
If you need the proxy/wrap ecosystem, use Headroom. If you need something you can read in an afternoon, run air-gapped, and certify for a client environment, use slimctx.
Install / test
pip install slimctx # from PyPI — or vendor the slimctx/ directory
python -m pytest tests/ -q # 26 tests: invariants, not examples
python3 benchmarks/bench.py # reproduce the numbers aboveIntegration sketches
As a library (any framework): call pipe.compress(messages) right
before your provider SDK call; expose pipe.retrieve as a tool named
retrieve so the model can pull originals.
As an MCP server (GitHub Copilot, Claude Code, Cursor, ...): ships built in, stdlib-only:
python3 -m slimctx.mcp_server --db ~/.slimctx/store.dbSee USAGE.md for the GitHub Copilot (.vscode/mcp.json) setup
and a security deployment checklist.
Encrypted store:
from cryptography.fernet import Fernet # optional, your choice
f = Fernet(key)
store = SqliteStore("ccr.db", cipher=(f.encrypt, f.decrypt))
pipe = Pipeline(store=store)License
Apache-2.0. Original implementation — no code derived from Headroom.
Available Tools
3 toolsslimctx_compressA
Compress large tool output, logs, JSON, or file content before reasoning over it. Returns a compact version that preserves errors, outliers, and query-relevant content. If the result contains a [slimctx-ref ...] marker, the full original can be recovered with slimctx_retrieve.
Inputs: text (required), query.
slimctx_retrieveA
Recover the byte-exact original content for a [slimctx-ref ] marker seen in previously compressed output.
Inputs: ref (required).
slimctx_statsC
Token savings accumulated in this session.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool has a clearly distinct role: compress creates a reference, retrieve recovers original content from a reference, and stats reports session token savings. No overlap or ambiguity between them.
All tool names follow a consistent 'slimctx_' prefix followed by a clear verb: compress, retrieve, stats. The pattern is uniform and predictive.
Three tools is an ideal size for this focused server. Each tool is essential to the compression-retrieval-stats lifecycle, and no redundant or extraneous tools exist.
The tool surface fully covers the domain: compressing content, retrieving it when needed, and tracking token savings. There are no obvious workflow gaps for the stated purpose.
Maintenance
Related MCP Connectors
Compress coding-agent context ~64%. Hosted Neural Keep MCP for Cursor/Claude/Codex.
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log
Related MCP Servers
- AlicenseAqualityBmaintenanceAn MCP server that preserves LLM context by intercepting large data outputs and returning only concise summaries or relevant sections. It enables efficient sandboxed code execution, file processing, and documentation indexing across multiple programming languages and authenticated CLIs.1156,064 npm34,423Elastic 2.0
- AlicenseAqualityDmaintenanceAn MCP server that helps AI agents reduce token usage by compressing, summarizing, and managing conversation/context data more efficiently.11MIT
- AlicenseAqualityCmaintenanceLocal-first MCP server that gives any AI coding agent per-project memory, workflow intelligence, and always-on, lossless token & context optimization.378 npm6MIT
- FlicenseNot gradedqualityDmaintenanceSemantic compression MCP server that reduces document token usage by 60-80% using structured symbolic notation, enabling Claude to efficiently store, retrieve, diff, and summarise documents across PRD, CODE, PAPER, and MEETING domains.-