Engineering · · 4 min read
When a tool response is too large, keep the fields the task needs
Reduce oversized tool results without cutting off identifiers, continuation state, or evidence needed for the next action.
A tool finds the right customer, returns a large JSON object, and pushes the conversation over its context limit. The next attempt trims the response to its first few thousand characters, so the customer identifier is visible and the support commitment at the end is gone.
This is a response design problem before a model selection problem: can the agent finish the job with the fields it receives? An MCP community discussion about one API becoming many tools raises the tradeoff between useful projections and overlapping tool definitions.
Start with the next decision#
List the decisions the response must support. An account brief needs the owner, renewal date, open commitment summaries, and links to source records, and skips historical addresses, audit fields, and embedded attachments.
Ask the provider for the relevant fields when its API supports that. Microsoft Graph distinguishes selecting properties from filtering rows in its query parameter documentation, and fewer fields and fewer records solve different problems for any connector.
Each reduction fails differently:
- A row limit can drop the important record.
- A field projection can omit the important fact from every record.
- A text truncation can corrupt the structure entirely.
State the reduction method so the agent knows what to fetch next.
Work through a support brief#
Take a tool that returns an account plus every support ticket, for a brief on whether an unresolved incident could affect renewal. The connector returns account identity, renewal date, ticket identifiers, status, severity, last update, and a short source excerpt, plus a separate fetch by ticket identifier for the full conversation.
If the excerpt ends before a customer promise, mark that field incomplete. Do not summarize “no outstanding commitments” from a preview that never included the relevant messages; a second, narrow read retrieves the ticket's commitment history.
The full payload stays in controlled storage behind an access-checked reference that works for the consuming agent and expires per the data policy. A file path on the connector's machine is useless to a remote agent.
The MCP tools specification supports structured results and resource links, which are transport choices. Your application still defines what the compact result means and how the client gets omitted information.
Design a result that admits its limits#
For an account-summary tool, distinguish these conditions:
| Result condition | What the agent should do |
|---|---|
| All requested fields present | Write the brief with references |
| More matching records exist | Continue enumeration or state partial scope |
| Field omitted by projection | Fetch that field through the defined operation |
| Preview truncated | Retrieve the full record before concluding |
| Source inaccessible | Report the missing evidence, no guess |
Preserve identifiers, source references, update times, and completeness flags before narrative, and keep each record's fields together. Cutting a JSON string at a byte boundary can destroy parsing and the relationships between the remaining values.
A useful compact response includes three unresolved tickets and a statement that seven closed tickets were excluded by an explicit filter. It never claims three tickets are the entire history, because users can understand a stated scope and cannot inspect a silent truncation.
Recover without restarting the task#
When a response exceeds the budget, keep the original query and target identifiers, then retry with a narrower projection or an artifact reference. Do not rerun account discovery, identity matching, and every earlier tool because one payload was too large.
If the model already received a malformed fragment, replace that tool result with a clear failure or a valid reduced representation through the framework's supported mechanism. Appending “ignore the previous response” leaves broken state or contradictory evidence in the conversation.
Test the reduced result against real downstream jobs: a long ticket with its decisive commitment near the end, a missing owner, two similarly named accounts, and a paged response. Assert that the agent obtains the missing evidence or limits its answer.
Version the compact-result contract alongside the tool so consumers can detect a changed projection, and save the projection and difficult fixture as a reusable method. Deixic's MCP gateway and connection setup cover connected calls.