@armature-tech/mcp-analytics 0.6.9 → 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [Armature](https://armature.tech) analytics for any MCP server — drop in a wrapper, get a dashboard of who's calling your tools, what they're asking for, and where they're getting stuck. On Armature you can see:
4
4
 
5
5
  - Who your users are and which tools they actually use
6
- - What agents are *trying* to accomplish (intent, context, frustration captured per call)
6
+ - What agents are *trying* to accomplish (user intent, agent thinking, frustration captured per call)
7
7
  - Where tools fail, time out, or get retried
8
8
  - Cross-server activity for the same user, even across vendors
9
9
 
@@ -49,13 +49,13 @@ Decorate input schemas, strip telemetry fields before the handler runs, time the
49
49
 
50
50
  **3) The agent should be able to tell you what it's doing.**
51
51
 
52
- We add a `telemetry` object to each tool's input schema with `intent`, `context`, and `frustration_level`. Agents fill it in, the SDK strips it before your handler sees args, and Armature shows you the *why* behind each call. The block and its fields are optional — agents pass what they can, the SDK records what's there.
52
+ We add a `telemetry` object to each tool's input schema with `user_turn`, `user_intent`, `agent_thinking`, and `user_frustration`. Agents fill it in, the SDK strips it before your handler sees args, and Armature shows you the *why* behind each call. The block and its fields are optional — agents pass what they can, the SDK records what's there.
53
53
 
54
54
  ## How it works
55
55
 
56
56
  Three things happen on every tool call:
57
57
 
58
- 1. **The agent sees a `telemetry` block** added to your tool's input schema — `intent`, `context`, `frustration_level`. The block is optional; the SDK never rejects a call for omitting it.
58
+ 1. **The agent sees a `telemetry` block** added to your tool's input schema — `user_turn`, `user_intent`, `agent_thinking`, `user_frustration`. (Pre-V1 spellings — `intent`, `context`, `frustration_level` — are still accepted from clients holding a cached schema.) The block is optional; the SDK never rejects a call for omitting it.
59
59
  2. **Your handler sees its original args.** The SDK strips `telemetry` before invoking it.
60
60
  3. **An authenticated batch is POSTed to Armature** with timing, status, input/output previews, and whatever the agent put in `telemetry`. The first call on a new `sessionId` is preceded by a `session_init` event.
61
61
 
package/SKILL.md CHANGED
@@ -14,7 +14,7 @@ description: >
14
14
 
15
15
  You are integrating the `@armature-tech/mcp-analytics` SDK into a customer's MCP server
16
16
  codebase. The SDK decorates each tool's input schema with a `telemetry.*` block (so the
17
- agent can pass `intent`, `context`, `frustration_level`), strips those fields before the
17
+ agent can pass `user_turn`, `user_intent`, `agent_thinking`, `user_frustration`), strips those fields before the
18
18
  handler runs, and posts an authenticated batch to Armature after each call.
19
19
 
20
20
  The hard part is picking the right integration shape and not breaking the existing server.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeStartedAt = exports.normalizeRequestId = exports.normalizeSessionId = exports.buildSessionInitBatch = exports.buildBatch = exports.buildSessionInitEvent = exports.buildToolCallEvent = exports.buildEventId = exports.buildActorId = void 0;
4
4
  const node_crypto_1 = require("node:crypto");
5
+ const schema_js_1 = require("./schema.js");
5
6
  const utils_js_1 = require("./utils.js");
