Repository navigation
Conversation
$mcp_tool_call gains $mcp_response_text_chars (characters in the result's text blocks) and $mcp_response_structured_chars (its structured content as JSON, when present). Hosts cut or move a result past about 40,000 characters and read different parts of it, so the two are counted apart. The handler measures the result and passes only the numbers to analytics.
[Medium impact] This PR appears safe to merge. SummaryAdds separate text and structured-content lengths to
Reviews (1) · Last reviewed commit: "test(core): read the tool-call event wit..." · Reviewed by Greptile |
There was a problem hiding this comment.
Builder reviewed your changes and has a few items to flag 🟡
Review Details
Code Review Summary
PR #9687 adds separate character counts for MCP tool-result text blocks and serialized structuredContent, emits them as numeric $mcp_tool_call properties, documents the fields, and updates coverage/snapshots. This is standard-risk framework analytics work. The split is useful because clients consume the two result parts differently, and the handler sends only lengths—not payload content—to tracking. Tests exercise mixed result content and assert the result text is absent from analytics. The changeset is included.
Findings
- 🟡 Avoidable serialization when analytics are disabled — Both review agents found that result sizing runs before
trackMcpToolCallchecks whether analytics are enabled; one rated it medium and the other low. This can stringify large structured results even when the measurement will be discarded. - Snapshot audit trail overwritten — One agent noted the update replaces existing
oracle-changeexplanations with the new result-size explanation in several places, losing the earlier snapshot-change rationale. Keep both reasons where both changes apply.
No blocking issue was identified. 🧪 Browser testing: Skipped — PR only modifies backend, docs, changeset, and tests; no UI impact.
Visual recap — generation failedRecap authentication failed — |
Why
MCP hosts cut or move a big tool result before the model sees it. Measured on Nov 18 with a small probe server:
Since #7110, read-only actions return their whole JSON, so a large read now reaches the model cut short. Nobody knows yet which reads get that big, or how often:
$mcp_tool_callrecords the tool, how long it took and whether it failed, but nothing about the size of what it returned. This PR adds the size, so the reads that need paging can be picked from data instead of guessed.What changes
$mcp_tool_callgets two numbers:$mcp_response_text_chars: characters in the result's text blocks.$mcp_response_structured_chars: characters in the result's structured content (structuredContent) written out as JSON. It's left out when the result has none.They're counted apart because hosts read different parts. Claude Code and OpenCode show the model only the structured content when a result has one, and Codex shows both, so a read costs a Codex user about double. Images and other block types aren't counted.
The
tools/callhandler measures the result it's about to return, after every early return, with the newmcpToolResultSize()inmcp/analytics.ts, and handstrackMcpToolCallonly the two numbers. The result itself never reaches the analytics call, so the specs that check a ticket or the caller's text stays out of analytics still hold.The tracking skill lists the two properties and says why they're separate.
direct-action-call.spec.tspins the analytics payload of every call it makes, so its 41 snapshots gain the size lines, each with anoracle-changenote.Risk
$mcp_responseis still never sent, and$mcp_parametersstays opt-in.JSON.stringifyof the structured content per call, which the SDK serializes anyway to send it. A value JSON can't hold (aBigInt, a cycle) now fails in the handler rather than in the transport. The call failed either way.$mcp_listed_tool_countand$mcp_vendor_source.Verification
On a fresh Linux machine, with this branch on main at
21c90bd:pnpm typecheckand the workspacepnpm typecheckpass.src/mcpspecs pass (3,016 tests). They include a new end-to-end check that the event's two numbers equal the text and structured content the client received, and that the result's text never appears in the event.direct-action-call.spec.tspassed two more runs after its snapshot update, so the sizes don't drift between runs.pnpm guardspasses all 112 checks, and oxfmt and oxlint pass on the changed files.Review focus
mcpToolResultSizeruns on every call, including when MCP analytics are off. Worth skipping then?Follow-ups
🤖 Generated with Claude Code