Skip to main content

Module chunking

Module chunking 

Source
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 overview CLI passes its --token-budget straight into apply_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 None if 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_BUDGET so a sub-floor budget ships small bodies as one chunk instead of fragmenting them.