From ffa8446d9adc24cd281199893ee188febb963ae9 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:24:15 -0500 Subject: [PATCH 1/4] feat(core): record each MCP tool result's size in tool-call analytics $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. --- .agents/skills/tracking/SKILL.md | 11 +- .changeset/mcp-tool-call-result-size.md | 5 + .../direct-action-call.spec.ts.snap | 129 ++++++++++++++++-- packages/core/src/mcp/analytics.spec.ts | 43 +++++- packages/core/src/mcp/analytics.ts | 45 +++++- packages/core/src/mcp/build-server.ts | 2 + 6 files changed, 221 insertions(+), 14 deletions(-) create mode 100644 .changeset/mcp-tool-call-result-size.md diff --git a/.agents/skills/tracking/SKILL.md b/.agents/skills/tracking/SKILL.md index 06ec047462e..f5722e21498 100644 --- a/.agents/skills/tracking/SKILL.md +++ b/.agents/skills/tracking/SKILL.md @@ -350,7 +350,8 @@ Shared properties: `$mcp_source` (`http` / `stdio`), `$mcp_server_name`, `$mcp_client_user_agent`, `$mcp_vendor_client`, `$mcp_protocol_version`. Per event: `$mcp_tool_name`, `$mcp_tool_description`, `$mcp_tool_category` (`read` / `write`), `$mcp_listed_tool_names`, `$mcp_duration_ms`, -`$mcp_is_error`, `$mcp_error_type`, `$mcp_error_message`, `$mcp_resource_name`, +`$mcp_response_text_chars`, `$mcp_response_structured_chars`, `$mcp_is_error`, +`$mcp_error_type`, `$mcp_error_message`, `$mcp_resource_name`, `$mcp_resource_uri`. - **A client's own name is only on the wire at `initialize`.** The mount is @@ -364,6 +365,14 @@ event: `$mcp_tool_name`, `$mcp_tool_description`, `$mcp_tool_category` where it returns rather than having it guessed back out of the response text. - **Payloads stay out.** `$mcp_response` is never emitted. `$mcp_parameters` is off by default and redacted when on — tool arguments carry user content. +- **A result's size goes in, counted per part.** `$mcp_response_text_chars` + counts the characters in the result's text blocks, and + `$mcp_response_structured_chars` the structured content as JSON (absent when + the result has none). Hosts cut or move a result past about 40,000 + characters, and they read different parts: Claude Code and OpenCode show the + model only the structured content when there is one, Codex shows both. The + handler measures the result and passes only the two numbers, so no part of + the payload reaches `trackMcpToolCall`. Off switches: `MCP_ANALYTICS=false` (`observability.mcpEvents`) disables the events; `MCP_ANALYTICS_PARAMETERS=true` (`observability.mcpCaptureParameters`) diff --git a/.changeset/mcp-tool-call-result-size.md b/.changeset/mcp-tool-call-result-size.md new file mode 100644 index 00000000000..7ba6d077ac5 --- /dev/null +++ b/.changeset/mcp-tool-call-result-size.md @@ -0,0 +1,5 @@ +--- +"@agent-native/core": patch +--- + +`$mcp_tool_call` now records how big each result is: `$mcp_response_text_chars` counts the characters in its text blocks, and `$mcp_response_structured_chars` its structured content as JSON, when it has any. MCP hosts cut or move a result past about 40,000 characters, and Claude Code and OpenCode show the model only the structured content while Codex shows both, so the two are counted apart. Only the numbers are sent; the result's text stays out of analytics. diff --git a/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap b/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap index afc95d7c4a0..cdbe44b86ab 100644 --- a/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap +++ b/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: a client without elicitation gets the review page link 1`] = ` { "trace": [ @@ -37,6 +37,7 @@ exports[`direct tools/call wire output > approval: a client without elicitation "parameters": { "draftId": "d-6", }, + "resultTextChars": 384, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -79,7 +80,7 @@ After they approve, call publish again with exactly the same arguments before 20 } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: a grant that expired in the store is refused 1`] = ` { "trace": [ @@ -116,6 +117,7 @@ exports[`direct tools/call wire output > approval: a grant that expired in the s "parameters": { "draftId": "d-8", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -139,6 +141,7 @@ exports[`direct tools/call wire output > approval: a grant that expired in the s "parameters": { "draftId": "d-8", }, + "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -219,7 +222,7 @@ Draft id: d-8", } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: a resume after the approval window is refused 1`] = ` { "trace": [ @@ -256,6 +259,7 @@ exports[`direct tools/call wire output > approval: a resume after the approval w "parameters": { "draftId": "d-9", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -279,6 +283,7 @@ exports[`direct tools/call wire output > approval: a resume after the approval w "parameters": { "draftId": "d-9", }, + "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -359,6 +364,7 @@ Draft id: d-9", } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: a static-token caller cannot approve 1`] = ` { "trace": [ @@ -369,6 +375,7 @@ exports[`direct tools/call wire output > approval: a static-token caller cannot "parameters": { "draftId": "d-5", }, + "resultTextChars": 56, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -404,7 +411,7 @@ exports[`direct tools/call wire output > approval: a static-token caller cannot } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: client-fulfilled elicitation round trip 1`] = ` { "trace": [ @@ -441,6 +448,7 @@ exports[`direct tools/call wire output > approval: client-fulfilled elicitation "parameters": { "draftId": "d-4", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -553,6 +561,7 @@ exports[`direct tools/call wire output > approval: client-fulfilled elicitation "parameters": { "draftId": "d-4", }, + "resultTextChars": 9, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -632,7 +641,7 @@ Draft id: d-4", } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: denied decision and predicate outcomes 1`] = ` { "trace": [ @@ -669,6 +678,7 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "parameters": { "draftId": "d-3", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -693,6 +703,7 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "parameters": { "draftId": "d-3", }, + "resultTextChars": 25, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -739,6 +750,7 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "parameters": { "big": true, }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Approval only for big changes", "toolName": "maybe-approve", @@ -781,6 +793,7 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "durationMs": "", "isError": false, "parameters": {}, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Approval predicate throws", "toolName": "approval-throws", @@ -950,7 +963,7 @@ Big: Yes", } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: elicitation, approved retry, and replay 1`] = ` { "trace": [ @@ -987,6 +1000,7 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-1", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1099,6 +1113,7 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-1", }, + "resultTextChars": 9, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1122,6 +1137,7 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-1", }, + "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1134,6 +1150,7 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-2", }, + "resultTextChars": 66, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1261,7 +1278,7 @@ Draft id: d-1", } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: the client gives up when its round limit is exhausted 1`] = ` { "trace": [ @@ -1298,6 +1315,7 @@ exports[`direct tools/call wire output > approval: the client gives up when its "parameters": { "draftId": "d-7", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1361,7 +1379,7 @@ Draft id: d-7", } `; -// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: two concurrent resumes of one approval run the action once 1`] = ` { "firstLeg": { @@ -1399,6 +1417,7 @@ exports[`direct tools/call wire output > approval: two concurrent resumes of one "parameters": { "draftId": "d-10", }, + "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1523,10 +1542,11 @@ Draft id: d-10", { "mcpToolCall": { "durationMs": "", - "isError": false, + "isError": true, "parameters": { "draftId": "d-10", }, + "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1535,10 +1555,11 @@ Draft id: d-10", { "mcpToolCall": { "durationMs": "", - "isError": true, + "isError": false, "parameters": { "draftId": "d-10", }, + "resultTextChars": 9, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1644,7 +1665,7 @@ Draft id: d-10", } `; -// oracle-change: a read-only grant no longer gets cards by default, so the widget returns a plain result +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: embed-widget 1`] = ` { "trace": [ @@ -1663,6 +1684,8 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 68, + "resultTextChars": 68, "toolCategory": "read", "toolDescription": "Opens a widget", "toolName": "embed-widget", @@ -1703,6 +1726,7 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: read-thing 1`] = ` { "trace": [ @@ -1713,6 +1737,7 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: "errorType": "unknown_tool", "isError": true, "parameters": {}, + "resultTextChars": 24, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "read-thing", @@ -1748,6 +1773,7 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: write-thing 1`] = ` { "trace": [ @@ -1758,6 +1784,7 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: "errorType": "unknown_tool", "isError": true, "parameters": {}, + "resultTextChars": 25, "toolCategory": "write", "toolDescription": "Write a thing", "toolName": "write-thing", @@ -1793,6 +1820,7 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > directory catalog: projected results, errors, and widget embeds 1`] = ` { "trace": [ @@ -1837,6 +1865,8 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 400, + "resultTextChars": 136, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "dir-read", @@ -1936,6 +1966,7 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "errorType": "Error", "isError": true, "parameters": {}, + "resultTextChars": 22, "toolCategory": "write", "toolDescription": "Always fails", "toolName": "dir-fail", @@ -1986,6 +2017,8 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 350, + "resultTextChars": 72, "toolCategory": "read", "toolDescription": "Opens a widget", "toolName": "dir-widget", @@ -2100,6 +2133,8 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 355, + "resultTextChars": 71, "toolCategory": "write", "toolDescription": "Opens a widget after a write", "toolName": "dir-write-widget", @@ -2199,6 +2234,7 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": true, "parameters": {}, + "resultTextChars": 33, "toolCategory": "write", "toolDescription": "Proxied MCP error", "toolName": "dir-proxy-error", @@ -2211,6 +2247,7 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "errorType": "unknown_tool", "isError": true, "parameters": {}, + "resultTextChars": 24, "toolName": "read-thing", }, }, @@ -2262,6 +2299,7 @@ data: {"result":{"content":[{"type":"text","text":"Unknown tool: read-thing"}]," } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: app-only 1`] = ` { "trace": [ @@ -2350,6 +2388,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: app-only 1`] "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 43, + "resultTextChars": 19, "toolCategory": "write", "toolDescription": "Widget-only helper", "toolName": "app-only", @@ -2391,6 +2431,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: app-only 1`] } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: bigint-read 1`] = ` { "trace": [ @@ -2411,6 +2452,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-read 1 "errorType": "result_not_json", "isError": true, "parameters": {}, + "resultTextChars": 68, "toolCategory": "read", "toolDescription": "Read whose result is not JSON", "toolName": "bigint-read", @@ -2446,6 +2488,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-read 1 } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: bigint-write 1`] = ` { "trace": [ @@ -2535,6 +2578,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-write "durationMs": "", "isError": false, "parameters": {}, + "resultTextChars": 98, "toolCategory": "write", "toolDescription": "Write whose result is not JSON", "toolName": "bigint-write", @@ -2569,6 +2613,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-write } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: contract-empty-code 1`] = ` { "trace": [ @@ -2660,6 +2705,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-empt "errorType": "ActionContractError", "isError": true, "parameters": {}, + "resultTextChars": 25, "toolCategory": "write", "toolDescription": "Fails a contract with an empty code", "toolName": "contract-empty-code", @@ -2695,6 +2741,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-empt } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: contract-fail 1`] = ` { "trace": [ @@ -2786,6 +2833,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-fail "errorType": "stale_revision", "isError": true, "parameters": {}, + "resultTextChars": 53, "toolCategory": "write", "toolDescription": "Fails a contract", "toolName": "contract-fail", @@ -2821,6 +2869,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-fail } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: contract-generic 1`] = ` { "trace": [ @@ -2912,6 +2961,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-gene "errorType": "action_failed", "isError": true, "parameters": {}, + "resultTextChars": 23, "toolCategory": "write", "toolDescription": "Fails generically", "toolName": "contract-generic", @@ -2947,6 +2997,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-gene } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: cycle-read 1`] = ` { "trace": [ @@ -2965,6 +3016,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-read 1` "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 42, + "resultTextChars": 42, "toolCategory": "read", "toolDescription": "Read whose result is circular", "toolName": "cycle-read", @@ -3003,6 +3056,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-read 1` } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: cycle-write 1`] = ` { "trace": [ @@ -3092,6 +3146,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-write 1 "durationMs": "", "isError": false, "parameters": {}, + "resultTextChars": 33, "toolCategory": "write", "toolDescription": "Write whose result is circular", "toolName": "cycle-write", @@ -3126,6 +3181,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-write 1 } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-empty 1`] = ` { "trace": [ @@ -3144,6 +3200,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-empty 1 "durationMs": "", "isError": true, "parameters": {}, + "resultStructuredChars": 15, + "resultTextChars": 2, "toolCategory": "read", "toolDescription": "Widget with nothing to show", "toolName": "embed-empty", @@ -3182,6 +3240,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-empty 1 } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-leak 1`] = ` { "trace": [ @@ -3200,6 +3259,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-leak 1` "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 102, + "resultTextChars": 102, "toolCategory": "read", "toolDescription": "Returns an embed ticket without a widget", "toolName": "embed-leak", @@ -3246,6 +3307,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-leak 1` } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget 1`] = ` { "trace": [ @@ -3264,6 +3326,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 68, + "resultTextChars": 16, "toolCategory": "read", "toolDescription": "Opens a widget", "toolName": "embed-widget", @@ -3308,6 +3372,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget-existing 1`] = ` { "trace": [ @@ -3396,6 +3461,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget- "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 70, + "resultTextChars": 11, "toolCategory": "write", "toolDescription": "Widget with its own ticket", "toolName": "embed-widget-existing", @@ -3439,6 +3506,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget- } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-write-leak 1`] = ` { "trace": [ @@ -3528,6 +3596,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-write-l "durationMs": "", "isError": false, "parameters": {}, + "resultTextChars": 37, "toolCategory": "write", "toolDescription": "Write that returns an embed ticket", "toolName": "embed-write-leak", @@ -3562,6 +3631,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-write-l } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: fail-thing 1`] = ` { "trace": [ @@ -3653,6 +3723,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: fail-thing 1` "errorType": "Error", "isError": true, "parameters": {}, + "resultTextChars": 11, "toolCategory": "write", "toolDescription": "Always fails", "toolName": "fail-thing", @@ -3688,6 +3759,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: fail-thing 1` } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: image-thing 1`] = ` { "trace": [ @@ -3706,6 +3778,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: image-thing 1 "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 28, + "resultTextChars": 193, "toolCategory": "read", "toolDescription": "Returns images", "toolName": "image-thing", @@ -3752,6 +3826,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: image-thing 1 } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: list-things 1`] = ` { "trace": [ @@ -3770,6 +3845,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: list-things 1 "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 33, + "resultTextChars": 23, "toolCategory": "read", "toolDescription": "List things", "toolName": "list-things", @@ -3814,6 +3891,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: list-things 1 } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: long-read 1`] = ` { "trace": [ @@ -3832,6 +3910,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: long-read 1`] "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 2611, + "resultTextChars": 2611, "toolCategory": "read", "toolDescription": "Read a long thing", "toolName": "long-read", @@ -3869,6 +3949,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: long-read 1`] } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: maybe-approve 1`] = ` { "trace": [ @@ -3969,6 +4050,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: maybe-approve "parameters": { "big": false, }, + "resultTextChars": 24, "toolCategory": "write", "toolDescription": "Approval only for big changes", "toolName": "maybe-approve", @@ -4003,6 +4085,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: maybe-approve } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: no-such-tool 1`] = ` { "trace": [ @@ -4013,6 +4096,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: no-such-tool "errorType": "unknown_tool", "isError": true, "parameters": {}, + "resultTextChars": 26, "toolName": "no-such-tool", }, }, @@ -4046,6 +4130,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: no-such-tool } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: partial-then-fail 1`] = ` { "trace": [ @@ -4140,6 +4225,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: partial-then- "errorType": "Error", "isError": true, "parameters": {}, + "resultTextChars": 27, "toolCategory": "write", "toolDescription": "Writes, then fails", "toolName": "partial-then-fail", @@ -4175,6 +4261,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: partial-then- } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: read-thing 1`] = ` { "trace": [ @@ -4193,6 +4280,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: read-thing 1` "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 375, + "resultTextChars": 111, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "read-thing", @@ -4256,6 +4345,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: read-thing 1` } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: throws-string 1`] = ` { "trace": [ @@ -4347,6 +4437,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: throws-string "errorType": "Error", "isError": true, "parameters": {}, + "resultTextChars": 16, "toolCategory": "write", "toolDescription": "Throws a non-Error", "toolName": "throws-string", @@ -4382,6 +4473,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: throws-string } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-error 1`] = ` { "trace": [ @@ -4464,6 +4556,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-error "durationMs": "", "isError": true, "parameters": {}, + "resultTextChars": 15, "toolCategory": "write", "toolDescription": "Proxied MCP error", "toolName": "wrapped-error", @@ -4499,6 +4592,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-error } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-ok 1`] = ` { "trace": [ @@ -4517,6 +4611,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-ok 1` "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 32, + "resultTextChars": 19, "toolCategory": "read", "toolDescription": "Proxied MCP result", "toolName": "wrapped-ok", @@ -4557,6 +4653,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-ok 1` } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-text-reads 1`] = ` { "trace": [ @@ -4578,6 +4675,8 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-text- "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 11, + "resultTextChars": 19, "toolCategory": "read", "toolDescription": "Proxied MCP result whose text can be read only so often", "toolName": "wrapped-text-reads", @@ -4615,6 +4714,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-text- } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: write-thing 1`] = ` { "trace": [ @@ -4708,6 +4808,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-thing 1 "parameters": { "name": "draft", }, + "resultTextChars": 30, "toolCategory": "write", "toolDescription": "Write a thing", "toolName": "write-thing", @@ -4742,6 +4843,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-thing 1 } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: write-void 1`] = ` { "trace": [ @@ -4830,6 +4932,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-void 1` "durationMs": "", "isError": false, "parameters": {}, + "resultTextChars": 21, "toolCategory": "write", "toolDescription": "Write without a result", "toolName": "write-void", @@ -4864,6 +4967,7 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-void 1` } `; +// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, read-only OAuth scope: a write is refused by scope 1`] = ` { "trace": [ @@ -4874,6 +4978,7 @@ exports[`direct tools/call wire output > full catalog, read-only OAuth scope: a "errorType": "forbidden_scope", "isError": true, "parameters": {}, + "resultTextChars": 54, "toolCategory": "write", "toolDescription": "Write a thing", "toolName": "write-thing", @@ -4894,6 +4999,8 @@ exports[`direct tools/call wire output > full catalog, read-only OAuth scope: a "durationMs": "", "isError": false, "parameters": {}, + "resultStructuredChars": 375, + "resultTextChars": 111, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "read-thing", diff --git a/packages/core/src/mcp/analytics.spec.ts b/packages/core/src/mcp/analytics.spec.ts index 95f58004d27..155048ba877 100644 --- a/packages/core/src/mcp/analytics.spec.ts +++ b/packages/core/src/mcp/analytics.spec.ts @@ -10,6 +10,7 @@ import { import type { TrackingEvent } from "../tracking/types.js"; import { detectVendorClient, + mcpToolResultSize, readClientInfoFromRequest, vendorForRedirectHost, } from "./analytics.js"; @@ -29,7 +30,7 @@ function config(): MCPConfig { "list-messages": { tool: { description: "List messages", parameters: undefined }, readOnly: true, - run: async () => [{ id: "m1" }], + run: async () => [{ id: "m1", subject: "Quarterly plan draft" }], } as any, "send-message": { tool: { description: "Send a message", parameters: undefined }, @@ -119,6 +120,46 @@ describe("MCP analytics events", () => { expect(props.$mcp_error_type).toBeUndefined(); }); + it("reports how big the result the client got is, never its text", async () => { + const client = await connectedClient(); + const result = await client.callTool({ + name: "list-messages", + arguments: {}, + }); + + const props = eventNamed("$mcp_tool_call")!.properties!; + const text = (result.content as Array<{ type: string; text?: string }>) + .filter((block) => block.type === "text") + .map((block) => block.text ?? "") + .join(""); + expect(text).toContain("Quarterly plan draft"); + expect(props.$mcp_response_text_chars).toBe(text.length); + expect(result.structuredContent).toBeDefined(); + expect(props.$mcp_response_structured_chars).toBe( + JSON.stringify(result.structuredContent).length, + ); + expect(JSON.stringify(props)).not.toContain("Quarterly plan draft"); + }); + + it("counts a result's text blocks and leaves out structured content it lacks", () => { + expect( + mcpToolResultSize({ + content: [ + { type: "text", text: "Two parts" }, + { type: "image", data: "aGVsbG8=", mimeType: "image/png" }, + { type: "text", text: ", one size." }, + ], + }), + ).toEqual({ resultTextChars: 20 }); + expect( + mcpToolResultSize({ + content: [{ type: "text", text: "{}" }], + structuredContent: { items: ["a"] }, + }), + ).toEqual({ resultTextChars: 2, resultStructuredChars: 15 }); + expect(mcpToolResultSize(undefined)).toEqual({ resultTextChars: 0 }); + }); + it("includes redacted $mcp_parameters only when opted in", async () => { process.env.MCP_ANALYTICS_PARAMETERS = "true"; resetAppConfigForTests(); diff --git a/packages/core/src/mcp/analytics.ts b/packages/core/src/mcp/analytics.ts index 0b7e1e0289e..40ccc674e60 100644 --- a/packages/core/src/mcp/analytics.ts +++ b/packages/core/src/mcp/analytics.ts @@ -210,6 +210,43 @@ export function trackMcpToolsList( }); } +export interface McpToolResultSize { + resultTextChars: number; + resultStructuredChars?: number; +} + +// How big a result is, never what it says. Hosts cut or move a result past +// about 40,000 characters, and they read different parts of it: Claude Code +// and OpenCode show the model only the structured content when there is one, +// and Codex shows both, so each part is counted on its own. +export function mcpToolResultSize(result: unknown): McpToolResultSize { + const record = + result && typeof result === "object" + ? (result as { content?: unknown; structuredContent?: unknown }) + : {}; + let resultTextChars = 0; + if (Array.isArray(record.content)) { + for (const block of record.content) { + if (block?.type === "text" && typeof block.text === "string") { + resultTextChars += block.text.length; + } + } + } + let resultStructuredChars: number | undefined; + if (record.structuredContent !== undefined) { + try { + resultStructuredChars = JSON.stringify(record.structuredContent).length; + } catch { + // A value JSON cannot hold fails the response on its own; the + // measurement never adds a failure of its own. + } + } + return { + resultTextChars, + ...(resultStructuredChars !== undefined ? { resultStructuredChars } : {}), + }; +} + export function trackMcpToolCall( ctx: McpAnalyticsContext, args: { @@ -221,7 +258,7 @@ export function trackMcpToolCall( isError: boolean; errorType?: string; errorMessage?: string; - }, + } & Partial, ): void { if (!analyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.toolCall, ctx, { @@ -234,6 +271,12 @@ export function trackMcpToolCall( ? { $mcp_parameters: safeValue(args.parameters) } : {}), $mcp_duration_ms: args.durationMs, + ...(args.resultTextChars !== undefined + ? { $mcp_response_text_chars: args.resultTextChars } + : {}), + ...(args.resultStructuredChars !== undefined + ? { $mcp_response_structured_chars: args.resultStructuredChars } + : {}), $mcp_is_error: args.isError, ...(args.errorType ? { $mcp_error_type: args.errorType } : {}), ...(args.errorMessage ? { $mcp_error_message: args.errorMessage } : {}), diff --git a/packages/core/src/mcp/build-server.ts b/packages/core/src/mcp/build-server.ts index 1a79971b5e8..9d5e3f6f12f 100644 --- a/packages/core/src/mcp/build-server.ts +++ b/packages/core/src/mcp/build-server.ts @@ -99,6 +99,7 @@ import { import { type McpAnalyticsContext, describeMcpError, + mcpToolResultSize, readClientInfoFromRequest, trackMcpResourceRead, trackMcpResourcesList, @@ -4987,6 +4988,7 @@ export async function createMCPServerForRequest( : {}), parameters: analyticsParameters(toolName, calledArgs), durationMs: Date.now() - startedAt, + ...mcpToolResultSize(result), isError: (result as { isError?: boolean }).isError === true, ...(failure ?? {}), }); From 6fef0b876a680c62460806effbba7bffa9cc5ee2 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:34:08 -0500 Subject: [PATCH 2/4] refactor(core): measure MCP results without prose comments or a swallowed catch --- packages/core/src/mcp/analytics.spec.ts | 6 ++- packages/core/src/mcp/analytics.ts | 49 +++++++++++++------------ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/core/src/mcp/analytics.spec.ts b/packages/core/src/mcp/analytics.spec.ts index 155048ba877..43d7d8a9064 100644 --- a/packages/core/src/mcp/analytics.spec.ts +++ b/packages/core/src/mcp/analytics.spec.ts @@ -157,7 +157,11 @@ describe("MCP analytics events", () => { structuredContent: { items: ["a"] }, }), ).toEqual({ resultTextChars: 2, resultStructuredChars: 15 }); - expect(mcpToolResultSize(undefined)).toEqual({ resultTextChars: 0 }); + expect(mcpToolResultSize({ structuredContent: null })).toEqual({ + resultTextChars: 0, + resultStructuredChars: 4, + }); + expect(mcpToolResultSize(undefined)).toEqual({}); }); it("includes redacted $mcp_parameters only when opted in", async () => { diff --git a/packages/core/src/mcp/analytics.ts b/packages/core/src/mcp/analytics.ts index 40ccc674e60..fef90074201 100644 --- a/packages/core/src/mcp/analytics.ts +++ b/packages/core/src/mcp/analytics.ts @@ -215,35 +215,36 @@ export interface McpToolResultSize { resultStructuredChars?: number; } -// How big a result is, never what it says. Hosts cut or move a result past -// about 40,000 characters, and they read different parts of it: Claude Code -// and OpenCode show the model only the structured content when there is one, -// and Codex shows both, so each part is counted on its own. -export function mcpToolResultSize(result: unknown): McpToolResultSize { - const record = - result && typeof result === "object" - ? (result as { content?: unknown; structuredContent?: unknown }) - : {}; +/** + * How big an MCP tool result is, never what it says: the characters in its + * text blocks, and in its structured content as JSON when it has any. Hosts + * read different parts of a result, so each part is counted on its own. + */ +export function mcpToolResultSize(result: unknown): Partial { + if (typeof result !== "object" || result === null) return {}; + const blocks: unknown[] = + "content" in result && Array.isArray(result.content) ? result.content : []; let resultTextChars = 0; - if (Array.isArray(record.content)) { - for (const block of record.content) { - if (block?.type === "text" && typeof block.text === "string") { - resultTextChars += block.text.length; - } - } - } - let resultStructuredChars: number | undefined; - if (record.structuredContent !== undefined) { - try { - resultStructuredChars = JSON.stringify(record.structuredContent).length; - } catch { - // A value JSON cannot hold fails the response on its own; the - // measurement never adds a failure of its own. + for (const block of blocks) { + if ( + typeof block === "object" && + block !== null && + "type" in block && + block.type === "text" && + "text" in block && + typeof block.text === "string" + ) { + resultTextChars += block.text.length; } } return { resultTextChars, - ...(resultStructuredChars !== undefined ? { resultStructuredChars } : {}), + ...("structuredContent" in result && result.structuredContent !== undefined + ? { + resultStructuredChars: JSON.stringify(result.structuredContent) + .length, + } + : {}), }; } From bcb46d2f26bede28158d43533b5ce75a99e9e580 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:40:30 -0500 Subject: [PATCH 3/4] test(core): read the tool-call event without non-null assertions --- packages/core/src/mcp/analytics.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core/src/mcp/analytics.spec.ts b/packages/core/src/mcp/analytics.spec.ts index 43d7d8a9064..6b4eec0387b 100644 --- a/packages/core/src/mcp/analytics.spec.ts +++ b/packages/core/src/mcp/analytics.spec.ts @@ -127,15 +127,16 @@ describe("MCP analytics events", () => { arguments: {}, }); - const props = eventNamed("$mcp_tool_call")!.properties!; + const props = eventNamed("$mcp_tool_call")?.properties; + expect(props).toBeDefined(); const text = (result.content as Array<{ type: string; text?: string }>) .filter((block) => block.type === "text") .map((block) => block.text ?? "") .join(""); expect(text).toContain("Quarterly plan draft"); - expect(props.$mcp_response_text_chars).toBe(text.length); + expect(props?.$mcp_response_text_chars).toBe(text.length); expect(result.structuredContent).toBeDefined(); - expect(props.$mcp_response_structured_chars).toBe( + expect(props?.$mcp_response_structured_chars).toBe( JSON.stringify(result.structuredContent).length, ); expect(JSON.stringify(props)).not.toContain("Quarterly plan draft"); From 0832079edbef0d31832ecb7a97cd38af63e7656d Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 09:44:36 -0500 Subject: [PATCH 4/4] perf(core): measure MCP results only when MCP analytics are on --- .agents/skills/tracking/SKILL.md | 3 +- .../direct-action-call.spec.ts.snap | 129 ++---------------- packages/core/src/mcp/analytics.ts | 16 +-- packages/core/src/mcp/build-server.ts | 3 +- 4 files changed, 23 insertions(+), 128 deletions(-) diff --git a/.agents/skills/tracking/SKILL.md b/.agents/skills/tracking/SKILL.md index f5722e21498..ba95990b92e 100644 --- a/.agents/skills/tracking/SKILL.md +++ b/.agents/skills/tracking/SKILL.md @@ -371,7 +371,8 @@ event: `$mcp_tool_name`, `$mcp_tool_description`, `$mcp_tool_category` the result has none). Hosts cut or move a result past about 40,000 characters, and they read different parts: Claude Code and OpenCode show the model only the structured content when there is one, Codex shows both. The - handler measures the result and passes only the two numbers, so no part of + handler measures the result only when MCP analytics are on + (`mcpAnalyticsEnabled()`), and passes only the two numbers, so no part of the payload reaches `trackMcpToolCall`. Off switches: `MCP_ANALYTICS=false` (`observability.mcpEvents`) disables the diff --git a/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap b/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap index cdbe44b86ab..afc95d7c4a0 100644 --- a/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap +++ b/packages/core/src/mcp/__snapshots__/direct-action-call.spec.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: a client without elicitation gets the review page link 1`] = ` { "trace": [ @@ -37,7 +37,6 @@ exports[`direct tools/call wire output > approval: a client without elicitation "parameters": { "draftId": "d-6", }, - "resultTextChars": 384, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -80,7 +79,7 @@ After they approve, call publish again with exactly the same arguments before 20 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: a grant that expired in the store is refused 1`] = ` { "trace": [ @@ -117,7 +116,6 @@ exports[`direct tools/call wire output > approval: a grant that expired in the s "parameters": { "draftId": "d-8", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -141,7 +139,6 @@ exports[`direct tools/call wire output > approval: a grant that expired in the s "parameters": { "draftId": "d-8", }, - "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -222,7 +219,7 @@ Draft id: d-8", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: a resume after the approval window is refused 1`] = ` { "trace": [ @@ -259,7 +256,6 @@ exports[`direct tools/call wire output > approval: a resume after the approval w "parameters": { "draftId": "d-9", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -283,7 +279,6 @@ exports[`direct tools/call wire output > approval: a resume after the approval w "parameters": { "draftId": "d-9", }, - "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -364,7 +359,6 @@ Draft id: d-9", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > approval: a static-token caller cannot approve 1`] = ` { "trace": [ @@ -375,7 +369,6 @@ exports[`direct tools/call wire output > approval: a static-token caller cannot "parameters": { "draftId": "d-5", }, - "resultTextChars": 56, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -411,7 +404,7 @@ exports[`direct tools/call wire output > approval: a static-token caller cannot } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: client-fulfilled elicitation round trip 1`] = ` { "trace": [ @@ -448,7 +441,6 @@ exports[`direct tools/call wire output > approval: client-fulfilled elicitation "parameters": { "draftId": "d-4", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -561,7 +553,6 @@ exports[`direct tools/call wire output > approval: client-fulfilled elicitation "parameters": { "draftId": "d-4", }, - "resultTextChars": 9, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -641,7 +632,7 @@ Draft id: d-4", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: denied decision and predicate outcomes 1`] = ` { "trace": [ @@ -678,7 +669,6 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "parameters": { "draftId": "d-3", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -703,7 +693,6 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "parameters": { "draftId": "d-3", }, - "resultTextChars": 25, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -750,7 +739,6 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "parameters": { "big": true, }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Approval only for big changes", "toolName": "maybe-approve", @@ -793,7 +781,6 @@ exports[`direct tools/call wire output > approval: denied decision and predicate "durationMs": "", "isError": false, "parameters": {}, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Approval predicate throws", "toolName": "approval-throws", @@ -963,7 +950,7 @@ Big: Yes", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: elicitation, approved retry, and replay 1`] = ` { "trace": [ @@ -1000,7 +987,6 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-1", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1113,7 +1099,6 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-1", }, - "resultTextChars": 9, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1137,7 +1122,6 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-1", }, - "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1150,7 +1134,6 @@ exports[`direct tools/call wire output > approval: elicitation, approved retry, "parameters": { "draftId": "d-2", }, - "resultTextChars": 66, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1278,7 +1261,7 @@ Draft id: d-1", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: the client gives up when its round limit is exhausted 1`] = ` { "trace": [ @@ -1315,7 +1298,6 @@ exports[`direct tools/call wire output > approval: the client gives up when its "parameters": { "draftId": "d-7", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1379,7 +1361,7 @@ Draft id: d-7", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: each grant the store is asked to create now carries createdAt, the ask time the server dated the approval notice from exports[`direct tools/call wire output > approval: two concurrent resumes of one approval run the action once 1`] = ` { "firstLeg": { @@ -1417,7 +1399,6 @@ exports[`direct tools/call wire output > approval: two concurrent resumes of one "parameters": { "draftId": "d-10", }, - "resultTextChars": 0, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1542,11 +1523,10 @@ Draft id: d-10", { "mcpToolCall": { "durationMs": "", - "isError": true, + "isError": false, "parameters": { "draftId": "d-10", }, - "resultTextChars": 58, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1555,11 +1535,10 @@ Draft id: d-10", { "mcpToolCall": { "durationMs": "", - "isError": false, + "isError": true, "parameters": { "draftId": "d-10", }, - "resultTextChars": 9, "toolCategory": "write", "toolDescription": "Publish", "toolName": "publish", @@ -1665,7 +1644,7 @@ Draft id: d-10", } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any +// oracle-change: a read-only grant no longer gets cards by default, so the widget returns a plain result exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: embed-widget 1`] = ` { "trace": [ @@ -1684,8 +1663,6 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 68, - "resultTextChars": 68, "toolCategory": "read", "toolDescription": "Opens a widget", "toolName": "embed-widget", @@ -1726,7 +1703,6 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: read-thing 1`] = ` { "trace": [ @@ -1737,7 +1713,6 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: "errorType": "unknown_tool", "isError": true, "parameters": {}, - "resultTextChars": 24, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "read-thing", @@ -1773,7 +1748,6 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: write-thing 1`] = ` { "trace": [ @@ -1784,7 +1758,6 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: "errorType": "unknown_tool", "isError": true, "parameters": {}, - "resultTextChars": 25, "toolCategory": "write", "toolDescription": "Write a thing", "toolName": "write-thing", @@ -1820,7 +1793,6 @@ exports[`direct tools/call wire output > compact catalog, read-only OAuth scope: } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > directory catalog: projected results, errors, and widget embeds 1`] = ` { "trace": [ @@ -1865,8 +1837,6 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 400, - "resultTextChars": 136, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "dir-read", @@ -1966,7 +1936,6 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "errorType": "Error", "isError": true, "parameters": {}, - "resultTextChars": 22, "toolCategory": "write", "toolDescription": "Always fails", "toolName": "dir-fail", @@ -2017,8 +1986,6 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 350, - "resultTextChars": 72, "toolCategory": "read", "toolDescription": "Opens a widget", "toolName": "dir-widget", @@ -2133,8 +2100,6 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 355, - "resultTextChars": 71, "toolCategory": "write", "toolDescription": "Opens a widget after a write", "toolName": "dir-write-widget", @@ -2234,7 +2199,6 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "durationMs": "", "isError": true, "parameters": {}, - "resultTextChars": 33, "toolCategory": "write", "toolDescription": "Proxied MCP error", "toolName": "dir-proxy-error", @@ -2247,7 +2211,6 @@ exports[`direct tools/call wire output > directory catalog: projected results, e "errorType": "unknown_tool", "isError": true, "parameters": {}, - "resultTextChars": 24, "toolName": "read-thing", }, }, @@ -2299,7 +2262,6 @@ data: {"result":{"content":[{"type":"text","text":"Unknown tool: read-thing"}]," } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: app-only 1`] = ` { "trace": [ @@ -2388,8 +2350,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: app-only 1`] "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 43, - "resultTextChars": 19, "toolCategory": "write", "toolDescription": "Widget-only helper", "toolName": "app-only", @@ -2431,7 +2391,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: app-only 1`] } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: bigint-read 1`] = ` { "trace": [ @@ -2452,7 +2411,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-read 1 "errorType": "result_not_json", "isError": true, "parameters": {}, - "resultTextChars": 68, "toolCategory": "read", "toolDescription": "Read whose result is not JSON", "toolName": "bigint-read", @@ -2488,7 +2446,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-read 1 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: bigint-write 1`] = ` { "trace": [ @@ -2578,7 +2535,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-write "durationMs": "", "isError": false, "parameters": {}, - "resultTextChars": 98, "toolCategory": "write", "toolDescription": "Write whose result is not JSON", "toolName": "bigint-write", @@ -2613,7 +2569,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: bigint-write } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: contract-empty-code 1`] = ` { "trace": [ @@ -2705,7 +2660,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-empt "errorType": "ActionContractError", "isError": true, "parameters": {}, - "resultTextChars": 25, "toolCategory": "write", "toolDescription": "Fails a contract with an empty code", "toolName": "contract-empty-code", @@ -2741,7 +2695,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-empt } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: contract-fail 1`] = ` { "trace": [ @@ -2833,7 +2786,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-fail "errorType": "stale_revision", "isError": true, "parameters": {}, - "resultTextChars": 53, "toolCategory": "write", "toolDescription": "Fails a contract", "toolName": "contract-fail", @@ -2869,7 +2821,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-fail } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: contract-generic 1`] = ` { "trace": [ @@ -2961,7 +2912,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-gene "errorType": "action_failed", "isError": true, "parameters": {}, - "resultTextChars": 23, "toolCategory": "write", "toolDescription": "Fails generically", "toolName": "contract-generic", @@ -2997,7 +2947,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: contract-gene } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: cycle-read 1`] = ` { "trace": [ @@ -3016,8 +2965,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-read 1` "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 42, - "resultTextChars": 42, "toolCategory": "read", "toolDescription": "Read whose result is circular", "toolName": "cycle-read", @@ -3056,7 +3003,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-read 1` } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: cycle-write 1`] = ` { "trace": [ @@ -3146,7 +3092,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-write 1 "durationMs": "", "isError": false, "parameters": {}, - "resultTextChars": 33, "toolCategory": "write", "toolDescription": "Write whose result is circular", "toolName": "cycle-write", @@ -3181,7 +3126,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: cycle-write 1 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-empty 1`] = ` { "trace": [ @@ -3200,8 +3144,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-empty 1 "durationMs": "", "isError": true, "parameters": {}, - "resultStructuredChars": 15, - "resultTextChars": 2, "toolCategory": "read", "toolDescription": "Widget with nothing to show", "toolName": "embed-empty", @@ -3240,7 +3182,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-empty 1 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-leak 1`] = ` { "trace": [ @@ -3259,8 +3200,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-leak 1` "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 102, - "resultTextChars": 102, "toolCategory": "read", "toolDescription": "Returns an embed ticket without a widget", "toolName": "embed-leak", @@ -3307,7 +3246,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-leak 1` } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget 1`] = ` { "trace": [ @@ -3326,8 +3264,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 68, - "resultTextChars": 16, "toolCategory": "read", "toolDescription": "Opens a widget", "toolName": "embed-widget", @@ -3372,7 +3308,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget-existing 1`] = ` { "trace": [ @@ -3461,8 +3396,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget- "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 70, - "resultTextChars": 11, "toolCategory": "write", "toolDescription": "Widget with its own ticket", "toolName": "embed-widget-existing", @@ -3506,7 +3439,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-widget- } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: embed-write-leak 1`] = ` { "trace": [ @@ -3596,7 +3528,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-write-l "durationMs": "", "isError": false, "parameters": {}, - "resultTextChars": 37, "toolCategory": "write", "toolDescription": "Write that returns an embed ticket", "toolName": "embed-write-leak", @@ -3631,7 +3562,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: embed-write-l } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: fail-thing 1`] = ` { "trace": [ @@ -3723,7 +3653,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: fail-thing 1` "errorType": "Error", "isError": true, "parameters": {}, - "resultTextChars": 11, "toolCategory": "write", "toolDescription": "Always fails", "toolName": "fail-thing", @@ -3759,7 +3688,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: fail-thing 1` } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: image-thing 1`] = ` { "trace": [ @@ -3778,8 +3706,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: image-thing 1 "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 28, - "resultTextChars": 193, "toolCategory": "read", "toolDescription": "Returns images", "toolName": "image-thing", @@ -3826,7 +3752,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: image-thing 1 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: list-things 1`] = ` { "trace": [ @@ -3845,8 +3770,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: list-things 1 "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 33, - "resultTextChars": 23, "toolCategory": "read", "toolDescription": "List things", "toolName": "list-things", @@ -3891,7 +3814,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: list-things 1 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: long-read 1`] = ` { "trace": [ @@ -3910,8 +3832,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: long-read 1`] "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 2611, - "resultTextChars": 2611, "toolCategory": "read", "toolDescription": "Read a long thing", "toolName": "long-read", @@ -3949,7 +3869,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: long-read 1`] } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: maybe-approve 1`] = ` { "trace": [ @@ -4050,7 +3969,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: maybe-approve "parameters": { "big": false, }, - "resultTextChars": 24, "toolCategory": "write", "toolDescription": "Approval only for big changes", "toolName": "maybe-approve", @@ -4085,7 +4003,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: maybe-approve } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: no-such-tool 1`] = ` { "trace": [ @@ -4096,7 +4013,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: no-such-tool "errorType": "unknown_tool", "isError": true, "parameters": {}, - "resultTextChars": 26, "toolName": "no-such-tool", }, }, @@ -4130,7 +4046,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: no-such-tool } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: partial-then-fail 1`] = ` { "trace": [ @@ -4225,7 +4140,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: partial-then- "errorType": "Error", "isError": true, "parameters": {}, - "resultTextChars": 27, "toolCategory": "write", "toolDescription": "Writes, then fails", "toolName": "partial-then-fail", @@ -4261,7 +4175,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: partial-then- } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: read-thing 1`] = ` { "trace": [ @@ -4280,8 +4193,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: read-thing 1` "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 375, - "resultTextChars": 111, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "read-thing", @@ -4345,7 +4256,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: read-thing 1` } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: throws-string 1`] = ` { "trace": [ @@ -4437,7 +4347,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: throws-string "errorType": "Error", "isError": true, "parameters": {}, - "resultTextChars": 16, "toolCategory": "write", "toolDescription": "Throws a non-Error", "toolName": "throws-string", @@ -4473,7 +4382,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: throws-string } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-error 1`] = ` { "trace": [ @@ -4556,7 +4464,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-error "durationMs": "", "isError": true, "parameters": {}, - "resultTextChars": 15, "toolCategory": "write", "toolDescription": "Proxied MCP error", "toolName": "wrapped-error", @@ -4592,7 +4499,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-error } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-ok 1`] = ` { "trace": [ @@ -4611,8 +4517,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-ok 1` "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 32, - "resultTextChars": 19, "toolCategory": "read", "toolDescription": "Proxied MCP result", "toolName": "wrapped-ok", @@ -4653,7 +4557,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-ok 1` } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-text-reads 1`] = ` { "trace": [ @@ -4675,8 +4578,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-text- "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 11, - "resultTextChars": 19, "toolCategory": "read", "toolDescription": "Proxied MCP result whose text can be read only so often", "toolName": "wrapped-text-reads", @@ -4714,7 +4615,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: wrapped-text- } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: write-thing 1`] = ` { "trace": [ @@ -4808,7 +4708,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-thing 1 "parameters": { "name": "draft", }, - "resultTextChars": 30, "toolCategory": "write", "toolDescription": "Write a thing", "toolName": "write-thing", @@ -4843,7 +4742,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-thing 1 } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, OAuth user: write-void 1`] = ` { "trace": [ @@ -4932,7 +4830,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-void 1` "durationMs": "", "isError": false, "parameters": {}, - "resultTextChars": 21, "toolCategory": "write", "toolDescription": "Write without a result", "toolName": "write-void", @@ -4967,7 +4864,6 @@ exports[`direct tools/call wire output > full catalog, OAuth user: write-void 1` } `; -// oracle-change: each tool call's analytics now carry the result's size: characters in its text blocks, and its structured content as JSON when it has any exports[`direct tools/call wire output > full catalog, read-only OAuth scope: a write is refused by scope 1`] = ` { "trace": [ @@ -4978,7 +4874,6 @@ exports[`direct tools/call wire output > full catalog, read-only OAuth scope: a "errorType": "forbidden_scope", "isError": true, "parameters": {}, - "resultTextChars": 54, "toolCategory": "write", "toolDescription": "Write a thing", "toolName": "write-thing", @@ -4999,8 +4894,6 @@ exports[`direct tools/call wire output > full catalog, read-only OAuth scope: a "durationMs": "", "isError": false, "parameters": {}, - "resultStructuredChars": 375, - "resultTextChars": 111, "toolCategory": "read", "toolDescription": "Read a thing", "toolName": "read-thing", diff --git a/packages/core/src/mcp/analytics.ts b/packages/core/src/mcp/analytics.ts index fef90074201..72f9c987b82 100644 --- a/packages/core/src/mcp/analytics.ts +++ b/packages/core/src/mcp/analytics.ts @@ -119,7 +119,7 @@ export function readClientInfoFromRequest( }; } -function analyticsEnabled(): boolean { +export function mcpAnalyticsEnabled(): boolean { if (listTrackingProviders().length === 0) return false; return getAppConfig().observability.mcpEvents; } @@ -194,7 +194,7 @@ function emit( } export function trackMcpInitialize(ctx: McpAnalyticsContext): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.initialize, ctx, {}); } @@ -202,7 +202,7 @@ export function trackMcpToolsList( ctx: McpAnalyticsContext, args: { toolNames: string[]; durationMs: number }, ): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.toolsList, ctx, { $mcp_listed_tool_names: args.toolNames, $mcp_listed_tool_count: args.toolNames.length, @@ -261,7 +261,7 @@ export function trackMcpToolCall( errorMessage?: string; } & Partial, ): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.toolCall, ctx, { $mcp_tool_name: args.toolName, ...(args.toolDescription @@ -288,7 +288,7 @@ export function trackMcpResourcesList( ctx: McpAnalyticsContext, args: { resourceCount: number; durationMs: number }, ): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.resourcesList, ctx, { $mcp_listed_resource_count: args.resourceCount, $mcp_duration_ms: args.durationMs, @@ -306,7 +306,7 @@ export function trackMcpResourceRead( errorMessage?: string; }, ): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.resourceRead, ctx, { ...(args.resourceName ? { $mcp_resource_name: args.resourceName } : {}), ...(args.resourceUri ? { $mcp_resource_uri: args.resourceUri } : {}), @@ -329,7 +329,7 @@ export function trackMcpOAuthAuthorizeOpened( ctx: McpAnalyticsContext, args: { route: McpOAuthRoute; signedIn: boolean }, ): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.oauthAuthorizeOpened, ctx, { $mcp_oauth_route: args.route, $mcp_oauth_signed_in: args.signedIn, @@ -340,7 +340,7 @@ export function trackMcpOAuthLoginWallShown( ctx: McpAnalyticsContext, args: { route: McpOAuthRoute }, ): void { - if (!analyticsEnabled()) return; + if (!mcpAnalyticsEnabled()) return; emit(MCP_ANALYTICS_EVENTS.oauthLoginWallShown, ctx, { $mcp_oauth_route: args.route, }); diff --git a/packages/core/src/mcp/build-server.ts b/packages/core/src/mcp/build-server.ts index 9d5e3f6f12f..48d34639225 100644 --- a/packages/core/src/mcp/build-server.ts +++ b/packages/core/src/mcp/build-server.ts @@ -99,6 +99,7 @@ import { import { type McpAnalyticsContext, describeMcpError, + mcpAnalyticsEnabled, mcpToolResultSize, readClientInfoFromRequest, trackMcpResourceRead, @@ -4988,7 +4989,7 @@ export async function createMCPServerForRequest( : {}), parameters: analyticsParameters(toolName, calledArgs), durationMs: Date.now() - startedAt, - ...mcpToolResultSize(result), + ...(mcpAnalyticsEnabled() ? mcpToolResultSize(result) : {}), isError: (result as { isError?: boolean }).isError === true, ...(failure ?? {}), });