Problem
ToolCallTelemetryProperties has no signal for how heavy tool results are. Bytes is a simple, language-agnostic measure we can add cheaply.
src/types.ts:335 — current shape has no size field:
export type ToolCallTelemetryProperties = {
// ...
tool_status: ToolStatus;
tool_exec_time_ms: number;
// no result_size_bytes
};
Result is built via buildMCPResponse (src/utils/mcp.ts) with texts and optional structuredContent — both contribute to the payload sent to the client.
Fix
Add result_size_bytes: number to ToolCallTelemetryProperties. Compute as UTF-8 byte length of joined content[].text plus JSON.stringify(structuredContent) when present. Capture the result in the CallToolRequestSchema handler and pass it into logToolCallAndTelemetry (src/mcp/server.ts:1198) so it's emitted on the Segment MCP Tool Call event alongside tool_exec_time_ms.
Out of scope
Token counting — requires per-model tokenizer, adds cost for marginal accuracy gain over bytes.
Problem
ToolCallTelemetryPropertieshas no signal for how heavy tool results are. Bytes is a simple, language-agnostic measure we can add cheaply.src/types.ts:335— current shape has no size field:Result is built via
buildMCPResponse(src/utils/mcp.ts) withtextsand optionalstructuredContent— both contribute to the payload sent to the client.Fix
Add
result_size_bytes: numbertoToolCallTelemetryProperties. Compute as UTF-8 byte length of joinedcontent[].textplusJSON.stringify(structuredContent)when present. Capture the result in theCallToolRequestSchemahandler and pass it intologToolCallAndTelemetry(src/mcp/server.ts:1198) so it's emitted on the SegmentMCP Tool Callevent alongsidetool_exec_time_ms.Out of scope
Token counting — requires per-model tokenizer, adds cost for marginal accuracy gain over bytes.