
Token Lens
io.github.mdfifty50-boop由 GitHub 账号 mdfifty50-boop 发布v0.1.2更新于 Oct 24, 2026
Context window token analysis and budget management
概览
本地 MCP 服务器,用于测算并压缩 MCP 工具定义、schema 与会话使用所占的上下文窗口 token 开销。
- 可以做什么
- 审计工具定义的单个与总 token 成本,以及占 128K/200K/1M 上下文窗口的比例
- 针对任务推荐最小工具集并估算可节省的 token
- 按轻度、中度、激进三档压缩 JSON schema 并报告节省比例
- 按会话记录已加载与已调用的工具,并按成本排序未使用工具
- 依据使用历史给出可安全移除的工具建议
- 生成综合健康报告(含评级与建议),并提供技巧资源
- 适用场景
- 当上下文被大量 MCP 工具定义挤占,需要量化这部分开销、精简 schema,或判断哪些工具可以移除时适用。
- 运行要求
- 通过 npx token-lens-mcp 以 stdio 在本地运行,需要 Node.js 与 npx。未声明任何认证、环境变量或请求头。
安装
在 SourceWeft 中
- 打开 控制台中的 Token Lens,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
token-lens-mcp
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
Claude Desktop
Add to claude_desktop_config.json:
Claude Code
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
License
MIT
来源:README.md,提交 f0a843e
工具
0版本历史
1- v0.1.2最新Sep 16, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。