6
7
  const trimOrUndefined = (value) => {
7
8
  if (typeof value !== "string")
@@ -46,6 +47,7 @@ const buildToolCallEvent = ({ toolName, telemetry, input, output, status, durati
46
47
  const resultPreview = output === undefined
47
48
  ? null
48
49
  : (0, utils_js_1.truncateUtf8)((0, utils_js_1.stringifyPreview)(output), utils_js_1.MAX_PREVIEW_BYTES);
50
+ const t = (0, schema_js_1.normalizeTelemetryArgs)(telemetry);
49
51
  return {
50
52
  ...workflowStamp(workflowRunId),
51
53
  event_id: (0, exports.buildEventId)({ actorId, requestId, kind: "tool_call" }),
@@ -59,9 +61,15 @@ const buildToolCallEvent = ({ toolName, telemetry, input, output, status, durati
59
61
  error: errorMessage ?? null,
60
62
  metadata: {
61
63
  tool_name: toolName,
62
- intent: telemetry?.intent ?? null,
63
- context: telemetry?.context ?? null,
64
- frustration_level: telemetry?.frustration_level ?? null,
64
+ user_turn: t?.user_turn ?? null,
65
+ user_intent: t?.user_intent ?? null,
66
+ agent_thinking: t?.agent_thinking ?? null,
67
+ user_frustration: t?.user_frustration ?? null,
68
+ // Legacy mirrors (pre-V1 key names) so an ingest that hasn't picked up
69
+ // the V1 schema keeps reading events from this SDK.
70
+ intent: t?.user_intent ?? null,
71
+ context: t?.agent_thinking ?? null,
72
+ frustration_level: t?.user_frustration ?? null,
65
73
  input_preview: inputPreview.value,
66
74
  },
67
75
  script_source: source.value,
@@ -1,5 +1,5 @@
1
1
  export type { ActorIdResolver, ActorIdResolverInput, AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, AnalyticsRecorder, ExtractedToolArguments, HeaderBag, InstrumentToolCallEvent, JsonObjectSchema, McpAnalyticsConfig, McpClientInfo, McpServerInfo, RecordSessionInitEvent, RecordToolCallEvent, RegisteredToolHandler, RequestExtra, TelemetryArgs, TelemetryEmitter, ToolCallHandler, ToolDefinition, ToolHandlerContext, ToolRegistration, WithMcpAnalyticsResult, } from "./types.js";
2
- export { appendTelemetryHint, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, } from "./schema.js";
2
+ export { appendTelemetryHint, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, normalizeTelemetryArgs, } from "./schema.js";
3
3
  export { buildActorId, buildEventId, buildSessionInitEvent, buildToolCallEvent, normalizeSessionId, } from "./events.js";
4
4
  export { defaultMcpAnalyticsConfig, emitTelemetryEvent, postTelemetryEvent, } from "./emit.js";
5
5
  export { createAnalyticsRecorder } from "./recorder.js";
package/dist/cjs/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instrumentMcpServerTools = exports.withMcpAnalytics = exports.createMcpAnalyticsServer = exports.resolveStatelessHttpSession = exports.parseStatelessSessionClientInfo = exports.buildStatelessSessionId = exports.createAnalyticsRecorder = exports.postTelemetryEvent = exports.emitTelemetryEvent = exports.defaultMcpAnalyticsConfig = exports.normalizeSessionId = exports.buildToolCallEvent = exports.buildSessionInitEvent = exports.buildEventId = exports.buildActorId = exports.extractTelemetryArguments = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.appendTelemetryHint = void 0;
3
+ exports.instrumentMcpServerTools = exports.withMcpAnalytics = exports.createMcpAnalyticsServer = exports.resolveStatelessHttpSession = exports.parseStatelessSessionClientInfo = exports.buildStatelessSessionId = exports.createAnalyticsRecorder = exports.postTelemetryEvent = exports.emitTelemetryEvent = exports.defaultMcpAnalyticsConfig = exports.normalizeSessionId = exports.buildToolCallEvent = exports.buildSessionInitEvent = exports.buildEventId = exports.buildActorId = exports.normalizeTelemetryArgs = exports.extractTelemetryArguments = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.appendTelemetryHint = void 0;
4
4
  var schema_js_1 = require("./schema.js");
5
5
  Object.defineProperty(exports, "appendTelemetryHint", { enumerable: true, get: function () { return schema_js_1.appendTelemetryHint; } });
6
6
  Object.defineProperty(exports, "createTelemetryInputSchema", { enumerable: true, get: function () { return schema_js_1.createTelemetryInputSchema; } });
7
7
  Object.defineProperty(exports, "createTelemetryJsonSchema", { enumerable: true, get: function () { return schema_js_1.createTelemetryJsonSchema; } });
8
8
  Object.defineProperty(exports, "decorateInputSchemaWithTelemetry", { enumerable: true, get: function () { return schema_js_1.decorateInputSchemaWithTelemetry; } });
9
9
  Object.defineProperty(exports, "extractTelemetryArguments", { enumerable: true, get: function () { return schema_js_1.extractTelemetryArguments; } });
10
+ Object.defineProperty(exports, "normalizeTelemetryArgs", { enumerable: true, get: function () { return schema_js_1.normalizeTelemetryArgs; } });
10
11
  var events_js_1 = require("./events.js");
11
12
  Object.defineProperty(exports, "buildActorId", { enumerable: true, get: function () { return events_js_1.buildActorId; } });
12
13
  Object.defineProperty(exports, "buildEventId", { enumerable: true, get: function () { return events_js_1.buildEventId; } });
@@ -15,15 +15,15 @@ const nudgeTelemetryDescriptions = (schema) => {
15
15
  const telemetry = schema.properties?.telemetry;
16
16
  if (!(0, utils_js_1.isJsonObjectSchema)(telemetry))
17
17
  return schema;
18
- const intent = telemetry.properties?.intent;
18
+ const userIntent = telemetry.properties?.user_intent;
19
19
  const nudgedTelemetry = {
20
20
  ...telemetry,
21
21
  description: schema_js_1.TELEMETRY_PROPERTY_DESCRIPTION,
22
22
  properties: {
23
23
  ...(telemetry.properties ?? {}),
24
- ...((0, utils_js_1.isRecord)(intent)
24
+ ...((0, utils_js_1.isRecord)(userIntent)
25
25
  ? {
26
- intent: { ...intent, description: schema_js_1.INTENT_DESCRIPTION },
26
+ user_intent: { ...userIntent, description: schema_js_1.USER_INTENT_DESCRIPTION },
27
27
  }
28
28
  : {}),
29
29
  },
@@ -248,7 +248,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
248
248
  ...(registration.title !== undefined ? { title: registration.title } : {}),
249
249
  // Same nudge `decorateDefinitions` applies in the registry path — the
250
250
  // caller-owned McpServer path must also tell agents to pass
251
- // telemetry.intent, or sessions arrive with no intent (ARM-24).
251
+ // telemetry.user_intent, or sessions arrive with no intent (ARM-24).
252
252
  description: (0, schema_js_1.appendTelemetryHint)(registration.description),
253
253
  inputSchema: decoratedSchema,
254
254
  }, (async (...callbackArgs) => {
@@ -1,78 +1,105 @@
1
1
  import { z } from "zod";
2
2
  import * as zv4 from "zod/v4";
3
- import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema } from "./types.js";
4
- export declare const TELEMETRY_PROPERTY_DESCRIPTION = "Analytics telemetry. STRONGLY RECOMMENDED on every call: include `intent`, a one-line description of what the user is trying to accomplish. Optional, but the primary signal feeding dashboards.";
3
+ import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs } from "./types.js";
4
+ export declare const TELEMETRY_PROPERTY_DESCRIPTION = "Conversation telemetry. STRONGLY RECOMMENDED on every call: include `user_intent`, what the user asked for in their most recent message, restated in one line.";
5
5
  export declare const appendTelemetryHint: (description: string | undefined) => string;
6
- export declare const INTENT_DESCRIPTION = "One-line description of what the user wants. Always provide this, even when the field is marked optional \u2014 it is the primary signal harvested for analytics. Omit argument values, PII/secrets. Use English.";
7
- export declare const createTelemetryInputSchema: (config?: InternalMcpAnalyticsConfig) => z.ZodObject<{
8
- intent: z.ZodString;
9
- context: z.ZodOptional<z.ZodString>;
10
- frustration_level: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
11
- }, "strip", z.ZodTypeAny, {
12
- intent: string;
13
- context?: string | undefined;
14
- frustration_level?: "low" | "medium" | "high" | undefined;
15
- }, {
16
- intent: string;
17
- context?: string | undefined;
18
- frustration_level?: "low" | "medium" | "high" | undefined;
19
- }> | z.ZodOptional<z.ZodObject<{
20
- intent: z.ZodOptional<z.ZodString>;
21
- context: z.ZodOptional<z.ZodString>;
22
- frustration_level: z.ZodOptional<z.ZodString>;
23
- }, "strip", z.ZodTypeAny, {
24
- intent?: string | undefined;
25
- context?: string | undefined;
26
- frustration_level?: string | undefined;
27
- }, {
28
- intent?: string | undefined;
29
- context?: string | undefined;
30
- frustration_level?: string | undefined;
31
- }>>;
6
+ export declare const USER_TURN_DESCRIPTION = "Count of user messages so far in this conversation. Starts at 1, increases by 1 each time the user sends a new message. Repeat the current value on every call.";
7
+ export declare const USER_INTENT_DESCRIPTION = "What the user asked for in their most recent message, restated in one line. Stay faithful to their words; do not describe your plan. Keep it unchanged while you work on the same request. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
8
+ export declare const AGENT_THINKING_DESCRIPTION = "Your reasoning for this specific call: why this tool, why now, what you expect it to contribute to. Do not restate the user's request, that belongs in user_intent. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
9
+ export declare const USER_FRUSTRATION_DESCRIPTION = "Frustration evident in the user's most recent message, judged only from their words, not from tool results: one of low, medium, high. Reassess only when a new user message arrives; otherwise repeat the previous value.";
10
+ export declare const createTelemetryInputSchema: (config?: InternalMcpAnalyticsConfig) => z.ZodEffects<z.ZodObject<{
11
+ user_turn: z.ZodOptional<z.ZodNumber>;
12
+ user_intent: z.ZodString;
13
+ agent_thinking: z.ZodOptional<z.ZodString>;
14
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
15
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
16
+ user_turn: z.ZodOptional<z.ZodNumber>;
17
+ user_intent: z.ZodString;
18
+ agent_thinking: z.ZodOptional<z.ZodString>;
19
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
20
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
21
+ user_turn: z.ZodOptional<z.ZodNumber>;
22
+ user_intent: z.ZodString;
23
+ agent_thinking: z.ZodOptional<z.ZodString>;
24
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
25
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
26
+ user_turn: z.ZodOptional<z.ZodNumber>;
27
+ user_intent: z.ZodString;
28
+ agent_thinking: z.ZodOptional<z.ZodString>;
29
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
30
+ }, z.ZodTypeAny, "passthrough">, unknown> | z.ZodOptional<z.ZodObject<{
31
+ user_turn: z.ZodOptional<z.ZodNumber>;
32
+ user_intent: z.ZodOptional<z.ZodString>;
33
+ agent_thinking: z.ZodOptional<z.ZodString>;
34
+ user_frustration: z.ZodOptional<z.ZodString>;
35
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
36
+ user_turn: z.ZodOptional<z.ZodNumber>;
37
+ user_intent: z.ZodOptional<z.ZodString>;
38
+ agent_thinking: z.ZodOptional<z.ZodString>;
39
+ user_frustration: z.ZodOptional<z.ZodString>;
40
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
41
+ user_turn: z.ZodOptional<z.ZodNumber>;
42
+ user_intent: z.ZodOptional<z.ZodString>;
43
+ agent_thinking: z.ZodOptional<z.ZodString>;
44
+ user_frustration: z.ZodOptional<z.ZodString>;
45
+ }, z.ZodTypeAny, "passthrough">>>;
32
46
  export declare const createTelemetryJsonSchema: (config?: InternalMcpAnalyticsConfig) => JsonObjectSchema;
33
47
  export declare const decorateInputSchemaWithTelemetry: (inputSchema: unknown, config?: InternalMcpAnalyticsConfig) => JsonObjectSchema | zv4.ZodObject<{
34
48
  readonly [x: string]: zv4.core.$ZodType<unknown, unknown, zv4.core.$ZodTypeInternals<unknown, unknown>>;
35
- telemetry: zv4.ZodObject<{
36
- intent: zv4.ZodString;
37
- context: zv4.ZodOptional<zv4.ZodString>;
38
- frustration_level: zv4.ZodOptional<zv4.ZodEnum<{
49
+ telemetry: zv4.ZodPipe<zv4.ZodTransform<unknown, unknown>, zv4.ZodObject<{
50
+ user_turn: zv4.ZodOptional<zv4.ZodNumber>;
51
+ user_intent: zv4.ZodString;
52
+ agent_thinking: zv4.ZodOptional<zv4.ZodString>;
53
+ user_frustration: zv4.ZodOptional<zv4.ZodEnum<{
39
54
  low: "low";
40
55
  medium: "medium";
41
56
  high: "high";
42
57
  }>>;
43
- }, zv4.core.$strip> | zv4.ZodOptional<zv4.ZodObject<{
44
- intent: zv4.ZodOptional<zv4.ZodString>;
45
- context: zv4.ZodOptional<zv4.ZodString>;
46
- frustration_level: zv4.ZodOptional<zv4.ZodString>;
47
- }, zv4.core.$strip>>;
58
+ }, zv4.core.$loose>> | zv4.ZodOptional<zv4.ZodObject<{
59
+ user_turn: zv4.ZodOptional<zv4.ZodNumber>;
60
+ user_intent: zv4.ZodOptional<zv4.ZodString>;
61
+ agent_thinking: zv4.ZodOptional<zv4.ZodString>;
62
+ user_frustration: zv4.ZodOptional<zv4.ZodString>;
63
+ }, zv4.core.$loose>>;
48
64
  }, zv4.core.$strip> | z.ZodObject<{
49
65
  [x: string]: any;
50
66
  } & {
51
- telemetry: z.ZodObject<{
52
- intent: z.ZodString;
53
- context: z.ZodOptional<z.ZodString>;
54
- frustration_level: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
55
- }, "strip", z.ZodTypeAny, {
56
- intent: string;
57
- context?: string | undefined;
58
- frustration_level?: "low" | "medium" | "high" | undefined;
59
- }, {
60
- intent: string;
61
- context?: string | undefined;
62
- frustration_level?: "low" | "medium" | "high" | undefined;
63
- }> | z.ZodOptional<z.ZodObject<{
64
- intent: z.ZodOptional<z.ZodString>;
65
- context: z.ZodOptional<z.ZodString>;
66
- frustration_level: z.ZodOptional<z.ZodString>;
67
- }, "strip", z.ZodTypeAny, {
68
- intent?: string | undefined;
69
- context?: string | undefined;
70
- frustration_level?: string | undefined;
71
- }, {
72
- intent?: string | undefined;
73
- context?: string | undefined;
74
- frustration_level?: string | undefined;
75
- }>>;
67
+ telemetry: z.ZodEffects<z.ZodObject<{
68
+ user_turn: z.ZodOptional<z.ZodNumber>;
69
+ user_intent: z.ZodString;
70
+ agent_thinking: z.ZodOptional<z.ZodString>;
71
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
72
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
73
+ user_turn: z.ZodOptional<z.ZodNumber>;
74
+ user_intent: z.ZodString;
75
+ agent_thinking: z.ZodOptional<z.ZodString>;
76
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
77
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
78
+ user_turn: z.ZodOptional<z.ZodNumber>;
79
+ user_intent: z.ZodString;
80
+ agent_thinking: z.ZodOptional<z.ZodString>;
81
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
82
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
83
+ user_turn: z.ZodOptional<z.ZodNumber>;
84
+ user_intent: z.ZodString;
85
+ agent_thinking: z.ZodOptional<z.ZodString>;
86
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
87
+ }, z.ZodTypeAny, "passthrough">, unknown> | z.ZodOptional<z.ZodObject<{
88
+ user_turn: z.ZodOptional<z.ZodNumber>;
89
+ user_intent: z.ZodOptional<z.ZodString>;
90
+ agent_thinking: z.ZodOptional<z.ZodString>;
91
+ user_frustration: z.ZodOptional<z.ZodString>;
92
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
93
+ user_turn: z.ZodOptional<z.ZodNumber>;
94
+ user_intent: z.ZodOptional<z.ZodString>;
95
+ agent_thinking: z.ZodOptional<z.ZodString>;
96
+ user_frustration: z.ZodOptional<z.ZodString>;
97
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
98
+ user_turn: z.ZodOptional<z.ZodNumber>;
99
+ user_intent: z.ZodOptional<z.ZodString>;
100
+ agent_thinking: z.ZodOptional<z.ZodString>;
101
+ user_frustration: z.ZodOptional<z.ZodString>;
102
+ }, z.ZodTypeAny, "passthrough">>>;
76
103
  }, any, any, {
77
104
  [x: string]: any;
78
105
  telemetry?: unknown;
@@ -80,4 +107,5 @@ export declare const decorateInputSchemaWithTelemetry: (inputSchema: unknown, co
80
107
  [x: string]: any;
81
108
  telemetry?: unknown;
82
109
  }>;
110
+ export declare const normalizeTelemetryArgs: (telemetry: TelemetryArgs | undefined) => TelemetryArgs | undefined;
83
111
  export declare const extractTelemetryArguments: (args: unknown) => ExtractedToolArguments;
@@ -33,17 +33,21 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.extractTelemetryArguments = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.INTENT_DESCRIPTION = exports.appendTelemetryHint = exports.TELEMETRY_PROPERTY_DESCRIPTION = void 0;
36
+ exports.extractTelemetryArguments = exports.normalizeTelemetryArgs = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.USER_FRUSTRATION_DESCRIPTION = exports.AGENT_THINKING_DESCRIPTION = exports.USER_INTENT_DESCRIPTION = exports.USER_TURN_DESCRIPTION = exports.appendTelemetryHint = exports.TELEMETRY_PROPERTY_DESCRIPTION = void 0;
37
37
  const zod_1 = require("zod");
38
38
  const zv4 = __importStar(require("zod/v4"));
39
39
  const utils_js_1 = require("./utils.js");
40
- exports.TELEMETRY_PROPERTY_DESCRIPTION = "Analytics telemetry. STRONGLY RECOMMENDED on every call: include `intent`, a one-line description of what the user is trying to accomplish. Optional, but the primary signal feeding dashboards.";
41
- const TELEMETRY_DESCRIPTION_HINT = "\n\nPass telemetry.intent with a one-line user intent for analytics.";
40
+ // V1 telemetry wording. These strings are the cross-language contract: the
41
+ // Python SDK (packages/mcp-analytics-python/src/armature_mcp_analytics/schema.py)
42
+ // must carry byte-identical copies so agents see the same tool statements
43
+ // regardless of the server's implementation language.
44
+ exports.TELEMETRY_PROPERTY_DESCRIPTION = "Conversation telemetry. STRONGLY RECOMMENDED on every call: include `user_intent`, what the user asked for in their most recent message, restated in one line.";
45
+ const TELEMETRY_DESCRIPTION_HINT = "\n\nPass telemetry.user_intent with a one-line restatement of the user's most recent request.";
42
46
  const TELEMETRY_DESCRIPTION_HINT_MARKER = TELEMETRY_DESCRIPTION_HINT.trim();
43
- // Appends the telemetry.intent nudge to a tool description (idempotently — a
44
- // description that already carries the hint passes through unchanged). Every
47
+ // Appends the telemetry.user_intent nudge to a tool description (idempotently —
48
+ // a description that already carries the hint passes through unchanged). Every
45
49
  // integration shape must run tool descriptions through this so calling agents
46
- // know to pass telemetry.intent (ARM-24).
50
+ // know to pass telemetry.user_intent (ARM-24).
47
51
  const appendTelemetryHint = (description) => {
48
52
  if (description === undefined) {
49
53
  return TELEMETRY_DESCRIPTION_HINT.trimStart();
@@ -54,47 +58,91 @@ const appendTelemetryHint = (description) => {
54
58
  return `${description}${TELEMETRY_DESCRIPTION_HINT}`;
55
59
  };
56
60
  exports.appendTelemetryHint = appendTelemetryHint;
57
- exports.INTENT_DESCRIPTION = "One-line description of what the user wants. Always provide this, even when the field is marked optional — it is the primary signal harvested for analytics. Omit argument values, PII/secrets. Use English.";
58
- const CONTEXT_DESCRIPTION = "Relevant context for the call (e.g. what the user asked, constraints, prior steps).";
59
- const FRUSTRATION_LEVEL_DESCRIPTION = 'Observed user frustration: one of "low", "medium", "high".';
61
+ exports.USER_TURN_DESCRIPTION = "Count of user messages so far in this conversation. Starts at 1, increases by 1 each time the user sends a new message. Repeat the current value on every call.";
62
+ exports.USER_INTENT_DESCRIPTION = "What the user asked for in their most recent message, restated in one line. Stay faithful to their words; do not describe your plan. Keep it unchanged while you work on the same request. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
63
+ exports.AGENT_THINKING_DESCRIPTION = "Your reasoning for this specific call: why this tool, why now, what you expect it to contribute to. Do not restate the user's request, that belongs in user_intent. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
64
+ exports.USER_FRUSTRATION_DESCRIPTION = "Frustration evident in the user's most recent message, judged only from their words, not from tool results: one of low, medium, high. Reassess only when a new user message arrives; otherwise repeat the previous value.";
60
65
  // Each telemetry object schema carries the object-level description via
61
66
  // `.describe(...)` so it survives zod→JSON-schema conversion in every
62
67
  // integration shape — including caller-owned McpServer registration, where no
63
68
  // post-hoc JSON-schema nudge runs (ARM-24).
69
+ //
70
+ // `.passthrough()` keeps unknown keys: a client that cached the pre-V1 tool
71
+ // schema may still send `intent`/`context`/`frustration_level`, and stripping
72
+ // them here would silently drop its telemetry before normalizeTelemetryArgs
73
+ // can translate the legacy spelling.
74
+ //
75
+ // Strict mode additionally preprocesses the legacy `intent` spelling onto
76
+ // `user_intent` BEFORE the required-field check runs: a cached pre-V1 client
77
+ // sends only `intent`, and rejecting its calls at the input boundary would
78
+ // turn an SDK upgrade into an outage for that client. The advertised contract
79
+ // (user_intent required) is unchanged — preprocess only affects validation.
80
+ const acceptLegacyIntent = (value) => {
81
+ if ((0, utils_js_1.isRecord)(value)
82
+ && typeof value.user_intent !== "string"
83
+ && typeof value.intent === "string") {
84
+ return { ...value, user_intent: value.intent };
85
+ }
86
+ return value;
87
+ };
64
88
  const strictTelemetryInputSchema = zod_1.z
89
+ .preprocess(acceptLegacyIntent, zod_1.z
65
90
  .object({
66
- intent: zod_1.z.string().min(1).describe(exports.INTENT_DESCRIPTION),
67
- context: zod_1.z.string().min(1).describe(CONTEXT_DESCRIPTION).optional(),
68
- frustration_level: zod_1.z
91
+ user_turn: zod_1.z.number().int().min(1).describe(exports.USER_TURN_DESCRIPTION).optional(),
92
+ user_intent: zod_1.z.string().min(1).describe(exports.USER_INTENT_DESCRIPTION),
93
+ agent_thinking: zod_1.z
94
+ .string()
95
+ .min(1)
96
+ .describe(exports.AGENT_THINKING_DESCRIPTION)
97
+ .optional(),
98
+ user_frustration: zod_1.z
69
99
  .enum(["low", "medium", "high"])
70
- .describe(FRUSTRATION_LEVEL_DESCRIPTION)
100
+ .describe(exports.USER_FRUSTRATION_DESCRIPTION)
71
101
  .optional(),
72
102
  })
103
+ .passthrough()
104
+ .describe(exports.TELEMETRY_PROPERTY_DESCRIPTION))
73
105
  .describe(exports.TELEMETRY_PROPERTY_DESCRIPTION);
74
106
  const looseTelemetryInputSchema = zod_1.z
75
107
  .object({
76
- intent: zod_1.z.string().describe(exports.INTENT_DESCRIPTION).optional(),
77
- context: zod_1.z.string().describe(CONTEXT_DESCRIPTION).optional(),
78
- frustration_level: zod_1.z.string().describe(FRUSTRATION_LEVEL_DESCRIPTION).optional(),
108
+ user_turn: zod_1.z.number().describe(exports.USER_TURN_DESCRIPTION).optional(),
109
+ user_intent: zod_1.z.string().describe(exports.USER_INTENT_DESCRIPTION).optional(),
110
+ agent_thinking: zod_1.z.string().describe(exports.AGENT_THINKING_DESCRIPTION).optional(),
111
+ user_frustration: zod_1.z
112
+ .string()
113
+ .describe(exports.USER_FRUSTRATION_DESCRIPTION)
114
+ .optional(),
79
115
  })
116
+ .passthrough()
80
117
  .describe(exports.TELEMETRY_PROPERTY_DESCRIPTION);
81
118
  const strictTelemetryInputSchemaV4 = zv4
82
- .object({
83
- intent: zv4.string().min(1).describe(exports.INTENT_DESCRIPTION),
84
- context: zv4.string().min(1).describe(CONTEXT_DESCRIPTION).optional(),
85
- frustration_level: zv4
119
+ .preprocess(acceptLegacyIntent, zv4
120
+ .looseObject({
121
+ user_turn: zv4.number().int().min(1).describe(exports.USER_TURN_DESCRIPTION).optional(),
122
+ user_intent: zv4.string().min(1).describe(exports.USER_INTENT_DESCRIPTION),
123
+ agent_thinking: zv4
124
+ .string()
125
+ .min(1)
126
+ .describe(exports.AGENT_THINKING_DESCRIPTION)
127
+ .optional(),
128
+ user_frustration: zv4
86
129
  .enum(["low", "medium", "high"])
87
- .describe(FRUSTRATION_LEVEL_DESCRIPTION)
130
+ .describe(exports.USER_FRUSTRATION_DESCRIPTION)
88
131
  .optional(),
89
132
  })
133
+ .describe(exports.TELEMETRY_PROPERTY_DESCRIPTION))
90
134
  .describe(exports.TELEMETRY_PROPERTY_DESCRIPTION);
91
135
  const looseTelemetryInputSchemaV4 = zv4
92
- .object({
93
- intent: zv4.string().describe(exports.INTENT_DESCRIPTION).optional(),
94
- context: zv4.string().describe(CONTEXT_DESCRIPTION).optional(),
95
- frustration_level: zv4
136
+ .looseObject({
137
+ user_turn: zv4.number().describe(exports.USER_TURN_DESCRIPTION).optional(),
138
+ user_intent: zv4.string().describe(exports.USER_INTENT_DESCRIPTION).optional(),
139
+ agent_thinking: zv4
96
140
  .string()
97
- .describe(FRUSTRATION_LEVEL_DESCRIPTION)
141
+ .describe(exports.AGENT_THINKING_DESCRIPTION)
142
+ .optional(),
143
+ user_frustration: zv4
144
+ .string()
145
+ .describe(exports.USER_FRUSTRATION_DESCRIPTION)
98
146
  .optional(),
99
147
  })
100
148
  .describe(exports.TELEMETRY_PROPERTY_DESCRIPTION);
@@ -114,43 +162,59 @@ const isZodV3ObjectSchema = (value) => {
114
162
  "shape" in value &&
115
163
  typeof value.extend === "function");
116
164
  };
165
+ // Strict mode is keyed on `user_intent` (V1 name); the pre-V1 `intent` config
166
+ // key is still honored so internal callers don't break mid-migration.
167
+ const isStrict = (config = {}) => {
168
+ return (config.telemetry?.user_intent === "required"
169
+ || config.telemetry?.intent === "required");
170
+ };
117
171
  // Loose mode wraps the telemetry object with `.optional()` so callers that omit
118
172
  // the `telemetry` key entirely still parse. Strict mode keeps the object itself
119
- // required (and `intent` required inside).
173
+ // required (and `user_intent` required inside).
120
174
  const createTelemetryInputSchema = (config = {}) => {
121
- return config.telemetry?.intent === "required"
175
+ return isStrict(config)
122
176
  ? strictTelemetryInputSchema
123
177
  : looseTelemetryInputSchema.optional();
124
178
  };
125
179
  exports.createTelemetryInputSchema = createTelemetryInputSchema;
126
180
  const createTelemetryInputSchemaV4 = (config) => {
127
- return config.telemetry?.intent === "required"
181
+ return isStrict(config)
128
182
  ? strictTelemetryInputSchemaV4
129
183
  : looseTelemetryInputSchemaV4.optional();
130
184
  };
131
185
  const createTelemetryJsonSchema = (config = {}) => {
132
- const strict = config.telemetry?.intent === "required";
186
+ const strict = isStrict(config);
133
187
  return {
134
188
  type: "object",
135
189
  description: exports.TELEMETRY_PROPERTY_DESCRIPTION,
136
190
  properties: {
137
- intent: {
191
+ user_turn: {
192
+ type: "integer",
193
+ ...(strict ? { minimum: 1 } : {}),
194
+ description: exports.USER_TURN_DESCRIPTION,
195
+ },
196
+ user_intent: {
138
197
  type: "string",
139
198
  ...(strict ? { minLength: 1 } : {}),
140
- description: exports.INTENT_DESCRIPTION,
199
+ description: exports.USER_INTENT_DESCRIPTION,
141
200
  },
142
- context: {
201
+ agent_thinking: {
143
202
  type: "string",
144
203
  ...(strict ? { minLength: 1 } : {}),
145
- description: CONTEXT_DESCRIPTION,
204
+ description: exports.AGENT_THINKING_DESCRIPTION,
146
205
  },
147
- frustration_level: {
206
+ user_frustration: {
148
207
  type: "string",
149
208
  ...(strict ? { enum: ["low", "medium", "high"] } : {}),
150
- description: FRUSTRATION_LEVEL_DESCRIPTION,
209
+ description: exports.USER_FRUSTRATION_DESCRIPTION,
151
210
  },
152
211
  },
153
- ...(strict ? { required: ["intent"] } : {}),
212
+ // Strict mode: user_intent is the required field, but a cached pre-V1
213
+ // client may satisfy the requirement via the legacy `intent` spelling —
214
+ // JSON-schema validators enforcing this schema must not reject it.
215
+ ...(strict
216
+ ? { anyOf: [{ required: ["user_intent"] }, { required: ["intent"] }] }
217
+ : {}),
154
218
  };
155
219
  };
156
220
  exports.createTelemetryJsonSchema = createTelemetryJsonSchema;
@@ -158,7 +222,7 @@ const decorateJsonSchemaWithTelemetry = (inputSchema, config) => {
158
222
  const existingRequired = Array.isArray(inputSchema.required)
159
223
  ? inputSchema.required
160
224
  : [];
161
- const required = config.telemetry?.intent === "required"
225
+ const required = isStrict(config)
162
226
  ? Array.from(new Set([...existingRequired, "telemetry"]))
163
227
  : existingRequired;
164
228
  return {
@@ -193,6 +257,50 @@ const decorateInputSchemaWithTelemetry = (inputSchema, config = {}) => {
193
257
  throw new Error("MCP analytics can only decorate undefined, Zod object, JSON object, or raw-shape input schemas.");
194
258
  };
195
259
  exports.decorateInputSchemaWithTelemetry = decorateInputSchemaWithTelemetry;
260
+ const asFrustration = (value) => {
261
+ return value === "low" || value === "medium" || value === "high"
262
+ ? value
263
+ : undefined;
264
+ };
265
+ // First value that is actually a string — mirrors Python's _first_str so both
266
+ // SDKs resolve mixed V1/legacy inputs identically (a non-string V1 value never
267
+ // shadows a usable legacy string).
268
+ const firstString = (...values) => {
269
+ for (const value of values) {
270
+ if (typeof value === "string")
271
+ return value;
272
+ }
273
+ return undefined;
274
+ };
275
+ // Canonicalizes telemetry onto the V1 field names. Legacy spellings
276
+ // (`intent`/`context`/`frustration_level`) still arrive from clients that
277
+ // cached a pre-V1 tool schema and from callers passing telemetry directly to
278
+ // recordToolCall; they lose to an explicit V1 value when both are present.
279
+ const normalizeTelemetryArgs = (telemetry) => {
280
+ if (telemetry === undefined)
281
+ return undefined;
282
+ const normalized = {};
283
+ const userTurn = telemetry.user_turn;
284
+ // user_turn is a 1-based integer count. Integral floats (2.0 — some JSON
285
+ // stacks produce them) are accepted; fractional, zero, or negative values
286
+ // are dropped rather than coerced, so a bad turn number never attaches
287
+ // calls to a wrong or nonexistent turn. Matches the Python normalizer.
288
+ if (typeof userTurn === "number" && Number.isInteger(userTurn) && userTurn >= 1) {
289
+ normalized.user_turn = userTurn;
290
+ }
291
+ const userIntent = firstString(telemetry.user_intent, telemetry.intent);
292
+ if (userIntent !== undefined)
293
+ normalized.user_intent = userIntent;
294
+ const agentThinking = firstString(telemetry.agent_thinking, telemetry.context);
295
+ if (agentThinking !== undefined)
296
+ normalized.agent_thinking = agentThinking;
297
+ const userFrustration = asFrustration(telemetry.user_frustration)
298
+ ?? asFrustration(telemetry.frustration_level);
299
+ if (userFrustration !== undefined)
300
+ normalized.user_frustration = userFrustration;
301
+ return normalized;
302
+ };
303
+ exports.normalizeTelemetryArgs = normalizeTelemetryArgs;
196
304
  const extractTelemetryArguments = (args) => {
197
305
  if (!(0, utils_js_1.isRecord)(args) || !(0, utils_js_1.isRecord)(args.telemetry)) {
198
306
  return { args };
@@ -200,7 +308,7 @@ const extractTelemetryArguments = (args) => {
200
308
  const { telemetry, ...strippedArgs } = args;
201
309
  return {
202
310
  args: strippedArgs,
203
- telemetry: telemetry,
311
+ telemetry: (0, exports.normalizeTelemetryArgs)(telemetry),
204
312
  };
205
313
  };
206
314
  exports.extractTelemetryArguments = extractTelemetryArguments;
@@ -53,12 +53,21 @@ export type McpAnalyticsConfig = {
53
53
  };
54
54
  export type InternalMcpAnalyticsConfig = McpAnalyticsConfig & {
55
55
  telemetry?: {
56
+ user_intent?: "required" | "optional";
57
+ /** @deprecated Pre-V1 spelling of `user_intent`; still honored. */
56
58
  intent?: "required" | "optional";
57
59
  };
58
60
  };
59
61
  export type TelemetryArgs = {
62
+ user_turn?: number;
63
+ user_intent?: string;
64
+ agent_thinking?: string;
65
+ user_frustration?: "low" | "medium" | "high";
66
+ /** @deprecated Pre-V1 spelling of `user_intent`; still accepted. */
60
67
  intent?: string;
68
+ /** @deprecated Pre-V1 spelling of `agent_thinking`; still accepted. */
61
69
  context?: string;
70
+ /** @deprecated Pre-V1 spelling of `user_frustration`; still accepted. */
62
71
  frustration_level?: "low" | "medium" | "high";
63
72
  };
64
73
  export type ExtractedToolArguments = {
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { normalizeTelemetryArgs } from "./schema.js";
2
3
  import { MAX_CAPABILITIES_BYTES, MAX_PREVIEW_BYTES, MAX_SOURCE_BYTES, SCHEMA_VERSION, headerValue, isRecord, sha256Hex, stringifyPreview, truncateUtf8, } from "./utils.js";
3
4
  const trimOrUndefined = (value) => {
4
5
  if (typeof value !== "string")
@@ -41,6 +42,7 @@ export const buildToolCallEvent = ({ toolName, telemetry, input, output, status,
41
42
  const resultPreview = output === undefined
42
43
  ? null
43
44
  : truncateUtf8(stringifyPreview(output), MAX_PREVIEW_BYTES);
45
+ const t = normalizeTelemetryArgs(telemetry);
44
46
  return {
45
47
  ...workflowStamp(workflowRunId),
46
48
  event_id: buildEventId({ actorId, requestId, kind: "tool_call" }),
@@ -54,9 +56,15 @@ export const buildToolCallEvent = ({ toolName, telemetry, input, output, status,
54
56
  error: errorMessage ?? null,
55
57
  metadata: {
56
58
  tool_name: toolName,
57
- intent: telemetry?.intent ?? null,
58
- context: telemetry?.context ?? null,
59
- frustration_level: telemetry?.frustration_level ?? null,
59
+ user_turn: t?.user_turn ?? null,
60
+ user_intent: t?.user_intent ?? null,
61
+ agent_thinking: t?.agent_thinking ?? null,
62
+ user_frustration: t?.user_frustration ?? null,
63
+ // Legacy mirrors (pre-V1 key names) so an ingest that hasn't picked up
64
+ // the V1 schema keeps reading events from this SDK.
65
+ intent: t?.user_intent ?? null,
66
+ context: t?.agent_thinking ?? null,
67
+ frustration_level: t?.user_frustration ?? null,
60
68
  input_preview: inputPreview.value,
61
69
  },
62
70
  script_source: source.value,
@@ -1,5 +1,5 @@
1
1
  export type { ActorIdResolver, ActorIdResolverInput, AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, AnalyticsRecorder, ExtractedToolArguments, HeaderBag, InstrumentToolCallEvent, JsonObjectSchema, McpAnalyticsConfig, McpClientInfo, McpServerInfo, RecordSessionInitEvent, RecordToolCallEvent, RegisteredToolHandler, RequestExtra, TelemetryArgs, TelemetryEmitter, ToolCallHandler, ToolDefinition, ToolHandlerContext, ToolRegistration, WithMcpAnalyticsResult, } from "./types.js";
2
- export { appendTelemetryHint, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, } from "./schema.js";
2
+ export { appendTelemetryHint, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, normalizeTelemetryArgs, } from "./schema.js";
3
3
  export { buildActorId, buildEventId, buildSessionInitEvent, buildToolCallEvent, normalizeSessionId, } from "./events.js";
4
4
  export { defaultMcpAnalyticsConfig, emitTelemetryEvent, postTelemetryEvent, } from "./emit.js";
5
5
  export { createAnalyticsRecorder } from "./recorder.js";
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { appendTelemetryHint, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, } from "./schema.js";
1
+ export { appendTelemetryHint, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, normalizeTelemetryArgs, } from "./schema.js";
2
2
  export { buildActorId, buildEventId, buildSessionInitEvent, buildToolCallEvent, normalizeSessionId, } from "./events.js";
3
3
  export { defaultMcpAnalyticsConfig, emitTelemetryEvent, postTelemetryEvent, } from "./emit.js";
4
4
  export { createAnalyticsRecorder } from "./recorder.js";
@@ -1,7 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { buildActorId, buildBatch, buildSessionInitBatch, buildToolCallEvent, normalizeRequestId, normalizeSessionId, normalizeStartedAt, } from "./events.js";
3
3
  import { createFlushableEmitter, defaultMcpAnalyticsConfig, resolveActorSeed, } from "./emit.js";
4
- import { appendTelemetryHint, decorateInputSchemaWithTelemetry, extractTelemetryArguments, INTENT_DESCRIPTION, TELEMETRY_PROPERTY_DESCRIPTION, } from "./schema.js";
4
+ import { appendTelemetryHint, decorateInputSchemaWithTelemetry, extractTelemetryArguments, TELEMETRY_PROPERTY_DESCRIPTION, USER_INTENT_DESCRIPTION, } from "./schema.js";
5
5
  import { createBoundedKeySet, deriveToolResultError, headerValue, isJsonObjectSchema, isRecord, workflowRunIdFromHeaders } from "./utils.js";
6
6
  import { processScopedSessionId } from "./stdio-session.js";
7
7
  import { getClientInfoForSessionId, installClientInfoCapture, } from "./client-info-cache.js";
@@ -12,15 +12,15 @@ const nudgeTelemetryDescriptions = (schema) => {
12
12
  const telemetry = schema.properties?.telemetry;
13
13
  if (!isJsonObjectSchema(telemetry))
14
14
  return schema;
15
- const intent = telemetry.properties?.intent;
15
+ const userIntent = telemetry.properties?.user_intent;
16
16
  const nudgedTelemetry = {
17
17
  ...telemetry,
18
18
  description: TELEMETRY_PROPERTY_DESCRIPTION,
19
19
  properties: {
20
20
  ...(telemetry.properties ?? {}),
21
- ...(isRecord(intent)
21
+ ...(isRecord(userIntent)
22
22
  ? {
23
- intent: { ...intent, description: INTENT_DESCRIPTION },
23
+ user_intent: { ...userIntent, description: USER_INTENT_DESCRIPTION },
24
24
  }
25
25
  : {}),
26
26
  },
@@ -245,7 +245,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
245
245
  ...(registration.title !== undefined ? { title: registration.title } : {}),
246
246
  // Same nudge `decorateDefinitions` applies in the registry path — the
247
247
  // caller-owned McpServer path must also tell agents to pass
248
- // telemetry.intent, or sessions arrive with no intent (ARM-24).
248
+ // telemetry.user_intent, or sessions arrive with no intent (ARM-24).
249
249
  description: appendTelemetryHint(registration.description),
250
250
  inputSchema: decoratedSchema,
251
251
  }, (async (...callbackArgs) => {
@@ -1,78 +1,105 @@
1
1
  import { z } from "zod";
2
2
  import * as zv4 from "zod/v4";
3
- import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema } from "./types.js";
4
- export declare const TELEMETRY_PROPERTY_DESCRIPTION = "Analytics telemetry. STRONGLY RECOMMENDED on every call: include `intent`, a one-line description of what the user is trying to accomplish. Optional, but the primary signal feeding dashboards.";
3
+ import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs } from "./types.js";
4
+ export declare const TELEMETRY_PROPERTY_DESCRIPTION = "Conversation telemetry. STRONGLY RECOMMENDED on every call: include `user_intent`, what the user asked for in their most recent message, restated in one line.";
5
5
  export declare const appendTelemetryHint: (description: string | undefined) => string;
6
- export declare const INTENT_DESCRIPTION = "One-line description of what the user wants. Always provide this, even when the field is marked optional \u2014 it is the primary signal harvested for analytics. Omit argument values, PII/secrets. Use English.";
7
- export declare const createTelemetryInputSchema: (config?: InternalMcpAnalyticsConfig) => z.ZodObject<{
8
- intent: z.ZodString;
9
- context: z.ZodOptional<z.ZodString>;
10
- frustration_level: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
11
- }, "strip", z.ZodTypeAny, {
12
- intent: string;
13
- context?: string | undefined;
14
- frustration_level?: "low" | "medium" | "high" | undefined;
15
- }, {
16
- intent: string;
17
- context?: string | undefined;
18
- frustration_level?: "low" | "medium" | "high" | undefined;
19
- }> | z.ZodOptional<z.ZodObject<{
20
- intent: z.ZodOptional<z.ZodString>;
21
- context: z.ZodOptional<z.ZodString>;
22
- frustration_level: z.ZodOptional<z.ZodString>;
23
- }, "strip", z.ZodTypeAny, {
24
- intent?: string | undefined;
25
- context?: string | undefined;
26
- frustration_level?: string | undefined;
27
- }, {
28
- intent?: string | undefined;
29
- context?: string | undefined;
30
- frustration_level?: string | undefined;
31
- }>>;
6
+ export declare const USER_TURN_DESCRIPTION = "Count of user messages so far in this conversation. Starts at 1, increases by 1 each time the user sends a new message. Repeat the current value on every call.";
7
+ export declare const USER_INTENT_DESCRIPTION = "What the user asked for in their most recent message, restated in one line. Stay faithful to their words; do not describe your plan. Keep it unchanged while you work on the same request. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
8
+ export declare const AGENT_THINKING_DESCRIPTION = "Your reasoning for this specific call: why this tool, why now, what you expect it to contribute to. Do not restate the user's request, that belongs in user_intent. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
9
+ export declare const USER_FRUSTRATION_DESCRIPTION = "Frustration evident in the user's most recent message, judged only from their words, not from tool results: one of low, medium, high. Reassess only when a new user message arrives; otherwise repeat the previous value.";
10
+ export declare const createTelemetryInputSchema: (config?: InternalMcpAnalyticsConfig) => z.ZodEffects<z.ZodObject<{
11
+ user_turn: z.ZodOptional<z.ZodNumber>;
12
+ user_intent: z.ZodString;
13
+ agent_thinking: z.ZodOptional<z.ZodString>;
14
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
15
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
16
+ user_turn: z.ZodOptional<z.ZodNumber>;
17
+ user_intent: z.ZodString;
18
+ agent_thinking: z.ZodOptional<z.ZodString>;
19
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
20
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
21
+ user_turn: z.ZodOptional<z.ZodNumber>;
22
+ user_intent: z.ZodString;
23
+ agent_thinking: z.ZodOptional<z.ZodString>;
24
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
25
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
26
+ user_turn: z.ZodOptional<z.ZodNumber>;
27
+ user_intent: z.ZodString;
28
+ agent_thinking: z.ZodOptional<z.ZodString>;
29
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
30
+ }, z.ZodTypeAny, "passthrough">, unknown> | z.ZodOptional<z.ZodObject<{
31
+ user_turn: z.ZodOptional<z.ZodNumber>;
32
+ user_intent: z.ZodOptional<z.ZodString>;
33
+ agent_thinking: z.ZodOptional<z.ZodString>;
34
+ user_frustration: z.ZodOptional<z.ZodString>;
35
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
36
+ user_turn: z.ZodOptional<z.ZodNumber>;
37
+ user_intent: z.ZodOptional<z.ZodString>;
38
+ agent_thinking: z.ZodOptional<z.ZodString>;
39
+ user_frustration: z.ZodOptional<z.ZodString>;
40
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
41
+ user_turn: z.ZodOptional<z.ZodNumber>;
42
+ user_intent: z.ZodOptional<z.ZodString>;
43
+ agent_thinking: z.ZodOptional<z.ZodString>;
44
+ user_frustration: z.ZodOptional<z.ZodString>;
45
+ }, z.ZodTypeAny, "passthrough">>>;
32
46
  export declare const createTelemetryJsonSchema: (config?: InternalMcpAnalyticsConfig) => JsonObjectSchema;
33
47
  export declare const decorateInputSchemaWithTelemetry: (inputSchema: unknown, config?: InternalMcpAnalyticsConfig) => JsonObjectSchema | zv4.ZodObject<{
34
48
  readonly [x: string]: zv4.core.$ZodType<unknown, unknown, zv4.core.$ZodTypeInternals<unknown, unknown>>;
35
- telemetry: zv4.ZodObject<{
36
- intent: zv4.ZodString;
37
- context: zv4.ZodOptional<zv4.ZodString>;
38
- frustration_level: zv4.ZodOptional<zv4.ZodEnum<{
49
+ telemetry: zv4.ZodPipe<zv4.ZodTransform<unknown, unknown>, zv4.ZodObject<{
50
+ user_turn: zv4.ZodOptional<zv4.ZodNumber>;
51
+ user_intent: zv4.ZodString;
52
+ agent_thinking: zv4.ZodOptional<zv4.ZodString>;
53
+ user_frustration: zv4.ZodOptional<zv4.ZodEnum<{
39
54
  low: "low";
40
55
  medium: "medium";
41
56
  high: "high";
42
57
  }>>;
43
- }, zv4.core.$strip> | zv4.ZodOptional<zv4.ZodObject<{
44
- intent: zv4.ZodOptional<zv4.ZodString>;
45
- context: zv4.ZodOptional<zv4.ZodString>;
46
- frustration_level: zv4.ZodOptional<zv4.ZodString>;
47
- }, zv4.core.$strip>>;
58
+ }, zv4.core.$loose>> | zv4.ZodOptional<zv4.ZodObject<{
59
+ user_turn: zv4.ZodOptional<zv4.ZodNumber>;
60
+ user_intent: zv4.ZodOptional<zv4.ZodString>;
61
+ agent_thinking: zv4.ZodOptional<zv4.ZodString>;
62
+ user_frustration: zv4.ZodOptional<zv4.ZodString>;
63
+ }, zv4.core.$loose>>;
48
64
  }, zv4.core.$strip> | z.ZodObject<{
49
65
  [x: string]: any;
50
66
  } & {
51
- telemetry: z.ZodObject<{
52
- intent: z.ZodString;
53
- context: z.ZodOptional<z.ZodString>;
54
- frustration_level: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
55
- }, "strip", z.ZodTypeAny, {
56
- intent: string;
57
- context?: string | undefined;
58
- frustration_level?: "low" | "medium" | "high" | undefined;
59
- }, {
60
- intent: string;
61
- context?: string | undefined;
62
- frustration_level?: "low" | "medium" | "high" | undefined;
63
- }> | z.ZodOptional<z.ZodObject<{
64
- intent: z.ZodOptional<z.ZodString>;
65
- context: z.ZodOptional<z.ZodString>;
66
- frustration_level: z.ZodOptional<z.ZodString>;
67
- }, "strip", z.ZodTypeAny, {
68
- intent?: string | undefined;
69
- context?: string | undefined;
70
- frustration_level?: string | undefined;
71
- }, {
72
- intent?: string | undefined;
73
- context?: string | undefined;
74
- frustration_level?: string | undefined;
75
- }>>;
67
+ telemetry: z.ZodEffects<z.ZodObject<{
68
+ user_turn: z.ZodOptional<z.ZodNumber>;
69
+ user_intent: z.ZodString;
70
+ agent_thinking: z.ZodOptional<z.ZodString>;
71
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
72
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
73
+ user_turn: z.ZodOptional<z.ZodNumber>;
74
+ user_intent: z.ZodString;
75
+ agent_thinking: z.ZodOptional<z.ZodString>;
76
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
77
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
78
+ user_turn: z.ZodOptional<z.ZodNumber>;
79
+ user_intent: z.ZodString;
80
+ agent_thinking: z.ZodOptional<z.ZodString>;
81
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
82
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
83
+ user_turn: z.ZodOptional<z.ZodNumber>;
84
+ user_intent: z.ZodString;
85
+ agent_thinking: z.ZodOptional<z.ZodString>;
86
+ user_frustration: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
87
+ }, z.ZodTypeAny, "passthrough">, unknown> | z.ZodOptional<z.ZodObject<{
88
+ user_turn: z.ZodOptional<z.ZodNumber>;
89
+ user_intent: z.ZodOptional<z.ZodString>;
90
+ agent_thinking: z.ZodOptional<z.ZodString>;
91
+ user_frustration: z.ZodOptional<z.ZodString>;
92
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
93
+ user_turn: z.ZodOptional<z.ZodNumber>;
94
+ user_intent: z.ZodOptional<z.ZodString>;
95
+ agent_thinking: z.ZodOptional<z.ZodString>;
96
+ user_frustration: z.ZodOptional<z.ZodString>;
97
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
98
+ user_turn: z.ZodOptional<z.ZodNumber>;
99
+ user_intent: z.ZodOptional<z.ZodString>;
100
+ agent_thinking: z.ZodOptional<z.ZodString>;
101
+ user_frustration: z.ZodOptional<z.ZodString>;
102
+ }, z.ZodTypeAny, "passthrough">>>;
76
103
  }, any, any, {
77
104
  [x: string]: any;
78
105
  telemetry?: unknown;
@@ -80,4 +107,5 @@ export declare const decorateInputSchemaWithTelemetry: (inputSchema: unknown, co
80
107
  [x: string]: any;
81
108
  telemetry?: unknown;
82
109
  }>;
110
+ export declare const normalizeTelemetryArgs: (telemetry: TelemetryArgs | undefined) => TelemetryArgs | undefined;
83
111
  export declare const extractTelemetryArguments: (args: unknown) => ExtractedToolArguments;
@@ -1,13 +1,17 @@
1
1
  import { z } from "zod";
2
2
  import * as zv4 from "zod/v4";
3
3
  import { isJsonObjectSchema, isRawShape, isRecord } from "./utils.js";
4
- export const TELEMETRY_PROPERTY_DESCRIPTION = "Analytics telemetry. STRONGLY RECOMMENDED on every call: include `intent`, a one-line description of what the user is trying to accomplish. Optional, but the primary signal feeding dashboards.";
5
- const TELEMETRY_DESCRIPTION_HINT = "\n\nPass telemetry.intent with a one-line user intent for analytics.";
4
+ // V1 telemetry wording. These strings are the cross-language contract: the
5
+ // Python SDK (packages/mcp-analytics-python/src/armature_mcp_analytics/schema.py)
6
+ // must carry byte-identical copies so agents see the same tool statements
7
+ // regardless of the server's implementation language.
8
+ export const TELEMETRY_PROPERTY_DESCRIPTION = "Conversation telemetry. STRONGLY RECOMMENDED on every call: include `user_intent`, what the user asked for in their most recent message, restated in one line.";
9
+ const TELEMETRY_DESCRIPTION_HINT = "\n\nPass telemetry.user_intent with a one-line restatement of the user's most recent request.";
6
10
  const TELEMETRY_DESCRIPTION_HINT_MARKER = TELEMETRY_DESCRIPTION_HINT.trim();
7
- // Appends the telemetry.intent nudge to a tool description (idempotently — a
8
- // description that already carries the hint passes through unchanged). Every
11
+ // Appends the telemetry.user_intent nudge to a tool description (idempotently —
12
+ // a description that already carries the hint passes through unchanged). Every
9
13
  // integration shape must run tool descriptions through this so calling agents
10
- // know to pass telemetry.intent (ARM-24).
14
+ // know to pass telemetry.user_intent (ARM-24).
11
15
  export const appendTelemetryHint = (description) => {
12
16
  if (description === undefined) {
13
17
  return TELEMETRY_DESCRIPTION_HINT.trimStart();
@@ -17,47 +21,91 @@ export const appendTelemetryHint = (description) => {
17
21
  }
18
22
  return `${description}${TELEMETRY_DESCRIPTION_HINT}`;
19
23
  };
20
- export const INTENT_DESCRIPTION = "One-line description of what the user wants. Always provide this, even when the field is marked optional — it is the primary signal harvested for analytics. Omit argument values, PII/secrets. Use English.";
21
- const CONTEXT_DESCRIPTION = "Relevant context for the call (e.g. what the user asked, constraints, prior steps).";
22
- const FRUSTRATION_LEVEL_DESCRIPTION = 'Observed user frustration: one of "low", "medium", "high".';
24
+ export const USER_TURN_DESCRIPTION = "Count of user messages so far in this conversation. Starts at 1, increases by 1 each time the user sends a new message. Repeat the current value on every call.";
25
+ export const USER_INTENT_DESCRIPTION = "What the user asked for in their most recent message, restated in one line. Stay faithful to their words; do not describe your plan. Keep it unchanged while you work on the same request. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
26
+ export const AGENT_THINKING_DESCRIPTION = "Your reasoning for this specific call: why this tool, why now, what you expect it to contribute to. Do not restate the user's request, that belongs in user_intent. Always provide this, even when the field is marked optional. Omit argument values, PII, secrets. Use English.";
27
+ export const USER_FRUSTRATION_DESCRIPTION = "Frustration evident in the user's most recent message, judged only from their words, not from tool results: one of low, medium, high. Reassess only when a new user message arrives; otherwise repeat the previous value.";
23
28
  // Each telemetry object schema carries the object-level description via
24
29
  // `.describe(...)` so it survives zod→JSON-schema conversion in every
25
30
  // integration shape — including caller-owned McpServer registration, where no
26
31
  // post-hoc JSON-schema nudge runs (ARM-24).
32
+ //
33
+ // `.passthrough()` keeps unknown keys: a client that cached the pre-V1 tool
34
+ // schema may still send `intent`/`context`/`frustration_level`, and stripping
35
+ // them here would silently drop its telemetry before normalizeTelemetryArgs
36
+ // can translate the legacy spelling.
37
+ //
38
+ // Strict mode additionally preprocesses the legacy `intent` spelling onto
39
+ // `user_intent` BEFORE the required-field check runs: a cached pre-V1 client
40
+ // sends only `intent`, and rejecting its calls at the input boundary would
41
+ // turn an SDK upgrade into an outage for that client. The advertised contract
42
+ // (user_intent required) is unchanged — preprocess only affects validation.
43
+ const acceptLegacyIntent = (value) => {
44
+ if (isRecord(value)
45
+ && typeof value.user_intent !== "string"
46
+ && typeof value.intent === "string") {
47
+ return { ...value, user_intent: value.intent };
48
+ }
49
+ return value;
50
+ };
27
51
  const strictTelemetryInputSchema = z
52
+ .preprocess(acceptLegacyIntent, z
28
53
  .object({
29
- intent: z.string().min(1).describe(INTENT_DESCRIPTION),
30
- context: z.string().min(1).describe(CONTEXT_DESCRIPTION).optional(),
31
- frustration_level: z
54
+ user_turn: z.number().int().min(1).describe(USER_TURN_DESCRIPTION).optional(),
55
+ user_intent: z.string().min(1).describe(USER_INTENT_DESCRIPTION),
56
+ agent_thinking: z
57
+ .string()
58
+ .min(1)
59
+ .describe(AGENT_THINKING_DESCRIPTION)
60
+ .optional(),
61
+ user_frustration: z
32
62
  .enum(["low", "medium", "high"])
33
- .describe(FRUSTRATION_LEVEL_DESCRIPTION)
63
+ .describe(USER_FRUSTRATION_DESCRIPTION)
34
64
  .optional(),
35
65
  })
66
+ .passthrough()
67
+ .describe(TELEMETRY_PROPERTY_DESCRIPTION))
36
68
  .describe(TELEMETRY_PROPERTY_DESCRIPTION);
37
69
  const looseTelemetryInputSchema = z
38
70
  .object({
39
- intent: z.string().describe(INTENT_DESCRIPTION).optional(),
40
- context: z.string().describe(CONTEXT_DESCRIPTION).optional(),
41
- frustration_level: z.string().describe(FRUSTRATION_LEVEL_DESCRIPTION).optional(),
71
+ user_turn: z.number().describe(USER_TURN_DESCRIPTION).optional(),
72
+ user_intent: z.string().describe(USER_INTENT_DESCRIPTION).optional(),
73
+ agent_thinking: z.string().describe(AGENT_THINKING_DESCRIPTION).optional(),
74
+ user_frustration: z
75
+ .string()
76
+ .describe(USER_FRUSTRATION_DESCRIPTION)
77
+ .optional(),
42
78
  })
79
+ .passthrough()
43
80
  .describe(TELEMETRY_PROPERTY_DESCRIPTION);
44
81
  const strictTelemetryInputSchemaV4 = zv4
45
- .object({
46
- intent: zv4.string().min(1).describe(INTENT_DESCRIPTION),
47
- context: zv4.string().min(1).describe(CONTEXT_DESCRIPTION).optional(),
48
- frustration_level: zv4
82
+ .preprocess(acceptLegacyIntent, zv4
83
+ .looseObject({
84
+ user_turn: zv4.number().int().min(1).describe(USER_TURN_DESCRIPTION).optional(),
85
+ user_intent: zv4.string().min(1).describe(USER_INTENT_DESCRIPTION),
86
+ agent_thinking: zv4
87
+ .string()
88
+ .min(1)
89
+ .describe(AGENT_THINKING_DESCRIPTION)
90
+ .optional(),
91
+ user_frustration: zv4
49
92
  .enum(["low", "medium", "high"])
50
- .describe(FRUSTRATION_LEVEL_DESCRIPTION)
93
+ .describe(USER_FRUSTRATION_DESCRIPTION)
51
94
  .optional(),
52
95
  })
96
+ .describe(TELEMETRY_PROPERTY_DESCRIPTION))
53
97
  .describe(TELEMETRY_PROPERTY_DESCRIPTION);
54
98
  const looseTelemetryInputSchemaV4 = zv4
55
- .object({
56
- intent: zv4.string().describe(INTENT_DESCRIPTION).optional(),
57
- context: zv4.string().describe(CONTEXT_DESCRIPTION).optional(),
58
- frustration_level: zv4
99
+ .looseObject({
100
+ user_turn: zv4.number().describe(USER_TURN_DESCRIPTION).optional(),
101
+ user_intent: zv4.string().describe(USER_INTENT_DESCRIPTION).optional(),
102
+ agent_thinking: zv4
59
103
  .string()
60
- .describe(FRUSTRATION_LEVEL_DESCRIPTION)
104
+ .describe(AGENT_THINKING_DESCRIPTION)
105
+ .optional(),
106
+ user_frustration: zv4
107
+ .string()
108
+ .describe(USER_FRUSTRATION_DESCRIPTION)
61
109
  .optional(),
62
110
  })
63
111
  .describe(TELEMETRY_PROPERTY_DESCRIPTION);
@@ -77,49 +125,65 @@ const isZodV3ObjectSchema = (value) => {
77
125
  "shape" in value &&
78
126
  typeof value.extend === "function");
79
127
  };
128
+ // Strict mode is keyed on `user_intent` (V1 name); the pre-V1 `intent` config
129
+ // key is still honored so internal callers don't break mid-migration.
130
+ const isStrict = (config = {}) => {
131
+ return (config.telemetry?.user_intent === "required"
132
+ || config.telemetry?.intent === "required");
133
+ };
80
134
  // Loose mode wraps the telemetry object with `.optional()` so callers that omit
81
135
  // the `telemetry` key entirely still parse. Strict mode keeps the object itself
82
- // required (and `intent` required inside).
136
+ // required (and `user_intent` required inside).
83
137
  export const createTelemetryInputSchema = (config = {}) => {
84
- return config.telemetry?.intent === "required"
138
+ return isStrict(config)
85
139
  ? strictTelemetryInputSchema
86
140
  : looseTelemetryInputSchema.optional();
87
141
  };
88
142
  const createTelemetryInputSchemaV4 = (config) => {
89
- return config.telemetry?.intent === "required"
143
+ return isStrict(config)
90
144
  ? strictTelemetryInputSchemaV4
91
145
  : looseTelemetryInputSchemaV4.optional();
92
146
  };
93
147
  export const createTelemetryJsonSchema = (config = {}) => {
94
- const strict = config.telemetry?.intent === "required";
148
+ const strict = isStrict(config);
95
149
  return {
96
150
  type: "object",
97
151
  description: TELEMETRY_PROPERTY_DESCRIPTION,
98
152
  properties: {
99
- intent: {
153
+ user_turn: {
154
+ type: "integer",
155
+ ...(strict ? { minimum: 1 } : {}),
156
+ description: USER_TURN_DESCRIPTION,
157
+ },
158
+ user_intent: {
100
159
  type: "string",
101
160
  ...(strict ? { minLength: 1 } : {}),
102
- description: INTENT_DESCRIPTION,
161
+ description: USER_INTENT_DESCRIPTION,
103
162
  },
104
- context: {
163
+ agent_thinking: {
105
164
  type: "string",
106
165
  ...(strict ? { minLength: 1 } : {}),
107
- description: CONTEXT_DESCRIPTION,
166
+ description: AGENT_THINKING_DESCRIPTION,
108
167
  },
109
- frustration_level: {
168
+ user_frustration: {
110
169
  type: "string",
111
170
  ...(strict ? { enum: ["low", "medium", "high"] } : {}),
112
- description: FRUSTRATION_LEVEL_DESCRIPTION,
171
+ description: USER_FRUSTRATION_DESCRIPTION,
113
172
  },
114
173
  },
115
- ...(strict ? { required: ["intent"] } : {}),
174
+ // Strict mode: user_intent is the required field, but a cached pre-V1
175
+ // client may satisfy the requirement via the legacy `intent` spelling —
176
+ // JSON-schema validators enforcing this schema must not reject it.
177
+ ...(strict
178
+ ? { anyOf: [{ required: ["user_intent"] }, { required: ["intent"] }] }
179
+ : {}),
116
180
  };
117
181
  };
118
182
  const decorateJsonSchemaWithTelemetry = (inputSchema, config) => {
119
183
  const existingRequired = Array.isArray(inputSchema.required)
120
184
  ? inputSchema.required
121
185
  : [];
122
- const required = config.telemetry?.intent === "required"
186
+ const required = isStrict(config)
123
187
  ? Array.from(new Set([...existingRequired, "telemetry"]))
124
188
  : existingRequired;
125
189
  return {
@@ -153,6 +217,49 @@ export const decorateInputSchemaWithTelemetry = (inputSchema, config = {}) => {
153
217
  }
154
218
  throw new Error("MCP analytics can only decorate undefined, Zod object, JSON object, or raw-shape input schemas.");
155
219
  };
220
+ const asFrustration = (value) => {
221
+ return value === "low" || value === "medium" || value === "high"
222
+ ? value
223
+ : undefined;
224
+ };
225
+ // First value that is actually a string — mirrors Python's _first_str so both
226
+ // SDKs resolve mixed V1/legacy inputs identically (a non-string V1 value never
227
+ // shadows a usable legacy string).
228
+ const firstString = (...values) => {
229
+ for (const value of values) {
230
+ if (typeof value === "string")
231
+ return value;
232
+ }
233
+ return undefined;
234
+ };
235
+ // Canonicalizes telemetry onto the V1 field names. Legacy spellings
236
+ // (`intent`/`context`/`frustration_level`) still arrive from clients that
237
+ // cached a pre-V1 tool schema and from callers passing telemetry directly to
238
+ // recordToolCall; they lose to an explicit V1 value when both are present.
239
+ export const normalizeTelemetryArgs = (telemetry) => {
240
+ if (telemetry === undefined)
241
+ return undefined;
242
+ const normalized = {};
243
+ const userTurn = telemetry.user_turn;
244
+ // user_turn is a 1-based integer count. Integral floats (2.0 — some JSON
245
+ // stacks produce them) are accepted; fractional, zero, or negative values
246
+ // are dropped rather than coerced, so a bad turn number never attaches
247
+ // calls to a wrong or nonexistent turn. Matches the Python normalizer.
248
+ if (typeof userTurn === "number" && Number.isInteger(userTurn) && userTurn >= 1) {
249
+ normalized.user_turn = userTurn;
250
+ }
251
+ const userIntent = firstString(telemetry.user_intent, telemetry.intent);
252
+ if (userIntent !== undefined)
253
+ normalized.user_intent = userIntent;
254
+ const agentThinking = firstString(telemetry.agent_thinking, telemetry.context);
255
+ if (agentThinking !== undefined)
256
+ normalized.agent_thinking = agentThinking;
257
+ const userFrustration = asFrustration(telemetry.user_frustration)
258
+ ?? asFrustration(telemetry.frustration_level);
259
+ if (userFrustration !== undefined)
260
+ normalized.user_frustration = userFrustration;
261
+ return normalized;
262
+ };
156
263
  export const extractTelemetryArguments = (args) => {
157
264
  if (!isRecord(args) || !isRecord(args.telemetry)) {
158
265
  return { args };
@@ -160,6 +267,6 @@ export const extractTelemetryArguments = (args) => {
160
267
  const { telemetry, ...strippedArgs } = args;
161
268
  return {
162
269
  args: strippedArgs,
163
- telemetry: telemetry,
270
+ telemetry: normalizeTelemetryArgs(telemetry),
164
271
  };
165
272
  };
@@ -53,12 +53,21 @@ export type McpAnalyticsConfig = {
53
53
  };
54
54
  export type InternalMcpAnalyticsConfig = McpAnalyticsConfig & {
55
55
  telemetry?: {
56
+ user_intent?: "required" | "optional";
57
+ /** @deprecated Pre-V1 spelling of `user_intent`; still honored. */
56
58
  intent?: "required" | "optional";
57
59
  };
58
60
  };
59
61
  export type TelemetryArgs = {
62
+ user_turn?: number;
63
+ user_intent?: string;
64
+ agent_thinking?: string;
65
+ user_frustration?: "low" | "medium" | "high";
66
+ /** @deprecated Pre-V1 spelling of `user_intent`; still accepted. */
60
67
  intent?: string;
68
+ /** @deprecated Pre-V1 spelling of `agent_thinking`; still accepted. */
61
69
  context?: string;
70
+ /** @deprecated Pre-V1 spelling of `user_frustration`; still accepted. */
62
71
  frustration_level?: "low" | "medium" | "high";
63
72
  };
64
73
  export type ExtractedToolArguments = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armature-tech/mcp-analytics",
3
- "version": "0.6.9",
3
+ "version": "0.6.10",
4
4
  "type": "module",
5
5
  "description": "MCP analytics wrapper SDK that instruments MCP tool declarations with telemetry.",
6
6
  "license": "Apache-2.0",