Result Handler
Shows how Delta-MCP’s result handler automatically protects the LLM context window from large tool outputs.
What it demonstrates
| Scenario | Raw output | Handled output |
|---|---|---|
| Large string | 50 KB text | { truncated: true, preview, totalChars, estimatedTokens } |
| Long array | 50 items | { paginated: true, items: [first 5], page, totalPages, hasMore } |
| Big object | 100 keys | { _summarized: true, _totalKeys: 100, key_0: "value_0", ... } |
| Upstream 429 | thrown error | { type: "rate_limited", retryAfterSeconds, upstream } |
Run
npx tsx examples/result-handler/index.tsConfiguration
Set limits in the server constructor — they apply to every tool call:
new MyServer({ resultHandler: { maxTokens: 2000, // truncate strings over ~2000 tokens (~8 KB) paginateAfter: 50, // paginate arrays longer than 50 items },});The model controls pagination by passing page and pageSize in tool args:
// model calls this after seeing hasMore: true in the previous resultawait client.callTool("list_records", { page: 2, pageSize: 5 });Rate-limit results give the model enough information to retry:
{ "type": "rate_limited", "retryAfterSeconds": 30, "upstream": "call_rate_limited_api"}See also
- Result Handler — how it works
- Pagination example for a more involved pagination walkthrough