Promptbudget Mcp

io.github.MukundaKatta由 GitHub 帳號 MukundaKatta 發布v0.2.0更新於 Oct 24, 2026

Token-budget-aware text handling: count, truncate, and chunk for LLM prompts.

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

概覽

AI 產生的概覽

本機 MCP 伺服器,在文字進入提示詞前依 token 預算進行計數、截斷與分塊。

可以做什麼
  • 估算文字的 token 數,可對照 max_tokens 上限回傳是否放得下及超出量。
  • 依 token 預算裁剪文字,支援 head、tail、head_tail 與 smart_cut 四種策略。
  • 將長文字切成多個不超預算的區塊,可選擇重疊,方便 RAG 攝取。
適用情境
適合助理在組裝上下文、把聊天紀錄塞進模型視窗,或把長文件送進提示詞時,先做一次大小檢查或切分。
執行需求
以本機 stdio 程序執行,通常透過 npx 啟動 npm 套件 @mukundakatta/promptbudget-mcp;需要 Node.js 以及 Claude Desktop、Cursor、Cline、Windsurf 或 Zed 等 MCP 用戶端。未宣告帳號、金鑰或環境變數。
安裝前請注意
token 數是依每 token 字元數(預設 4)估算,英文誤差約 10-15%,其他語言與程式碼更不準;需要更精確時應提供實際分詞器的比例。截斷會捨棄文字,請審慎選擇策略。

安裝

在 SourceWeft 中

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

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

@mukundakatta/promptbudget-mcp

MCP server for token-budget-aware text handling. Three tools: count, truncate, chunk. Use when an LLM is preparing context, fitting chat history, or feeding long source documents through a prompt.

Tools

ToolWhat it does
count_tokens(text, max_tokens?, chars_per_token?)Pre-flight check. Returns tokens. With max_tokens, also returns fits + overflow_tokens.
truncate_to_token_budget(text, max_tokens, strategy?, ...)Trim text to fit. 4 strategies: head, tail, head_tail, smart_cut.
chunk_to_budget(text, max_tokens, overlap_tokens?, ...)Split long text into multiple under-budget chunks, with optional overlap.

Strategies for truncate

StrategyDropsGood for
headTailLong source docs you want to summarize from the top
tail (default)HeadChat history where latest matters most
head_tailMiddleInstructions + latest turn both matter
smart_cutMiddle, with visible markerSame as head_tail but model knows truncation happened

Real workflows

"Does this fit in my prompt?"

jsonc
// Tool call from your agent{  "name": "count_tokens",  "arguments": { "text": "<...long text...>", "max_tokens": 4096 }}// Returns:{ "tokens": 5230, "max_tokens": 4096, "fits": false, "overflow_tokens": 1134, "chars_per_token": 4 }

If fits: true, send as-is. If fits: false, decide between truncate_to_token_budget (lose info) or chunk_to_budget (multiple LLM calls).

"Make this fit, keep the latest"

jsonc
{  "name": "truncate_to_token_budget",  "arguments": { "text": "<chat history>", "max_tokens": 4096, "strategy": "tail" }}// Returns:{ "truncated": "...", "original_tokens": 5230, "truncated_tokens": 4096, "strategy_used": "tail" }

"Ingest this 50k-token doc into my RAG"

jsonc
{  "name": "chunk_to_budget",  "arguments": { "text": "<long doc>", "max_tokens": 512, "overlap_tokens": 50 }}// Returns:{  "chunks": ["...", "...", "..."],  "chunk_count": 110,  "total_tokens": 50000,  "chunk_max_tokens": 512,  "overlap_tokens": 50}

The overlap_tokens value lets sentences at chunk boundaries still have surrounding context in the next chunk — important for RAG retrieval quality.

Token counting accuracy

The default chars_per_token = 4 is the OpenAI rule of thumb. It's accurate within ~10–15% for English. For accurate accounting against a specific model, plug in your real tokenizer's chars-per-token ratio:

TokenizerChars/token (English)
cl100k_base (GPT-4, GPT-3.5)~4
o200k_base (GPT-4o)~4.5
Claude tokenizer~3.5
Llama 3~3.8

For non-English text, divide further (Chinese is ~1 char/token, code is ~3 chars/token).

Install — Claude Desktop

json
{  "mcpServers": {    "promptbudget": {      "command": "npx",      "args": ["-y", "@mukundakatta/promptbudget-mcp"]    }  }}

Same shape for Cursor / Cline / Windsurf / Zed.

Run directly (no MCP client)

bash
npx -y @mukundakatta/promptbudget-mcp

The server speaks MCP over stdio. Pair with mcptools or your client of choice. If nothing prints to the terminal, that is correct: stdio servers wait silently for an MCP client to connect.

Sibling library

The Rust crate promptbudget implements the same logic in pure Rust, in case you'd rather link the algorithm into a non-MCP context.

Changelog

  • 0.2.0 (2026-05-10) — added count_tokens (pre-flight check) and chunk_to_budget (split-with-overlap). README expanded with workflow examples + tokenizer ratio table.
  • 0.1.1 (2026-05-09) — added mcpName field for MCP Registry compatibility.
  • 0.1.0 (2026-05-09) — initial release with truncate_to_token_budget.

License

MIT OR Apache-2.0.

來源:packages/promptbudget-mcp/README.md,提交 6fad5bb

工具

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

版本歷史

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

評分

已滿足適用檢查項的 50%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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