A 40,000-character MCP tool result: what the model gets
Codex keeps about 6 KB from each end; Claude Code moves anything past 50,000 characters to a file. A script to size your own tool's result, and what to change.
Published · updated
The deploy agent's first step is a search in the team's memory server: "deploy freeze". The server is generous. It returns forty matches, 38,000 characters, sorted by score. Match number 17, around character 20,000, says: production deploys are frozen from December 18 to January 5, decided by Ana on December 1.
In Codex, the model gets the first 5,982 bytes of that result, then a marker that says …8 tokens truncated…, then the last 5,982 bytes. Match 17 is not in either piece. The agent answers that it found no active freeze and goes on to deploy. Nothing in the terminal says the result was cut, and the marker the model sees reports 8 tokens, not 26,000 bytes.
The same search in Claude Code arrives whole. Make it 60,000 characters and Claude Code stops sending it: the model gets a 2 KB preview and the path of a file, and has to read the rest from disk.
Neither tool is broken. Both have a limit on tool results, and both document it. What the documentation does not make obvious is how small one of them is, where each one cuts, and what the model gets in place of the text. This guide shows what each tool documents, what we measured, a script that sizes your own tool's results, and what to change on the server side so the answer survives.
What each tool documents
| Claude Code | Codex | |
|---|---|---|
| Limit on one MCP tool result | MAX_MCP_OUTPUT_TOKENS, "the default maximum is 25,000 tokens", and a result "longer than 50,000 characters" is saved to a file "whatever its token count" | tool_output_token_limit: "Token budget for storing individual tool/function outputs in history". No default written next to it |
| What happens past it | Claude Code "saves it to a file and replaces it in the conversation with a message that names the file path, so Claude reads the file when it needs the content" | The per-tool entry says it "Overrides the model's default output truncation budget for that tool"; where the cut falls is not described |
| Per tool | The server declares _meta["anthropic/maxResultSizeChars"] on the tool; text results from that tool use its value instead | mcp_servers.<id>.tools.<tool>.output_token_limit: "Token budget for one MCP tool's output, before the standard 20% serialization allowance" |
| Warning | The transcript viewer warns when a result "exceeds a fixed 10,000 tokens" | None documented |
What we measured
On one Linux machine, on December 2, 2026, with Claude Code 2.1.329 and codex-cli 0.156.1. One small MCP server over streamable HTTP (about 50 lines of Node) has a single tool, memory_search, that returns a text result of the size we ask for: 100-character lines, a marker line every 10,000 characters and one at the very end.
Instead of calling a model, we pointed each tool at a local stand-in for its API on 127.0.0.1. The stand-in answers the first request with a call to memory_search, records the next request, which carries the tool result exactly as the model would receive it, and then answers "ok". No model call runs and no account is used. Each case is one headless run, claude -p or codex exec, in a fresh git repository.
Two settings were needed just to get a headless call through, and they are worth knowing on their own. claude -p refused the call until the tool was in --allowedTools. codex exec refused it with "MCP tool call requires approval, but approval policy is never" until the server's table in config.toml had default_tools_approval_mode = "approve". The configuration reference documents that key per server and approval_mode per tool, under [mcp_servers.<id>.tools.<tool>].
| Claude Code case | What reached the model |
|---|---|
| 8,000, 40,000 and 49,000 characters | all of it |
| 51,000 characters | a 2 KB preview, the path of the saved file and "Output too large (50.3KB)" |
| 60,000 characters | the same, "Output too large (59.2KB)" |
| 100,000 and 120,000 characters | no preview: an error that the result "exceeds maximum allowed tokens", the path, and instructions to read the file "in sequential chunks until 100%" |
120,000 characters, MAX_MCP_OUTPUT_TOKENS=100000 | a 2 KB preview and the path, "Output too large (118.4KB)" |
120,000 characters, the tool declares anthropic/maxResultSizeChars = 200,000 | all of it |
| 45,000 and 49,900 characters of Japanese text | all of it, and Claude Code never asked the API for a token count |
120,000 characters, then the model calls Read on the saved file | Read ran without being in --allowedTools; the first read returned lines 1 to 842 of 1,201 |
Above 50,000 characters Claude Code sent one extra request to the API's token-counting endpoint before deciding which message to show. Our stand-in answers it at about four characters per token for English, so the switch from the preview message to the "exceeds maximum allowed tokens" message depends on that answer; with the real API the switch point will move with the real count.
| Codex case | What reached the model |
|---|---|
| 8,000, 10,000 and 11,000 characters | all of it |
| 12,000, 20,000, 40,000, 51,000 and 120,000 characters | the first 5,982 bytes, …7 tokens truncated… or …8 tokens truncated…, the last 5,982 bytes |
| 45,000 characters of Japanese text (about 135 KB) | the first and last 5,981 bytes: 4,022 characters in all |
The same 120,000 characters also sent as structuredContent | the same cut |
-c tool_output_token_limit=5000 | 23,964 characters, from both ends |
-c tool_output_token_limit=25000 | 119,964 of 120,000 characters |
-c tool_output_token_limit=200000 | all of it |
output_token_limit = 30000 under [mcp_servers.memory.tools.memory_search] | all of it |
Default settings with the model set to gpt-5, gpt-5.1-codex, gpt-5.2-codex, o3 and a name Codex does not know | the same 5,982 + 5,982 bytes in every one |
In no Codex case did the terminal mention the cut.
Five things the lab shows
1. Codex's default is about 12 KB, and it is counted in bytes. Everything past 11,964 bytes was cut, whatever the model name. A memory search, a SELECT with a few hundred rows or a list of open tickets passes that easily. Text with accents, CJK or emoji costs more bytes per character, so the same budget holds fewer characters: our Japanese result kept 4,022 of 45,000.
2. Codex keeps the start and the end, and drops the middle. Results sorted by score put the second-tier matches in the middle, and that is the part that goes. The marker in its place is the only hint the model gets, and the count in it did not track what was removed: it said 8 tokens whether we cut 8,000 characters or 108,000.
3. Claude Code does not cut, it moves. Up to 50,000 characters the result goes whole, which is roughly four times what Codex passes. Past that the model gets a pointer, and the content is only as good as the agent's next step: in our run one Read stopped at line 842 of 1,201, so an agent that reads once and answers has seen about 70% of the result. Raising MAX_MCP_OUTPUT_TOKENS did not move the 50,000-character line, as the documentation says. One exception, from the same documentation: a result marked isError: true reaches the model as error text, and past about 11,000 characters Claude Code keeps only its first 5,000 and last 5,000 characters, with a marker between them. We did not run that case.
4. Below 50,000 characters, Claude Code did not ask the API for a token count. Our 49,900-character Japanese result went to the model whole and no request went to the token-counting endpoint. Japanese text runs close to one token per character, so a result like that is probably past the 25,000-token default and arrives anyway. In our runs, the token limit only came into play once the character limit had already been crossed.
5. The fix that works is per tool, and it lives in two different places. anthropic/maxResultSizeChars is set by whoever writes the MCP server and travels with the tool to every Claude Code user. Codex's output_token_limit is set in each user's config.toml, so every laptop and every CI runner has to carry it, and a machine without it cuts silently.
Size your own tool's results: two minutes
This calls one tool on a streamable HTTP MCP server, the way a client would, and says what each tool does with the result at default settings. It needs only Python's standard library.
#!/usr/bin/env python3
"""Call one tool on a streamable HTTP MCP server and say how Claude Code and Codex would pass the result on.
usage: mcp-result-size.py URL TOOL '{"query": "deploy freeze"}' [-H 'Authorization: Bearer ...']
Numbers measured on Dec 2, 2026 with Claude Code 2.1.329 and codex-cli 0.156.1 (default settings).
"""
import json, sys, urllib.request
CLAUDE_CHARS = 50_000 # above this Claude Code saves the result to a file and sends a preview or a pointer
CODEX_BYTES = 11_964 # above this Codex keeps ~5,982 bytes from each end and drops the middle
def post(url, headers, msg):
req = urllib.request.Request(url, json.dumps(msg).encode(), method="POST", headers={
"content-type": "application/json", "accept": "application/json, text/event-stream", **headers})
with urllib.request.urlopen(req, timeout=60) as r:
sid = r.headers.get("mcp-session-id")
raw = r.read().decode("utf-8", "replace")
if not raw.strip():
return None, sid
if raw.lstrip().startswith("{"):
return json.loads(raw), sid
for line in raw.splitlines(): # text/event-stream: take the data line that answers our id
if line.startswith("data:"):
d = json.loads(line[5:])
if d.get("id") == msg.get("id"):
return d, sid
return None, sid
def main():
a = sys.argv[1:]
hdr = {}
while "-H" in a:
i = a.index("-H"); k, v = a[i + 1].split(":", 1); hdr[k.strip()] = v.strip(); del a[i:i + 2]
url, tool, args = a[0], a[1], json.loads(a[2] if len(a) > 2 else "{}")
_, sid = post(url, hdr, {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {
"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "mcp-result-size", "version": "1"}}})
if sid: hdr["mcp-session-id"] = sid
post(url, hdr, {"jsonrpc": "2.0", "method": "notifications/initialized"})
res, _ = post(url, hdr, {"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": tool, "arguments": args}})
if not res or "result" not in res:
sys.exit(f"no result: {res}")
text = "".join(c.get("text", "") for c in res["result"].get("content", []) if c.get("type") == "text")
chars, nbytes, lines = len(text), len(text.encode()), text.count("\n") + 1
print(f"{tool}: {chars:,} characters, {nbytes:,} bytes, {lines:,} lines")
print("Claude Code:", "passed whole" if chars <= CLAUDE_CHARS else
"saved to a file; the model gets a 2 KB preview or only the path, and has to Read the rest")
print("Codex: ", "passed whole" if nbytes <= CODEX_BYTES else
f"middle cut; the model gets the first and last ~5,982 bytes, {nbytes - CODEX_BYTES:,} bytes never arrive")
if __name__ == "__main__":
main()Against the lab server with a 40,000-character result:
memory_search: 40,000 characters, 40,000 bytes, 401 lines
Claude Code: passed whole
Codex: middle cut; the model gets the first and last ~5,982 bytes, 28,036 bytes never arriveRun it with the queries your agents actually send: the broad one at the start of a task ("deploy", "auth", "billing"), not the narrow one you would type while testing. Broad queries are the ones that come back long. The script does not cover stdio servers; for those, log the length of the result inside the server.
What to change
Make the server return less, on purpose. The limits are per result, so the lasting fix is in the tool, not in every client's settings. Return the top matches with a short snippet and an id, and give the agent a second tool that fetches one item in full. Ten matches of 300 characters is 3 KB and passes everywhere; the agent asks for match 17 when it needs it.
Put what matters first. Codex keeps the head and the tail. A result that starts with the newest dated decision and ends with a one-line summary ("40 matches; showing 10; 2 are dated decisions") survives the cut better than forty matches in score order.
Declare the limit in the server if a result really must be long. _meta["anthropic/maxResultSizeChars"] on the tool definition lets Claude Code pass it whole, for every user of the server, without anyone touching their environment. It does nothing for Codex.
Set the per-tool budget where Codex runs. output_token_limit under [mcp_servers.<id>.tools.<tool>] brought back all 120,000 characters in our run. Like any setting in config.toml, it has to be on every laptop and every runner, and it makes every call to that tool cost more context.
Let headless runs read the saved file. In Claude Code, a result past 50,000 characters is only useful if the agent reads the file after. That worked in our claude -p run with only the MCP tool allowed, but a prompt that says "answer in one line" can end the turn before the agent reads it all.
The same search with ValorBrain
ValorBrain is a memory server for teams of agents, reached over MCP at one URL from every repository, tool and machine. Its search tool, memory_retrieve, returns 12 results by default in compact form, each with a snippet of up to 200 characters and without the full content unless the agent asks for it with include_content. Above the results it puts up to five keyed facts that match the query, with their full values. That keeps a default search short, but it is not a cap: long fact values, a limit up to 40 or include_content can take a result past Codex's 12 KB. To read one document in full, the agent calls get or multi_get with the id it got back.
The freeze in the opening example would not be match 17 in a pile of notes. It is one keyed fact:
{
"tool": "upsert_keyed_fact",
"arguments": {
"fact_key": "deploy.production.freeze",
"fact_value": "frozen 2026-12-18 to 2027-01-05; hotfixes need the on-call lead",
"as_of": "2026-12-01",
"evidence": "#eng-announce, 2026-12-01 10:40, Ana",
"authority": "agent"
}
}The hook that connect installs on Claude Code and Codex runs the same recall as memory_prepare at session start and with each prompt. It brings the keyed facts whose key or value matches words in the request, near the top, and the server caps what each prompt adds at 8,000 characters, below the 10,000 at which Claude Code moves a hook's output to a file. A request about a deploy gets this value in a few hundred bytes, before any search. When the freeze ends, the new value is written under the same key and replaces the old one, so the search does not grow a new match every time the state changes.
npx -y @valorbrain/connect@latest --token <vbm_…> --harness <claude-code|codex|cursor>What ValorBrain does not do
- It does not change either client's limits. A ValorBrain call with
include_contentand a highlimitcan return a long result, and Codex cuts it at the same 12 KB as anything else. - It does not fix your other MCP servers. The database, logs or ticket server that returns 40,000 characters is still cut. Size those with the script above.
- It does not guarantee the agent asks. A compact result works when the agent fetches the item it needs. An agent that answers from the snippets alone has the snippets alone.
What we ran and what we did not
Thirty-five runs on one Linux machine, with filler text, one local MCP server and local stand-ins for both APIs: sixteen in Claude Code and nineteen in Codex, counting the ones that only showed a call being refused or a tool being hidden. No model call ran, so the lab shows what each model receives, not what it does with it. Claude Code's switch between its two over-the-limit messages depends on the token count our stand-in returned. With Codex we did not measure gpt-5.5, which in codex-cli 0.156.1 hides MCP tools behind a tool_search step our stand-in does not answer, and we did not run the Codex TUI, the IDE extension or cloud tasks. We tested text results only: no images, no resources, no stdio servers. Grok Build is not installed on the lab machine and is not covered.
The lab is one bash script, the MCP server and the two stand-in APIs. Everything is built under /tmp and deleted after each run.
Checklist
- You ran the size script on the broad queries your agents send at the start of a task, and no result is over 11,964 bytes, or you know which ones are.
- Your search tools return a short list with ids and a way to fetch one item in full.
- The most important line of a long result is at the top, not in the middle.
- If you own the server and one tool must return long text, it declares
anthropic/maxResultSizeChars. - If your team uses Codex with a long-result tool,
output_token_limitfor that tool is in theconfig.tomlof every laptop and every CI runner. claude -pandcodex execjobs allow the MCP tools they need (--allowedTools;default_tools_approval_modeorapproval_modeset to"approve"), or the first call fails.
Sources, read on December 2, 2026: Claude Code, Connect Claude Code to tools via MCP (MCP output limits and warnings, anthropic/maxResultSizeChars, error results), environment variables (MAX_MCP_OUTPUT_TOKENS) and Hooks reference (the 10,000-character cap on hook output); Codex, Configuration reference (tool_output_token_limit, mcp_servers.<id>.tools.<tool>.output_token_limit, default_tools_approval_mode, approval_mode).
Next: How much context a memory MCP server costs for what the tool definitions take before the first question, When the MCP server is slow or fails mid-run for timeouts and errors in headless runs, and AGENTS.md past 32 KiB for the other place Codex cuts without saying so.
AGENTS.md past 32 KiB: the rules Codex never reads
Codex cuts mid-line, in the file closest to your work, with nothing on screen. Where it cuts, what Claude Code does with 200 KB, and a script that shows yours.
There is no share button: what a Claude Code project keeps to itself, and what your team can share instead
Six people asked Anthropic the same question in twelve hours: where is the share button for my project? What the documentation says about the new Projects and the classic ones, which part of a project stays with its owner, where each part can live so the team gets it, and where a team memory fits and where it does not.