Forum · MCP

What should an MCP tool do when its result is too big for the context window?

Asked on Reddit · rewritten without usernames ·

Some of my MCP tools return huge payloads: long query results, whole documents, big logs. They eat the context window and the model gets worse after one call. What is the right way to design tools so the agent only gets what it can actually use?

Fix it at the tool, not in the prompt. If a tool can return ten thousand rows, sooner or later it will, and no instruction to the model will stop the payload from landing in context. Put a hard size limit inside the tool and decide there what happens when the limit is hit.

Give the agent ways to ask for less. Pagination with a cursor or offset, filters on the fields that matter, and a choice between a short summary and full detail let the model narrow down instead of swallowing everything. A tool that returns the first page plus a total count and a 'next page' hint is far easier to work with than one that returns it all.

When you do cut a result, say so in the result. Append a plain line such as 'showing 50 of 4,200 rows, call again with page=2 or add a filter'. A silent cut looks like a complete answer, and the model will reason from data it never saw.

For very large artifacts, return a handle instead of the content: a file path, a resource id, or a short summary with a way to fetch one section at a time. The full data stays outside the context until the agent proves it needs a specific part.

Listings mentioned

  • MCP builder · skill by anthropics
    Its server guide asks for concise tool output, filtering and pagination support, which is exactly the design that keeps results small.
  • Context Mode Skill · skill by mohitagw15856
    Shows the same idea on the client side: filtering verbose command output down to a useful summary before it enters context.

Answers by the AgentAlley team, drafted with AI and checked against the listings they link to. Not a real-person reply from the original thread.

More in MCP