Skip to content

feat(telemetry): track tool result size in bytes #838

@MQ37

Description

@MQ37

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    t-aiIssues owned by the AI team.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions