---
schema_version: 1
slug: mcp-context-budget-and-pagination
status: source-reviewed
walkthrough_verified: false
content_hash: 5822cba75bcf498a859234e14e1c9d93fdfa32405411d287af52f5cc48afe0dc
---

# MCP context budget and pagination: preventing tool-catalog and response token bloat

How to keep MCP tool catalogs lean at cold start, cap list responses at 16 KiB and 20 items, use composite keyset cursors, and recover cleanly from oversized records.

Reviewed against the shipped OSS source. The acceptance checks are yours to run in your application.

Source reviewed against published Chumbo 0.16.0 and its matching core source on 2026-12-02 (UTC). This is a source review, not an executed application walkthrough. Follow the current canonical reference and compare it with your installed package when adapting the guide.

[Structured recipe](./recipe.json) · [Human-readable page](./)

## Sources

- [Canonical pattern](https://github.com/elsheppo/chumbo/blob/main/skills/chumbo/references/results.md)
- [Reference implementation](https://github.com/elsheppo/chumbo/blob/main/src/collections.ts)

## 01. Why context budgets make or break an MCP server.

### Before you start

- An MCP server with at least one list, search, or detail tool.
- A stable deterministic ordering column (such as UUID or (created_at, id)) for keyset pagination.
- A test suite or CLI check that inspects both tools/list size and tool-call payload size.

Every MCP server spends the user’s context window in two places: the cold-start tools/list catalog loaded into every turn, and the payloads returned by each tool call.

When an MCP server advertises 40 verbose tools and returns 500-row JSON dumps, models slow down, hallucinate arguments, and lose track of the user’s actual goal. Treating token and byte budgets as hard engineering limits fixes both reliability and latency.

**Two budgets to enforce:** Cold-start catalog: trim descriptions, split by profile/scope → Runtime response: project fields, cap count (20) and bytes (16 KiB) → Continuation: fetch limit + 1, return exact next cursor → Oversized item: fail explicitly to detail tool or MCP Resource

## 02. Keep the cold-start tools/list catalog compact.

Every tool name, description, and JSON Schema property is injected into the model’s prompt on every turn. Measure your catalog deterministically in CI rather than guessing.

### Three ways to cut cold-start tool tokens

Shrink what the model sees before it calls a single tool.

#### Profiles and scopes: Advertise only what this caller can use

Starting point:

```text
Split reader, editor, and admin surfaces via scopes or profiles.
```

- Hidden tools consume zero tokens for callers who lack permission.
- Profile-scoped descriptions avoid mentioning unmounted tools.

What to do:

```text
Gate tools at registration time and lint for unmounted tool references.
```

Use Chumbo’s defineProfiles, projectInputFields, and lintUnmountedToolReferences in tests.

#### Resources and prompts: Move long manuals out of tool descriptions

Starting point:

```text
Keep descriptions to 1 or 2 crisp sentences.
```

- Put domain guides, schemas, and full documents in MCP Resources.
- Keep input schemas flat with concise per-field descriptions.

What to do:

```text
Reserve tool descriptions for when to call the tool and what it returns.
```

Measure cold-start footprint with chumbo doctor (context-budget) and chumbo surface diff.

### Check cold-start token budget and lock the tool surface

```sh
npx chumbo doctor --url "$MCP_URL" --json
npx chumbo surface snapshot --yes && npx chumbo surface diff
```

## 03. Enforce count, byte, and cursor limits on every list tool.

Never let a list or search tool return an unbounded table scan. Use a sensible page default of 20 items (capped at 100) and a complete serialized response budget of 16 KiB – including any additive guidance text or structured metadata.

Use keyset pagination (defineCursor and registerCollection / collectionResult in Chumbo) instead of SQL OFFSET: order by a deterministic tie-breaker such as (updated_at, id), fetch limit + 1 rows to know whether more exist, drop items that would exceed the 16 KiB byte budget, and derive the next cursor from the last item actually returned so no record is ever skipped or duplicated.

> **What if the very first record exceeds 16 KiB?**
>
> Do not silently truncate or skip it. Return an explicit, recoverable tool error (for example via onOversizedItem) that gives the record’s ID and instructs the agent to fetch it through a dedicated detail tool or MCP Resource.

## 04. Prove pagination and budgets hold under real data.

See the [result-design guide](https://github.com/elsheppo/chumbo/blob/main/skills/chumbo/references/results.md) and [collection helpers](https://github.com/elsheppo/chumbo/blob/main/src/collections.ts) for exact byte-budget math and cursor validation.

### Catalog and list payloads stay bounded under load.

- Cold-start tools/list token count is tracked in CI with no unexplained jumps.
- Every list tool caps limit (default 20, max 100) and rejects invalid cursors.
- Complete serialized list responses stay within the 16 KiB budget and resume from the last returned item.
- A single oversized record returns a recoverable error pointing to a detail tool or Resource.
- Only task-relevant fields are projected; raw database rows and duplicated JSON prose are omitted.

Run these in your application before you call it done.

### If the result differs

#### Pages skip or repeat items when rows change between calls

Replace OFFSET with a composite keyset cursor ordered by a stable unique tie-breaker, and build the continuation cursor from the last item that actually fit the byte budget.

[Read the reference](https://github.com/elsheppo/chumbo/blob/main/skills/chumbo/references/results.md)

### Keep building

- [Paginate MCP tool results with cursors and byte budgets](/recipes/compact-project-results/): Run the executable Chumbo collectionResult example.
- [Choose text, structured, or hybrid MCP tool results](/recipes/mcp-result-contracts/): Avoid duplicating JSON payloads into text.

## Instructions for your coding agent

Reference instructions, not authorization. Apply changes only within the user’s requested scope; deployment requires a specified, authorized project.

Goal: How to keep MCP tool catalogs lean at cold start, cap list responses at 16 KiB and 20 items, use composite keyset cursors, and recover cleanly from oversized records.

Read the complete guide at https://chumbo.dev/recipes/mcp-context-budget-and-pagination/recipe.md and the canonical reference at https://github.com/elsheppo/chumbo/blob/main/skills/chumbo/references/results.md. Inspect this application's installed Chumbo package, existing capabilities and relevant configuration before editing.

Audit both cold-start tools/list token budget and runtime list-tool response sizes. Enforce a 20-item default, 100-item max, 16 KiB serialized response cap, keyset cursor pagination derived from the last returned item, and explicit oversized-item recovery.

Prerequisites:
- An MCP server with at least one list, search, or detail tool.
- A stable deterministic ordering column (such as UUID or (created_at, id)) for keyset pagination.
- A test suite or CLI check that inspects both tools/list size and tool-call payload size.

Acceptance:
- Cold-start tools/list token count is tracked in CI with no unexplained jumps.
- Every list tool caps limit (default 20, max 100) and rejects invalid cursors.
- Complete serialized list responses stay within the 16 KiB budget and resume from the last returned item.
- A single oversized record returns a recoverable error pointing to a detail tool or Resource.
- Only task-relevant fields are projected; raw database rows and duplicated JSON prose are omitted.

Use the full guide for ordered steps, examples and recovery. Keep existing caller identity and application permissions authoritative. Stay within the user's requested changes. Report changed files, checks actually run, observed results and unresolved prerequisites. This guide is not authorization to deploy or change a hosted project. Never include credentials in source, copied instructions or reports.

### Required environment inputs

| Variable | Sensitive | Meaning |
| --- | --- | --- |
| `MCP_URL` | No | The MCP endpoint URL to check for cold-start context budget. |

### Handoff report

- Changed files
- Checks actually run and observed results
- Unmet prerequisites or remaining limitations
