One Tool Call, 313,576 Characters: Shape What Your Agent Reads
"I Trimmed My Agent's Tool Results to Five Fields. It Solved More, Not Fewer." was one of the most-commented posts on DEV in the week to 22 November, with 67 comments. The title alone makes a point most of us skip: when an agent calls a tool, whatever the tool returns goes into the context, and somebody decided what that was. Often nobody decided, and the tool just passes the API response through.
I wrote earlier about trimming what fills your agent's context from the user's side: check /context, disable servers, filter noisy test output. This article is for the other side, when you're the one writing the tool, whether that's an MCP server or a function in your own agent. The question is simple: what should a tool give back?
What happens to a big result today
Agents don't let a tool result grow forever, but the limits are a safety net, not a design. Claude Code's MCP documentation lists them:
- The transcript viewer shows a warning when an MCP tool output exceeds 10,000 tokens.
- The default maximum is 25,000 tokens, adjustable with
MAX_MCP_OUTPUT_TOKENS. - A successful text result over the limit, or longer than 50,000 characters, is saved to a file and replaced in the conversation with a message naming the file path.
- Error text longer than about 11,000 characters keeps only its first 5,000 and last 5,000 characters.
So an oversized result doesn't break the session. But everything under those limits lands in the context as-is, and a result that gets moved to a file makes the agent spend another step reading it back. The size and the shape are still your job.
Measure one real result first
I took a real response: the 50 most recently created open items from the GitHub REST API's issues endpoint for the modelcontextprotocol/python-sdk repository, fetched on 28 November. (That endpoint also returns pull requests; 4 of the 50 were PRs.) Then I measured it with a short Python script, standard library only, counting characters of the JSON. Characters, not tokens, because token counts depend on the model's tokenizer and I didn't want to guess.
This is the raw response, unchanged, which is what a pass-through tool would return:
raw response: 50 issues, 313,576 chars body 147,809 chars (47%) user 49,854 chars (16%) labels 27,502 chars (9%) reactions 10,250 chars (3%) title 4,732 chars (2%) one 'user' object: 19 fields, 12 of them URLs, 964 chars Two things stand out. The issue bodies are almost half the size, and you rarely need all 50 of them to decide what to look at. And the user field takes 16%: each one is a full profile object with 19 fields, 12 of them URLs, when the agent needs one thing from it, the login name. The titles, which are what an agent actually reads to choose an issue, are 2%.
At 313,576 characters, this single result is more than six times Claude Code's 50,000-character threshold. Returned by an MCP tool, it would be saved to a file rather than shown in the conversation.
Shape the result for the agent, not the API
Anthropic's engineering post on writing tools for agents is the clearest guide I've found on this. Four of its recommendations map directly onto the numbers above.
1. Return the fields an agent acts on. The post says tools should "return only high signal information" and avoid low-level identifiers such as uuid, 256px_image_url and mime_type, in favour of fields like name, image_url and file_type. For issues, that means number, title, labels and a date, not the 12 profile URLs.
2. Let the agent ask for more detail. The post suggests a response_format parameter with "concise" and "detailed" values, so the agent can get IDs and extra fields only when a follow-up call needs them. In its Slack example, the concise response used about a third of the tokens of the detailed one.
3. Page, filter and truncate by default, and say so. Its advice is "some combination of pagination, range selection, filtering, and/or truncation with sensible default parameter values," plus instructions in the response when you truncate, so the agent knows how to get the rest.
4. Write errors the agent can act on. Instead of an opaque error code or a traceback, say what was wrong with the input and what a correct one looks like.
Here's the shaping part of my script. shape() decides the fields; list_issues() adds the defaults (10 items, concise), a label filter, and a note telling the agent what to do next:
# 2. Shape it: keep the fields an agent acts on, cap long text, page. def shape(issue, fmt): out = {"number": issue["number"], "title": issue["title"], "labels": [l["name"] for l in issue["labels"]], "updated": issue["updated_at"][:10]} if fmt == "detailed": body = issue.get("body") or "" out.update(author=issue["user"]["login"], comments=issue["comments"], url=issue["html_url"], body=body[:300] + ("..." if len(body) > 300 else "")) return out def list_issues(fmt="concise", limit=10, page=1, label=None): pool = [i for i in issues if label is None or label in [l["name"] for l in i["labels"]]] start = (page - 1) * limit items = [shape(i, fmt) for i in pool[start:start + limit]] result = {"issues": items} left = len(pool) - start - len(items) if left > 0: result["note"] = (f"{left} more issues. Call again with page={page + 1}, " "or pass label= to narrow the list.") return result And the same 50 issues, shaped:
detailed limit=50 50 issues, 30,509 chars concise limit=50 50 issues, 8,851 chars concise limit=10 10 issues, 1,825 chars concise label=bug 10 issues, 2,066 chars sample concise result (first item + note): { "issues": [ { "number": 3934, "title": "[v2] Use the documented middleware accessor in the tracing opt-out example", "labels": [ "v2" ], "updated": "2026-11-26" } ], "note": "40 more issues. Call again with page=2, or pass label= to narrow the list." } The detailed format, with all 50 issues and the first 300 characters of each body, is under a tenth of the raw response. The default call, 10 concise issues and a note, is 1,825 characters. Nothing here measures whether an agent does better with the smaller result. That depends on your tasks, and it's worth testing (more on that below). What it shows is how much of the raw response was never chosen by anyone.
If you're writing an MCP server
Two parts of the MCP tools specification (version 2026-07-28, the current one) are worth knowing here.
Structured content travels twice. A tool can return JSON in structuredContent, optionally validated against an outputSchema. But the spec also says "a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block." So trimming the structured result trims the text version too. There's no separate "machine-only" channel where extra fields come for free.
Link instead of embedding. A tool may return a resource_link, a URI the client can fetch, instead of the full content. For large files or logs, a link plus a short summary can replace pasting everything into the result.
And when a large result really is necessary, Claude Code lets a tool declare it: setting _meta["anthropic/maxResultSizeChars"] in the tool's tools/list entry raises that tool's persist-to-disk threshold, up to a hard ceiling of 500,000 characters. The docs give database schemas and full file trees as examples. Use it for those cases, on purpose, rather than raising the limit for everything.
Check it with your own tasks
Anthropic's post is clear that the right response structure "will vary widely by task and agent" and should be chosen from your own evaluation. A smaller result can also remove something the agent needed. The safe way to trim is to run the same small set of tasks before and after the change and compare task by task, the method from yesterday's article on testing your coding agent. If a task starts failing, the field you removed was load-bearing. Put it back in the detailed format.
When your tool list itself changes, this check for MCP tool changes covers the other half.
Checklist
- Save one real response from each tool and measure it.
- Find which fields take the most space, and which ones the agent actually uses.
- Return only those by default; drop internal IDs and URL lists.
- Add a concise/detailed option for follow-up calls that need IDs.
- Set a default limit, a filter, and a note that says how to get more.
- Cap long text fields and say that you did.
- Write errors that explain the fix.
- For MCP: keep
structuredContentlean, link large content, and declare a bigger limit only for tools that need one. - Re-run your task set before and after, and compare per task.
Where to go next
Context Engineering: The Complete Guide covers the wider discipline in 40 pages: the four core strategies (Write, Select, Compress, Isolate), the anatomy of a context window and token budgets, the four failure modes (context poisoning, distraction, confusion and clash) and context rot, context formats and schema design, context engineering in Claude Code and Cursor, 20 reusable patterns, 12 common pitfalls, and a 30-day plan.
What's the biggest tool result you've found in your own agent's context, and which field was taking the space?
This article was written with the assistance of AI and reviewed by the author.