An MCP Tool Returning 1KB Doubled Your Token Bill: One Result Sent Twice

You wire a small MCP server of your own into Hermes so it can look up internal tickets. The interface is boring: give it a ticket number, get back a chunk of text. Locally it returns about 1KB per call.
Within an hour of connecting it, two odd things show up.
First, token usage is roughly double what you expected. Second, every so often a result gets written to disk instead of staying in context — and when you open that spill file, it holds only half the content, followed by a JSON-escaped copy of what looks like the same thing.
Your server is not broken and Hermes is not calling twice. What happened is simpler and worse: the same result was handed to the model twice, because one of Hermes’ checks failed to recognise that the second copy was just a wrapper around the first. PR #148982 fixed it on November 14. The mechanism is worth understanding, because if you write MCP servers it will find you.
The result went out twice
MCP defines two fields: content, a list of text blocks meant for humans and models, and structuredContent, a structured object meant for programs.
FastMCP and the official Python SDK hit a constraint: if a tool is annotated -> str, -> int or -> list[...], the SDK must return an object. So it wraps the value and ships {"result": <value>} as structuredContent, while content carries the bare value.
One payload, two representations.
Hermes already knew about the spec’s backwards-compatibility dual-emit: a tool returning structured content should also put a serialised JSON copy in one text block. So it has a check, _content_dual_emits_structured — if some text block is exactly structuredContent serialised as JSON, drop structuredContent, because the model already has it.
The problem: that check only recognises structuredContent serialised verbatim. The SDK ships a {"result": X} wrapper while the text block carries X itself. They are not equal, the check fails, and Hermes forwards both copies.
The cost was not just tokens
On one operator deployment the bug had four effects:
| Effect | What it looked like |
|---|---|
| context doubled | every result cost about twice the tokens inline |
| spill threshold halved | the 50,000-character mcp_result_size_chars was compared against the doubled payload, so results spilled at half their real size |
| redundant spill files | the file held the text, then a second JSON-escaped copy |
| turn budget burned faster | the 200,000-character per-turn budget ran out twice as quickly |
That third row has a history: a spill file writes the body, then a metadata copy inside <mcp-result-metadata>. When structuredContent was not recognised as a duplicate, it became that second copy.
Fourteen days, one deployment
The PR fixes issue #124451 and salvages community work from #124452. The most convincing part is the production data — over 14 days of real traffic to the affected tools:
- 75% of calls sent the duplicate to the model in full;
- 15% of calls spilled to disk only because of the duplicate.
Three quarters of calls were burning tokens for nothing, and one in six was writing a pointless file — all while the intuition said “my tool returns something tiny, it should never spill”.
The fix: unwrap the single-key copy, compare per block
The core of the fix is a new function, _collapse_sdk_wrapped_copy, whose docstring is blunt about scope: it affects the model’s view only.
The logic:
- If
structuredContentis a dict whose only key isresult, takevalue. - If some text block equals
value— verbatim for a string, JSON for anything else — dropstructuredContent. - If
valueis a list and the block count equals the list length with every block matching its item (the “one block per item” shapeMCPServerproduces), collapse to a single JSON copy. - Otherwise keep both.
Step 4 is deliberate: an extra copy costs tokens, a dropped copy costs data, and only one of those is reversible. So the check stays conservative.
Two details in the comparison matter:
- Exact and type-stable:
1is notTrue. In Python1 == Trueis true, so a plain==could classify a boolean and an integer as duplicates and drop real content. bytesare compared too: the SDK serialises non-string returns intocontent(for example"abc"with quotes) whilestructuredContentholds bareabc, so strings are also tried as JSON.
Three cases still keep both copies, on purpose
You might think the obvious move is to drop structuredContent everywhere. That breaks servers where structuredContent is the only data source. Both copies survive when:
- The wrapped value differs from the text block. A status line (
Found 3 tickets) next to full structured data is not the same thing. - The wrapper has extra keys.
{"result": ..., "warnings": [...]}carries information beyondresult. - The text block is a prose summary or a reorganised rendering. The data may live on either side; keeping both is safer.
For context, the earlier rule (“content wins whenever it rendered anything”) irreversibly lost data from servers that only populated structuredContent. The current rule deliberately inverts that priority: preserving data beats saving tokens.
If you write MCP servers
The bug lives in the defaults on both sides, so server authors can help:
- Do not dual-emit by hand. If you return
contentand also put the same data instructuredContent, rely on the SDK’s wrapper instead of stuffing a second JSON copy into a text block yourself. - Watch the
-> strtrap. A FastMCP tool annotated-> stralways takes the wrapper path. For long human-readable text that is fine now that Hermes collapses it — but if you wanted “structured plus a short text”, return an object and put only the summary incontent. - Be careful with lists.
-> list[...]becomes one text block per item plus a wrapper. On older builds both representations were forwarded, so a long list was amplified twice.
Checking and tuning it yourself
The fastest self-check: look at one mcp_ tool result. If it contains two nearly identical chunks, this is what you are seeing.
The spill threshold is configurable. The default is 50,000 characters (tool_budget.mcp_result_size_chars) versus 100,000 for ordinary tools — MCP tools spill earlier by design, because MCP servers routinely return un-paginated 20K–50K payloads.
tool_budget:
mcp_result_size_chars: 50000 # default: lower spills earlier, higher spills later
Three things to keep in mind together:
- Spilling is not data loss. The full payload goes to a file on disk and context keeps a 1,500-character preview.
- The per-turn budget defaults to 200,000 characters. Per-result threshold and per-turn budget are separate gates.
read_fileis pinned at an infinite threshold to prevent a persist → read → persist loop.
If you are watching MCP cost, two related reads: MCP tool costs and spend limits on the budget machinery, and MCP catalog security on the risk surface of third-party servers.
The plugin path is untouched
One detail worth isolating: a plugin calling an MCP tool through ctx.call_mcp does not go through this collapse.
The reason is sound — a plugin receives the typed value it wants to parse, and the {"result": ...} wrapper may be exactly what it needs. The collapse is subtraction for the model’s view, not for a program’s view.
So plugin behaviour is unchanged. Whether the model’s view changed depends on whether that tool took the SDK wrapper path.
Status: main only, not in v0.23.1
PR #148982 merged on November 14, 2026 and lives on main. v0.23.1 (November 9) does not include it. On a stable release today:
Update (2026-11-17): these changes shipped in v0.23.2 (November 16) —
hermes updatebrings them in. The “not in v0.23.1” wording above is a snapshot from publication time.
- doubled token usage is still there;
- the two-copy spill file is still there;
- the threshold is still compared against the doubled payload.
After the next release:
hermes update
No config change is needed — this is a correction to internal judgement, with no new switch. The only thing you will notice is that the same calls suddenly cost less, and results that used to spill for no visible reason stop spilling. Small -> str tools that return a few hundred characters are where the difference shows up most, because they were dual-emitting on every single call.