Token Optimization
FreeNot checkedA fully offline MCP server for token estimation, prompt compression, model routing, and semantic caching to optimize LLM usage costs and efficiency.
About
A fully offline MCP server for token estimation, prompt compression, model routing, and semantic caching to optimize LLM usage costs and efficiency.
README
Production-ready Model Context Protocol server for token counting, prompt compression, model routing and semantic caching. Zero external API calls — works fully offline.
Tools
| Tool | Description |
|---|---|
estimate_tokens |
Count tokens for any text+model (calibrated chars/token ratios) |
compress_prompt |
Shrink prompts with trim, summarize_hint or aggressive strategy |
route_model |
Pick cheapest model meeting quality + context requirements |
cache_lookup |
Semantic cache hit/miss by prompt or pre-computed key |
cache_store |
Store prompt+result with token-savings metadata |
cache_invalidate |
Remove one or all cache entries |
analyze_context |
Conversation health: role breakdown, issues, recommendations |
savings_report |
Session-level token/USD savings dashboard |
deduplicate_messages |
Remove duplicate turns, count saved tokens |
Quick Start
cd mcps/token-optimization-mcp
uv sync
# stdio – Claude Code / Copilot
uv run main.py
# SSE – LangGraph / CrewAI / browser
uv run main.py --sse --port 8001
Environment Variables
| Variable | Default | Description |
|---|---|---|
USE_REDIS |
false |
Enable Redis backend |
REDIS_URL |
redis://localhost:6379/1 |
Redis connection URL |
CACHE_TTL_SECONDS |
86400 |
Default cache TTL (1 day) |
RATE_LIMIT_PER_MIN |
120 |
Requests/min per client |
AUDIT_LOG_ENABLED |
true |
Print audit log to stdout |
Registration
Claude Code (~/.claude/settings.json)
{
"mcpServers": {
"token-optimization": {
"command": "uv",
"args": ["run", "/path/to/token-optimization-mcp/main.py"]
}
}
}
VS Code Copilot (.vscode/mcp.json)
{
"servers": {
"token-optimization": {
"type": "stdio",
"command": "uv",
"args": ["run", "${workspaceFolder}/mcps/token-optimization-mcp/main.py"]
}
}
}
SSE (LangGraph / CrewAI / Cursor)
http://127.0.0.1:8001/sse
Supported Models (routing catalogue)
| Model | Context | Quality | Cost/1k |
|---|---|---|---|
github:copilot |
128k | 8 | free |
gpt-4o-mini |
128k | 7 | $0.00015 |
claude-3-5-haiku |
200k | 7 | $0.00025 |
gemini-1.5-flash |
1M | 6 | $0.000075 |
gpt-4o |
128k | 9 | $0.005 |
claude-3-5-sonnet |
200k | 9 | $0.003 |
claude-3-opus |
200k | 10 | $0.015 |
Testing
uv run --group test pytest
# 118 tests, 100% coverage
Architecture
token-optimization-mcp/
├── main.py ← FastMCP server (9 tools)
├── pyproject.toml
├── README.md
├── tests/
│ ├── conftest.py ← state-reset fixtures
│ ├── test_helpers.py ← unit tests + Hypothesis
│ └── test_tools.py ← integration tests per tool
└── mcp-servers/
└── context-cache-server/ ← standalone Redis-backed sub-server
├── server.py
├── config.py
└── security.py
Install Token Optimization in Claude Desktop, Claude Code & Cursor
unyly install token-optimization-mcpInstalls into Claude Desktop, Claude Code, Cursor & VS Code — handles npx, uvx and build-from-source repos for you.
First time? Get the CLI: curl -fsSL https://unyly.org/install | sh
Or configure manually
Run in your terminal:
claude mcp add token-optimization-mcp -- uvx --from git+https://github.com/DCx7C5/token-optimization-mcp token-optimization-mcpFAQ
Is Token Optimization MCP free?
Yes, Token Optimization MCP is free — one-click install via Unyly at no cost.
Does Token Optimization need an API key?
No, Token Optimization runs without API keys or environment variables.
Is Token Optimization hosted or self-hosted?
A hosted option is available: Unyly runs the server in the cloud, no local setup required.
How do I install Token Optimization in Claude Desktop, Claude Code or Cursor?
Open Token Optimization on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
Fetch
Web content fetching and conversion for efficient LLM usage.
AWS KB Retrieval
Retrieval from AWS Knowledge Base using Bedrock Agent Runtime.
by modelcontextprotocolSpring AI MCP Server
Provides auto-configuration for setting up an MCP server in Spring Boot applications.
llm-analysis-assistant
A very streamlined mcp client that supports calling and monitoring stdio/sse/streamableHttp, and can also view request responses through the /logs page. It also
by xuzexin-hzCompare Token Optimization with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All ai MCPs
