
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 分