PluginBench
MCP Server
Maintained
MIT

io.github.base76-research-lab/token-compressor MCP Server

io.github.base76-research-lab/token-compressor

Compress LLM prompts 40–60% using local embedding validation while preserving conditionals.

What is the io.github.base76-research-lab/token-compressor MCP server?

The token-compressor MCP server reduces prompt token usage by 40–60% through a two-stage pipeline: LLM-based semantic compression followed by embedding-based validation to ensure meaning is preserved. It requires Ollama with llama3.2:1b and nomic-embed-text models running locally, and guarantees that all conditionals and negations survive compression.

token-compressor cuts prompt length without sacrificing intent by rewriting text through a local LLM, then validating the compressed output against the original using cosine similarity. If the similarity score falls below a configurable threshold (default 0.85), the original prompt is sent unchanged. This is useful for reducing API costs, speeding up inference, and staying within context windows while maintaining semantic fidelity.

How to install io.github.base76-research-lab/token-compressor

Copy-paste configuration for popular MCP clients.

transport: stdio
Config generated by PluginBench — verify against the source before use.
~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "token-compressor": {
      "command": "uvx",
      "args": [
        "token-compressor-mcp"
      ]
    }
  }
}

Tools & capabilities

Tools this server exposes to the agent.

  • compress_prompt — Compresses a text prompt using LLM rewriting and embedding validation, returning the compressed text (or original if validation fails) along with token statistics and coverage metrics.

Use cases

  • Reduce token costs when submitting long prompts to paid LLM APIs like Claude or GPT-4
  • Speed up inference by shrinking context size while preserving conditional logic and negations
  • Automatically compress system prompts and instructions before sending to downstream LLMs
  • Validate that compressed prompts maintain semantic similarity to originals via embedding cosine similarity
  • Integrate prompt compression into Claude Code workflows via MCP hooks

io.github.base76-research-lab/token-compressor MCP server FAQ

What does token-compressor do?

It compresses prompts 40–60% by rewriting them with a local LLM (llama3.2:1b) to remove filler and redundancy, then validates the compressed version against the original using embedding cosine similarity. If similarity drops below a threshold (default 0.85), it returns the original unchanged.

Is token-compressor free?

Yes, it is MIT-licensed and open-source. However, it requires running Ollama locally with two models (llama3.2:1b and nomic-embed-text), which consume local compute resources.

How do I install it in Claude or Cursor?

Install via pip (pip install token-compressor-mcp), then add the MCP server to ~/.claude/settings.json under mcpServers with command 'uvx token-compressor-mcp' or 'python3 -m token_compressor_mcp'. Requires Ollama running locally.

What are the requirements?

Python 3.10+, Ollama running locally, and two models pulled: ollama pull llama3.2:1b and ollama pull nomic-embed-text. Also requires numpy and the ollama Python package.

Does compression preserve conditionals and negations?

Yes. The compression pipeline is explicitly designed to preserve all conditionals (if, only if, unless, when, but only) and negations. If compression would lose these, the original prompt is returned instead.

Can I adjust the compression aggressiveness?

Yes. You can configure the cosine similarity threshold (default 0.85), minimum token count to compress (default 80), and the models used for compression and embedding validation.

README (reference)

Source of truth, from the repository.

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:


What it does

token-compressor is a two-stage pipeline that compresses prompts before they reach an LLM:

  1. LLM compression — a local model (llama3.2:1b via Ollama) rewrites the prompt to its semantic minimum, preserving all conditionals and negations
  2. 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.

Input prompt (300 tokens)
        ↓
  LLM compresses
        ↓
  Embedding validates (cosine ≥ 0.85?)
        ↓
  Pass → compressed (120 tokens)   Fail → original (300 tokens)

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:
ollama pull llama3.2:1b
ollama pull nomic-embed-text
  • Python dependencies:
pip install ollama numpy

Quick start

from compressor import LLMCompressEmbedValidate

pipeline = LLMCompressEmbedValidate()
result = pipeline.process("Your prompt text here...")

print(result.output_text)   # compressed (or original if validation failed)
print(result.report())      # MODE / COVERAGE / TOKENS saved

Result object:

FieldDescription
output_textText to send to your LLM
modecompressed / raw_fallback / skipped
coverageCosine similarity (0.0–1.0)
tokens_inEstimated input tokens
tokens_outEstimated output tokens
tokens_savedDifference

CLI usage

echo "Your long prompt here..." | python3 cli.py

Output: compressed text on stdout, stats on stderr.


Claude Code hook (recommended setup)

Add to your ~/.claude/settings.json under hooks → UserPromptSubmit:

{
  "type": "command",
  "command": "echo \"${CLAUDE_USER_PROMPT:-}\" | python3 /path/to/token-compressor/cli.py > /tmp/compressed_prompt.txt 2>/tmp/compress.log || true"
}

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:

pip install token-compressor-mcp

Tool: compress_prompt

  • Input: text (string)
  • Output: compressed text + stats footer

Claude Code MCP config (~/.claude/settings.json):

{
  "mcpServers": {
    "token-compressor": {
      "command": "uvx",
      "args": ["token-compressor-mcp"]
    }
  }
}

Or from source:

{
  "mcpServers": {
    "token-compressor": {
      "command": "python3",
      "args": ["-m", "token_compressor_mcp"],
      "cwd": "/path/to/token-compressor"
    }
  }
}

Configuration

pipeline = LLMCompressEmbedValidate(
    threshold=0.85,          # cosine similarity floor (lower = more aggressive)
    min_tokens=80,           # skip pipeline below this (not worth compressing)
    compress_model="llama3.2:1b",
    embed_model="nomic-embed-text",
)

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:

InputTokens inTokens outSaved
Research abstract (EN)893857%
Session intent (SV)321844%
Technical instruction472253%
Short command (<80t)——skipped

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

Related MCP servers

CognOS trust scoring (C=p·(1-Ue-Ua)) and session trace storage as MCP tools.

1
Python
View repository →

Exposes a CognOS agent system as a machine-readable graph. Full system snapshot with one tool call.

0
Python
View repository →
FOForums logo

Forums

Active

Ask questions about any GitHub repository and get source-backed answers powered by AI.

41
TypeScript
GPL-3.0
View repository →

Domain attribution and correlation for AI agents, with confidence and per-signal evidence.

Local-first knowledge management with bidirectional LLM sync via Markdown files.

3.3k
Python
AGPL-3.0
View repository →

Attested risk scores for stablecoins, DeFi protocols and wallets, with receipts.

View repository →