tokenslim-mcp
Provides context compression via the tokenslim engine, enabling MCP hosts to reduce token usage while preserving key information. Offers compress, retrieve, and stats tools for managing compressed content.
README
tokenslim-mcp
MCP server exposing the tokenslim
context-compression engine to any MCP host (Claude Code, Cursor, …). Stdio
transport, built on the official Python mcp SDK (FastMCP).
Tools
| Tool | Args | Returns |
|---|---|---|
tokenslim_compress |
content: str, content_type?: str |
Compressed text, CCR hash, changed, and stats (orig_tokens / new_tokens / saved_tokens / ratio). |
tokenslim_retrieve |
hash: str |
{ found, hash, content } — the original blob, or found: false if unknown to this session. |
tokenslim_stats |
— | Cumulative session savings: compressions, orig_tokens, new_tokens, saved_tokens, ratio. |
content_type is an advisory hint echoed back; the core auto-detects the real
type (JSON / log / code / diff / search / markdown / text) and picks a compressor.
Install & register
pip install -e . # pulls the tokenslim core via git
Register as a stdio MCP server. Example (Claude Code mcpServers):
{
"mcpServers": {
"tokenslim": { "command": "tokenslim-mcp" }
}
}
or run directly: tokenslim-mcp / python -m tokenslim_mcp.
How it works
Each tokenslim_compress call wraps the blob as a one-message array, runs it
through the core compress() (with min_bytes=0 so single blobs always get
compressed), and returns the rewritten text plus token stats. The original is
stored under its tokenslim.ccr.content_hash so tokenslim_retrieve can return
it verbatim. tokenslim_stats reports the running total.
Development
pip install -e ".[dev]"
ruff check .
python -m pytest -q
Tests call the tool handlers directly and exercise the FastMCP dispatch — no live MCP host or API keys required.
Known gaps
- Retrieval store is in-process. The core ships CCR markers +
content_hashbut not yet aretrieve()/ persistent store onmain, so retrieval is backed by a per-session dict populated bytokenslim_compress. Hashes already use the core'scontent_hash, so this will switch to the core CCR store once merged (TODO(core-ccr)inengine.py). A hash from a previous process (or another server instance) will reportfound: false. - Compression depth is whatever the core provides; this server adds no algorithms of its own.
License
Apache-2.0
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.