tksq
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@tksq compress this text at medium level and show the token savings"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
tksq
Universal LLM token compression MCP server. Squeeze your tokens.
tksq reduces token consumption when working with LLMs by compressing text through a multi-stage pipeline. It removes filler phrases, applies concise substitutions, eliminates redundancies, and normalizes whitespace — all while preserving code blocks, URLs, and semantic meaning.
Works as an MCP server with any compatible client: Claude Code, Cursor, VS Code, and more.
Features
4-stage compression pipeline: Cleanup, Semantic, Structural, Shorthand
3 compression levels: light, medium, aggressive
Multilingual: English and Russian language packs with full pipeline support
4 domain dictionaries: general, programming, legal, academic
Learning buffer: Discovers repeating patterns, suggests new substitutions
Agent orchestration: Ready-made tools for multi-agent token optimization
9 MCP tools for compression, analysis, configuration, and monitoring
Related MCP server: latent-gate
Quick Start
With Claude Code
Add to your MCP config (.mcp.json):
{
"mcpServers": {
"tksq": {
"command": "npx",
"args": ["-y", "tksq"]
}
}
}With Cursor
Add to .cursor/mcp.json:
{
"mcpServers": {
"tksq": {
"command": "npx",
"args": ["-y", "tksq"]
}
}
}How It Works
tksq processes text through up to 4 compression stages:
Input: 120 tokens
-> [Cleanup]: 115 tokens (-4.2%) # whitespace, fillers, redundancy
-> [Semantic]: 85 tokens (-26.1%) # phrase substitution, abbreviations
-> [Structural]: 82 tokens (-3.5%) # dedup, pattern collapse
-> [Shorthand]: 75 tokens (-8.5%) # telegraphic, deverbal nouns
Total: 120 -> 75 tokens (37.5% saved)What gets compressed
Filler phrases: "I would like to", "it is worth noting that", "basically" -> removed
Verbose phrases: "in order to" -> "to", "due to the fact that" -> "because"
Redundancies: "completely unique" -> "unique", "return back" -> "return"
Whitespace: multiple blank lines, trailing spaces, extra spaces
Russian: fillers, bureaucratic constructions, deverbal nouns, pronoun elision
What stays untouched
Code blocks (fenced and inline)
URLs
Long quoted strings
Custom patterns you specify
Tools
Core Compression
tksq_compress
Compress text with full per-stage statistics.
Parameters:
text (required) The text to compress
level (optional) "light" | "medium" | "aggressive"
domain (optional) "general" | "programming" | "legal" | "academic"
language (optional) "auto" | "en" | "ru"
tokenizer (optional) "cl100k_base" | "o200k_base" | "approximate"
preserve_patterns (optional) Additional regex patterns to preservetksq_count
Count tokens without compressing.
tksq_diff
Show word-level diff between original and compressed text.
tksq_benchmark
Benchmark compression across all levels side by side.
Configuration
tksq_configure
Read or update persistent configuration. Shows current settings, custom substitutions, promoted patterns, and learning config.
Learning
tksq_learn
Manage the learning buffer — patterns discovered from your usage.
Actions:
list Show candidate patterns with frequency counts
promote Activate a candidate as a compression substitution
reject Remove a false positive from candidates
add Manually add a pattern (phrase -> replacement)
reset Clear all learned data
stats Show compression statisticstksq_dashboard
Comprehensive overview: all-time stats, configuration, learning buffer state, dictionary sizes.
Agent Orchestration
tksq_agent_prompt
Get a ready-made system prompt snippet for multi-agent token optimization. Include in agent system prompts to enable pipeline-wide compression.
Parameters:
role (required) "child" | "parent"
style (optional) "default" | "aggressive"tksq_pack
Compress agent output for return to parent agent. Optimized for pipelines: preserves code blocks, file paths, line numbers. Returns compressed text with minimal metadata footer.
Parameters:
text (required) Agent output to compress
level (optional) "medium" | "aggressive"
language (optional) "auto" | "en" | "ru"Compression Levels
Level | Stages | Expected Savings |
light | Cleanup | 5-15% |
medium | Cleanup + Semantic | 20-40% |
aggressive | All 4 stages | 30-50%+ |
Multilingual Support
tksq auto-detects language (English/Russian) and applies the appropriate language pack.
Russian includes:
52 filler phrases, 99 substitutions, 49 redundancies
Pronoun elision, patronymic compression, comparative expansion
Deverbal noun compression (48 patterns across 10 verb families)
Bureaucratic phrase simplification
Domain Dictionaries
general (default): Prose-focused filler removal and substitutions
programming: Code abbreviations ("function" -> "fn", "configuration" -> "config")
legal: Legal-specific terminology and substitutions
academic: Academic writing patterns and abbreviations
Learning Buffer
tksq observes your compression patterns and discovers repeating phrases. When a phrase appears frequently enough, it suggests a shorthand substitution.
tksq_compress("...text...") -> tracks repeating n-grams
tksq_learn(action: "list") -> shows candidates with counts
tksq_learn(action: "promote", phrase: "machine learning", replacement: "ML")Promoted patterns are automatically applied in future compressions.
Data persists at:
Windows:
%APPDATA%\tksq\learned.jsonLinux/Mac:
~/.config/tksq/learned.json
Multi-Agent Orchestration
In multi-agent pipelines (Claude Code Task tool, etc.), tksq reduces token costs across the agent tree:
Parent agent includes
tksq_agent_prompt(role: "parent")in its contextChild agents get
tksq_agent_prompt(role: "child")in their system promptsBefore returning results, child agents call
tksq_packon their outputParent reads compressed results directly (LLMs handle compressed text well)
Typical savings: 20-40% reduction on natural-language analysis text per agent.
Configuration
Config file location:
Windows:
%APPDATA%\tksq\config.jsonLinux/Mac:
~/.config/tksq/config.json
{
"level": "medium",
"tokenizer": "cl100k_base",
"domain": "general",
"language": "auto",
"preservePatterns": [],
"customSubstitutions": {},
"learning": {
"enabled": true,
"minFrequency": 5,
"autoPromote": false,
"maxCandidates": 100
}
}Development
git clone https://github.com/Nexonium/tksq.git
cd tksq
npm install
npm run build
npm testProject Structure
src/
index.ts # Entry point (stdio MCP transport)
server.ts # MCP server, 9 tool registrations
pipeline/
Pipeline.ts # Stage orchestrator
stages/
CleanupStage.ts # Whitespace, fillers, redundancy
SemanticStage.ts # Substitutions, abbreviations
StructuralStage.ts # Dedup, pattern collapse
ShorthandStage.ts # Telegraphic, deverbal nouns
preserver/
PatternPreserver.ts # Protect code blocks, URLs
tokenizer/
TokenCounter.ts # tiktoken + approximate counter
dictionaries/
languages/
en.ts # English language pack
ru.ts # Russian language pack
types.ts # LanguagePack, ShorthandConfig
registry.ts # Language registry
domains/
general.ts, programming.ts, legal.ts, academic.ts
DictionaryLoader.ts # Dictionary loading and merging
language/
LanguageDetector.ts # Auto language detection
WordBoundary.ts # Unicode-aware word boundaries
learning/
types.ts # CandidatePattern, LearnedData, LearningConfig
PhraseStore.ts # JSON persistence for learned patterns
PhraseTracker.ts # Frequency analysis, replacement suggestion
config/
ConfigManager.ts # Persistent user config
defaults.ts # Default values
diff/
TextDiffer.ts # Word-level diffAvailable Tools
9 toolstksq_agent_promptA
Get a ready-made system prompt snippet for multi-agent token optimization. Returns instructions that tell agents to compress their output via tksq. Include the returned text in agent system prompts to enable pipeline-wide compression.
Inputs: role (required), style.
tksq_benchmarkA
Benchmark compression on a text sample across all levels and domains. Shows token reduction for each level (light, medium, aggressive) side by side. Helps choose optimal compression settings for your content.
Inputs: text (required), domain, language, tokenizer.
tksq_compressA
Compress text to reduce LLM token usage while preserving meaning. Removes filler phrases, applies concise substitutions, and normalizes whitespace. Automatically preserves code blocks, inline code, and URLs. Returns compressed text with token reduction statistics.
Inputs: text (required), level, domain, language, +2 more.
tksq_configureA
Read or update tksq configuration. Without arguments, returns current settings. With arguments, updates the specified settings and persists them.
Inputs: level, domain, language, tokenizer, +2 more.
tksq_countA
Count the number of LLM tokens in the given text. Supports multiple tokenizer encodings. Useful for checking token usage before and after manual edits.
Inputs: text (required), tokenizer.
tksq_dashboardA
Show a comprehensive dashboard with session stats, all-time stats, configuration overview, learned patterns, and dictionary sizes. Provides a quick overview of tksq's state and effectiveness.
Inputs: no named parameters.
tksq_diffA
Show a word-level diff between original and compressed text. Highlights what was removed and what was substituted. Accepts either two texts to compare, or a single text that will be compressed first.
Inputs: original (required), level, domain, language, +1 more.
tksq_learnB
Manage the learning buffer. List candidate patterns discovered from usage, promote them to active substitutions, reject false positives, or add manual patterns. Use 'stats' action to see compression statistics.
Inputs: action (required), phrase, replacement.
tksq_packA
Compress agent output for efficient return to parent agent. Optimized for multi-agent pipelines: applies medium/aggressive compression while preserving code blocks, file paths, line numbers, and key identifiers. Returns only the compressed text (minimal overhead). Use this as the last step before returning results from a child agent.
Inputs: text (required), level, language.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Most tools are crisply distinct (compress, count, diff, benchmark, configure, dashboard). The main overlaps are compress vs tksq_pack (a specialized compression variant for agent output) and dashboard vs the 'stats' action inside tksq_learn, both of which are separable from descriptions but still invite misselection.
All nine tools use the same predictable tksq_<verb/noun> snake_case pattern with no deviations or mixed conventions. The prefix and short single-word suffixes make the set easy to scan.
Nine tools is well within the sweet spot for a token-compression utility, and each one covers a distinct facet (compression, measurement, inspection, tuning, learning, reporting, integration). Nothing feels padded or missing at the count level.
The surface covers the full compression workflow: measure, compress, compare, benchmark, configure, learn, report, and integrate into agents. Minor gaps exist, such as no tool to reset/clear the learning buffer or stats and no batch/multi-text compression operation, but these are workable around existing tools.
Maintenance
Related MCP Connectors
Compact WebVTT/SRT transcripts, .eml email threads, Slack exports & Jira ADF JSON by 65-90%.
Compress prose for LLM context windows. Per-call USDC billing, signed receipt.
Cut tokens from HTML, JSON, logs and public URLs into compact context for LLMs.
Free no-LLM token savers: URL→Markdown, outline, JSON trim, log compress, token count; x402 extras
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables local-first context compression for AI agents, offering tools to compress text, retrieve original content, and get compression statistics.MIT
- FlicenseNot gradedqualityBmaintenanceShrinks logs, JSON, docs and web pages before your AI reads them: offline, deterministic, no API key. Folds repetitive log lines (12,037 to 127 tokens on a 400-line log) while code, URLs and quoted strings come back byte-for-byte. Also fetches URLs as clean text, counts tokens exactly, and has optional local Ollama tools for image and text compression.46 PyPI25-
- FlicenseNot gradedqualityNot gradedmaintenanceEnables MCP-compatible clients and autonomous agents to dynamically compress long-horizon context by pruning verbose tool outputs, HTML boilerplate, and semantic redundancy by 40-70%. It reduces token burn and latency through deterministic, zero-dependency processing.-
- AlicenseAqualityBmaintenanceEnables agents to shrink test output, logs, JSON, diffs and OpenAPI documents before reading them, replacing omitted content with markers that can be expanded later. Also reports tokens and money saved, so users can verify what was kept.771 PyPIMIT