Skip to content

Result Handler

Shows how Delta-MCP’s result handler automatically protects the LLM context window from large tool outputs.

What it demonstrates

ScenarioRaw outputHandled output
Large string50 KB text{ truncated: true, preview, totalChars, estimatedTokens }
Long array50 items{ paginated: true, items: [first 5], page, totalPages, hasMore }
Big object100 keys{ _summarized: true, _totalKeys: 100, key_0: "value_0", ... }
Upstream 429thrown error{ type: "rate_limited", retryAfterSeconds, upstream }

Run

Terminal window
npx tsx examples/result-handler/index.ts

Configuration

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 result
await 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"
}

View on GitHub →

See also