Expand description
Token-budget chunking for large MCP responses.
Constants§
- MIN_
TRANSPORT_ CHUNK_ BUDGET - Minimum transport chunk budget for surfaces that reuse a content
budget as the chunk size — the
overviewCLI passes its--token-budgetstraight intoapply_chunking. A tiny content budget should shrink what is included (the composer’s greedy-fill already drops heavy content), not fragment the always-shipped hard-required body into hundreds of mid-word pieces. So the chunk size is floored here while the content budget stays as the caller set it.
Functions§
- apply_
chunking - Apply chunking to a markdown response. Returns the chunk at
idx(0-based) with appropriate frontmatter metadata. - chunk_
markdown - Split a large response into chunks that fit within a token budget.
Splits at the nearest newline boundary to avoid breaking mid-syntax.
Returns
Noneif the content fits within the budget (no chunking needed). - estimate_
tokens - Estimate token count from a string (rough: chars / 4).
- floor_
chunk_ budget - Floor a requested chunk budget at
MIN_TRANSPORT_CHUNK_BUDGETso a sub-floor budget ships small bodies as one chunk instead of fragmenting them.