
Token Compressor
io.github.base76-research-labPublished by GitHub account base76-research-labv0.1.1Updated Oct 24, 2026
Compress prompts 40-60% using local LLM + embedding validation. Preserves all conditionals.
Overview
A local MCP server that compresses prompts before they reach an LLM, using a local Ollama model plus embedding validation to cut token counts while keeping the
- What you can do
- Compress a prompt to its semantic minimum with a local Ollama model, preserving conditionals and negations, then validate the result by cosine similarity against the original and fall back to the original text if it falls below the threshold. Return the compressed text with a stats footer covering mode, coverage and estimated tokens in, out and saved. Skip compression for short inputs below a configurable token floor.
- When to use it
- Useful when long prompts are sent repeatedly to an LLM and token cost or context length matters, and you want compression done locally with a safety check against meaning loss. Less useful for short prompts, which are skipped anyway.
- Requirements
- Runs as a local Python package (Python 3.10+) via uvx or python3. Needs Ollama running locally with the llama3.2:1b and nomic-embed-text models pulled, plus the ollama and numpy Python dependencies. No accounts, API keys or headers declared.
Installation
In SourceWeft
- Open Token Compressor in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
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
Source: README.md at commit 1f5e39e
Tools
0Version history
1- v0.1.1LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts