Token Lens

io.github.mdfifty50-boop由 GitHub 帳號 mdfifty50-boop 發布v0.1.2更新於 Oct 24, 2026

Context window token analysis and budget management

已驗證STDIO僅桌面開發者工具AI 與機器學習

概覽

AI 產生的概覽

本機 MCP 伺服器,用來估算並精簡 MCP 工具定義、schema 與工作階段使用量所佔的上下文視窗 token 成本。

可以做什麼
  • 稽核工具定義的單一與總 token 成本,以及佔 128K/200K/1M 上下文視窗的比例
  • 依任務推薦最小工具集並估算可節省的 token
  • 以輕度、中度、積極三種等級壓縮 JSON schema 並回報節省比例
  • 依工作階段記錄已載入與已呼叫的工具,並依成本排序未使用的工具
  • 依使用歷史提出可安全移除的工具建議
  • 產出綜合健康報告(含評級與建議),並提供技巧資源
適用情境
當上下文被大量 MCP 工具定義佔滿,需要量化這項開銷、精簡 schema,或判斷哪些工具可以移除時適用。
執行需求
透過 npx token-lens-mcp 以 stdio 在本機執行,需要 Node.js 與 npx。未宣告任何驗證、環境變數或標頭。
安裝前請注意
token 數是以字元數除以 4 估算,並非實際分詞結果。中度與積極壓縮會移除描述與範例,可能讓模型更難正確使用工具。傳入的工具定義與使用歷史由本機程序處理。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Token Lens,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

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

bash
npx token-lens-mcp

Claude Desktop

Add to claude_desktop_config.json:

json
{  "mcpServers": {    "token-lens": {      "command": "npx",      "args": ["token-lens-mcp"]    }  }}

Claude Code

bash
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 accomplish
  • available_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 tool
  • schema — JSON Schema object to compress
  • level — "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 identifier
  • action — "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 definitions
  • usage_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

bash
npm installnpm testnpm run dev  # watch mode

License

MIT

來源:README.md,提交 f0a843e

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.2最新Sep 16, 2026

評分

已滿足適用檢查項的 40%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

    請在儲存庫或註冊中心條目中宣告授權條款。