Promptbudget Mcp

io.github.MukundaKattaPublished by GitHub account MukundaKattav0.2.0Updated Oct 24, 2026

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

VerifiedSTDIODesktop onlyDeveloper ToolsAI & ML

Overview

AI-generated overview

Local MCP server that counts, truncates and chunks text to fit an LLM token budget before it goes into a prompt.

What you can do
  • Count estimated tokens in text, optionally against a max_tokens limit, returning whether it fits and how much it overflows.
  • Trim text to a token budget using head, tail, head_tail or smart_cut strategies.
  • Split long text into multiple under-budget chunks with optional overlap for RAG ingestion.
When to use it
Useful when an assistant is assembling context, fitting chat history into a model window, or feeding long source documents through a prompt and needs a pre-flight size check or a split.
Requirements
Runs as a local stdio process, typically launched with npx from the npm package @mukundakatta/promptbudget-mcp; needs Node.js and an MCP client such as Claude Desktop, Cursor, Cline, Windsurf or Zed. No accounts, keys or environment variables are declared.
Before you install
Token counts are estimates based on a chars-per-token ratio (default 4), accurate only within roughly 10-15% for English and less so for other languages or code; supply a real tokenizer ratio for tighter accounting. Truncation discards text, so choose the strategy deliberately.

Installation

In SourceWeft

  1. Open Promptbudget Mcp in the dashboard and add it to a workspace.
  2. Enable the server for the chats that should use its tools.

Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.

Other MCP clients

Follow the launch instructions in the repository.

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.

Source: packages/promptbudget-mcp/README.md at commit 6fad5bb

Tools

0
SourceWeft has not started this package in its sandbox yet, so its tools are not known.

Version history

1
  1. v0.2.0LatestSep 16, 2026

Score

50% of the applicable checks met

How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.

  • Reached in the last 30 days25 pts

    Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.

  • Auth declared10 pts

    Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.

  • Tools listed15 pts

    Answer tools/list without a credential, or ship a package that starts in a sandbox without one.

  • DescriptionRequired15 pts
  • Logo10 pts
  • Documentation15 pts
  • License10 pts