
Token Compressor
io.github.base76-research-lab由 GitHub 账号 base76-research-lab 发布v0.1.1更新于 Oct 24, 2026
Compress prompts 40-60% using local LLM + embedding validation. Preserves all conditionals.
概览
一个本地 MCP 服务器,在提示词送入大模型前先用本地 Ollama 模型压缩,并通过向量相似度校验,以减少 token 用量。
- 可以做什么
- 用本地 Ollama 模型把提示词改写为语义最简形式,保留条件语句和否定表达。用余弦相似度对比原文与压缩文本,低于阈值时原样返回原文。返回压缩文本及统计信息,包括模式、覆盖度以及输入、输出和节省的估算 token 数。对低于可配置 token 下限的短输入跳过压缩。
- 适用场景
- 适合反复向大模型发送长提示词、在意 token 成本或上下文长度的场景,并且希望压缩在本地完成、带有防止语义丢失的校验。短提示词会被跳过,收益有限。
- 运行要求
- 以本地 Python 包运行(需 Python 3.10 及以上),可通过 uvx 或 python3 启动。需要本地运行 Ollama,并已拉取 llama3.2:1b 和 nomic-embed-text 两个模型,还需 ollama 与 numpy 依赖。未声明账号、API 密钥或请求头。
安装
在 SourceWeft 中
- 打开 控制台中的 Token Compressor,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
token-compressor
Reduce LLM prompt tokens by 30–70% while preserving semantic meaning.
mcp-name: io.github.base76-research-lab/token-compressor
Semantic prompt compression for LLM workflows. Reduce token usage by 40–60% without losing meaning.
[License: MIT] [Requires: Ollama] [MCP Compatible]
Built by Base76 Research Lab — research into epistemic AI architecture.
Live demo
Intent Compiler MVP is now live and uses this project as part of the idea -> spec -> compressed output flow:
- Live: https://intent-compiler-mvp.pages.dev
- Product repo: https://github.com/base76-research-lab/token-compressor
What it does
token-compressor is a two-stage pipeline that compresses prompts before they reach an LLM:
- LLM compression — a local model (llama3.2:1b via Ollama) rewrites the prompt to its semantic minimum, preserving all conditionals and negations
- Embedding validation — cosine similarity between original and compressed embeddings must exceed a threshold (default: 0.85) — if not, the original is sent unchanged
The result: shorter prompts, lower costs, same intent.
Key design principle: conditionality is never sacrificed. If your prompt says "only do X if Y", that constraint survives compression.
Requirements
- Python 3.10+
- Ollama running locally
- Two models pulled:
- Python dependencies:
Quick start
Result object:
CLI usage
Output: compressed text on stdout, stats on stderr.
Claude Code hook (recommended setup)
Add to your ~/.claude/settings.json under hooks → UserPromptSubmit:
This runs on every prompt submission and writes the compressed version to a temp file, which can be injected back into context via a second hook or MCP server.
MCP server
The MCP server exposes compression as a tool callable from Claude Code and any MCP-compatible client.
Install:
Tool: compress_prompt
- Input:
text(string) - Output: compressed text + stats footer
Claude Code MCP config (~/.claude/settings.json):
Or from source:
Configuration
How it works
Stage 1 — LLM compression
The compression prompt instructs the model to:
- Preserve all conditionals (
if,only if,unless,when,but only) - Preserve all negations
- Remove filler, hedging, redundancy
- Target 40–60% of original length
Stage 2 — Embedding validation
Computes cosine similarity between the original and compressed text using nomic-embed-text. If similarity falls below threshold, the original is returned unchanged. This prevents silent meaning loss.
Results
Tested across Swedish and English prompts, technical and natural language:
Research background
This tool implements the architecture from:
Wikström, B. (2026). When Alignment Reduces Uncertainty: Epistemic Variance Collapse and Its Implications for Metacognitive AI. DOI: 10.5281/zenodo.18731535
Part of the Base76 Research Lab toolchain for epistemic AI infrastructure.
License
MIT — Base76 Research Lab, Sweden
来源:README.md,提交 1f5e39e
工具
0版本历史
1- v0.1.1最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分