
Token Optimizer
io.github.omkar9854由 GitHub 帳號 omkar9854 發布v0.1.0更新於 Oct 24, 2026
Reversible context compression for AI agents: cut token usage up to 94%, originals retrievable
概覽
一個本機 MCP 伺服器,在上下文(工具輸出、日誌、JSON、程式碼、文字)送進大型語言模型前先行壓縮,並可取回逐位元組一致的原文。
- 可以做什麼
- 在上下文送進模型前壓縮,依 JSON、日誌、程式碼與文字分別採用無損或可逆轉換以降低 token 用量。透過引用標記按需取回任何壓縮內容的逐位元組原文。錯誤與警告內容原樣保留,系統提示與最近訊息不會被修改。原文可存放於記憶體、SQLite 或自備的加密儲存。
- 適用情境
- 適合代理程式讀取大量工具輸出、日誌、JSON 資料或原始碼,且 token 成本或上下文長度成為問題時使用,尤其適用於禁止對外連線或需交付客戶環境的情境。
- 執行需求
- 透過 uvx 從 PyPI 套件 slimctx 以本機程序執行(Python,僅用標準函式庫)。README 的 MCP 範例需指定一個 SQLite 儲存路徑。未宣告帳號、API 金鑰、環境變數或請求標頭。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Token Optimizer,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
slimctx — the token optimizer for AI agents
[CI] [PyPI] [MCP Registry] [License: Apache 2.0] [Python 3.9+] [Dependencies: zero]
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.
[slimctx demo: 61,700 tokens compressed to 298 in 29ms, FATAL lines preserved, byte-exact retrieval]
Live output of python3 benchmarks/demo.py — run it yourself, nothing is staged.
Results (synthetic workloads modeled on real agent traffic)
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.
How it works
The 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:
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
Integration 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:
See USAGE.md for the GitHub Copilot (.vscode/mcp.json) setup
and a security deployment checklist.
Encrypted store:
License
Apache-2.0. Original implementation — no code derived from Headroom.
來源:README.md,提交 f2cc938
工具
0版本歷史
1- v0.1.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分