Token Lens
FreeMaintainedMCP server for context window optimization — audit token budgets, compress schemas, optimize tool loading
About
MCP server for context window optimization — audit token budgets, compress schemas, optimize tool loading
README
MCP server for analyzing and optimizing context window token usage. MCP tool definitions consume 40-72% of context windows before any user work begins — this server helps you measure, compress, and eliminate that waste.
Install
npx token-lens-mcp
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"token-lens": {
"command": "npx",
"args": ["token-lens-mcp"]
}
}
}
Claude Code
claude mcp add token-lens -- npx token-lens-mcp
Tools
audit_context_budget
Analyze the token cost of your MCP tool definitions. Estimates tokens per tool using chars/4 approximation on the full JSON definition.
Params:
tools— Array of{name, description, schema}objects
Returns: Per-tool token cost (sorted by cost), total tokens, percentage of 128K/200K/1M context windows.
optimize_tool_loading
Given a task description, recommend the minimal set of tools needed. Uses keyword matching and category relevance scoring.
Params:
task_description— What you're trying to accomplishavailable_tools— Array of{name, description, category?}
Returns: Recommended tools sorted by relevance, excluded tools, estimated tokens saved.
compress_schema
Compress verbose tool schemas to reduce token usage.
Params:
tool_name— Name of the toolschema— JSON Schema object to compresslevel—"light"|"medium"|"aggressive"
Levels:
- light — Remove descriptions under 20 chars
- medium — Shorten descriptions to 50 chars, remove examples
- aggressive — Strip all descriptions, keep only types and required fields
Returns: Compressed schema, original/compressed token counts, savings percentage.
analyze_session_usage
Track which tools are actually called vs loaded during a session.
Params:
session_id— Unique session identifieraction—"register_tool"|"log_call"|"report"tool_name— Tool name (required for register_tool/log_call)tool_tokens— Token cost (for register_tool, default 50)
Report returns: Loaded vs used counts, waste percentage, unused tools ranked by token cost.
suggest_removals
Identify tools that can be safely removed based on usage patterns.
Params:
usage_history— Array of{tool_name, call_count, last_used_days_ago}
Scoring: never_used (priority 3) > not_used_30_days (priority 2) > rarely_used (priority 1)
Returns: Removal candidates with reasons and estimated token savings.
get_optimization_report
Full context window health check combining audit, removal suggestions, and compression recommendations.
Params:
tools— Array of tool definitionsusage_history— Optional usage history array
Returns: Executive summary with health grade (excellent/good/fair/poor), audit results, removal suggestions, compression opportunities, and actionable recommendations.
Resources
token-lens://tips
Best practices guide for reducing MCP context window bloat, including schema design tips, token budget guidelines, and dynamic tool loading strategies.
Development
npm install
npm test
npm run dev # watch mode
License
MIT
Installing Token Lens
This server has no published package — it is built from source. Open the repository and follow its README.
▸ github.com/mdfifty50-boop/token-lens-mcpFAQ
Is Token Lens MCP free?
Yes, Token Lens MCP is free — one-click install via Unyly at no cost.
Does Token Lens need an API key?
No, Token Lens runs without API keys or environment variables.
Is Token Lens hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install Token Lens in Claude Desktop, Claude Code or Cursor?
Open Token Lens 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-hzMCP-Agent
A simple, composable framework to build agents using Model Context Protocol by [LastMile AI](https://www.lastmileai.dev)
by lastmile-aiSpring AI MCP Client
Provides auto-configuration for MCP client functionality in Spring Boot applications.
mcp.natoma.ai
A Hosted MCP Platform to discover, install, manage and deploy MCP servers by [Natoma Labs](https://www.natoma.ai)
MCPHub
Website to list high quality MCP servers and reviews by real users. Also provide online chatbot for popular LLM models with MCP server support.
MCP Servers Rating and User Reviews
Website to rate MCP servers, write authentic user reviews, and [search engine for agent & mcp](http://www.deepnlp.org/search/agent)
mkinf
An Open Source registry of hosted MCP Servers to accelerate AI agent workflows.
Compare Token Lens with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All ai MCPs
