About promptbudget-mcp
promptbudget-mcp is an MCP server for preparing text to fit LLM token budgets. It provides token estimates, truncation strategies, and chunking with optional overlap for agents handling prompts, chat history, and long documents.
Key features
- 01Estimate token counts and overflow
- 02Truncate text with four strategies
- 03Split text into budgeted chunks
- 04Add overlap between chunks
Use cases
- 01Check whether text fits a prompt limit
- 02Keep recent turns in a bounded chat history
- 03Prepare long documents for chunked processing
MCP support
Exposes count_tokens, truncate_to_token_budget, and chunk_to_budget as tools to MCP clients over stdio.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
Tools
3Saved tool list · updated 3w ago
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | |
| max_tokens | integer | No | Optional. If provided, response includes 'fits' and 'overflow_tokens'. |
| chars_per_token | integer | No | Approx chars per token. Default 4 (OpenAI rule of thumb). |
Details
From the project 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
| Tool | What 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
| Strategy | Drops | Good for |
|---|---|---|
head | Tail | Long source docs you want to summarize from the top |
tail (default) | Head | Chat history where latest matters most |
head_tail | Middle | Instructions + latest turn both matter |
smart_cut | Middle, with visible marker | Same as head_tail but model knows truncation happened |
Real workflows
"Does this fit in my prompt?"
// 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"
{
"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"
{
"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:
| Tokenizer | Chars/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
{
"mcpServers": {
"promptbudget": {
"command": "npx",
"args": ["-y", "@mukundakatta/promptbudget-mcp"]
}
}
}
Same shape for Cursor / Cline / Windsurf / Zed.
Run directly (no MCP client)
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) andchunk_to_budget(split-with-overlap). README expanded with workflow examples + tokenizer ratio table. - 0.1.1 (2026-05-09) — added
mcpNamefield for MCP Registry compatibility. - 0.1.0 (2026-05-09) — initial release with
truncate_to_token_budget.
License
MIT OR Apache-2.0.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.