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 分