@armature-tech/mcp-analytics 0.6.37 → 0.6.38

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
@@ -79,7 +79,7 @@ const server = createMcpAnalyticsServer(createMyMcpServer);
79
79
 
80
80
  | Understand demand | Find what breaks | Improve with context |
81
81
  | --- | --- | --- |
82
- | See which tools and use cases people actually need. | Surface failures, retries, latency, and dead ends. | Connect every call to user intent and agent reasoning. |
82
+ | See which tools and use cases people actually need. | Surface failures, retries, latency, and dead ends. | Connect every call to user intent and declared call purpose. |
83
83
 
84
84
  No custom event schema. No logging pipeline. No changes to your tool handlers.
85
85
 
@@ -97,7 +97,7 @@ No custom event schema. No logging pipeline. No changes to your tool handlers.
97
97
  Armature instruments the boundary around every tool call:
98
98
 
99
99
  1. The SDK adds an optional **telemetry** block to the tool’s input schema.
100
- 2. The agent can attach user intent, reasoning, and frustration to the call.
100
+ 2. The agent can attach user intent, call purpose, and expressed frustration to the call.
101
101
  3. The SDK removes telemetry before your handler receives the arguments.
102
102
  4. Timing, outcome, and truncated previews are sent to your dashboard.
103
103
 
@@ -105,13 +105,25 @@ Armature instruments the boundary around every tool call:
105
105
  {
106
106
  "telemetry": {
107
107
  "user_intent": "Check whether the customer's last payment succeeded",
108
- "agent_thinking": "The payment lookup tool provides the requested status",
108
+ "call_purpose": "The payment lookup tool provides the requested status",
109
109
  "user_frustration": "low"
110
110
  }
111
111
  }
112
112
  ~~~
113
113
 
114
- All telemetry fields are optional. Send **agent_thinking** on every call; send **user_intent** and **user_frustration** only on the first call after each new user message. Their absence on later calls means the same turn continues. The earlier **intent**, **context**, and **frustration_level** names remain accepted, while cached **user_turn** values are ignored.
114
+ All telemetry fields are optional. Include **call_purpose** with a short public
115
+ description of the action. Send **user_intent** and **user_frustration** only
116
+ on the first call after each new user message. Their absence on later calls
117
+ means the same turn continues.
118
+
119
+ The earlier **agent_thinking**, **intent**, **context**, and
120
+ **frustration_level** names remain accepted. Cached **user_turn** values are
121
+ ignored. **call_purpose** takes precedence over **agent_thinking** and
122
+ **context**, including an explicit empty string. It describes the visible
123
+ action and its relation to the stated goal.
124
+
125
+ The SDK stores its sanitized value under **agent_thinking** and **context**
126
+ for compatibility. Existing redaction hooks and readers keep working.
115
127
 
116
128
  > **Privacy:** Armature is observability, not authentication. Keep your existing MCP authentication and authorization in place. Do not put secrets in tool arguments or telemetry fields.
117
129
 
@@ -218,7 +230,7 @@ Honest limitations, dictated by what fastmcp exposes to `execute`:
218
230
  - **Tool schemas are not decorated by default** with the optional `telemetry` block (fastmcp validates opaque Standard Schema objects before `execute`, advertising `additionalProperties: false`), so agent-supplied conversation telemetry generally cannot arrive unless you opt in with `declareTelemetry: true` (below). If a `telemetry` argument does reach `execute` (for example a passthrough Zod object), it is stripped and exported per the usual contract, and a schema that declares its own top-level `telemetry` field keeps owning it.
219
231
  - `tool.timeoutMs` races outside `execute`: on timeout fastmcp answers with its own error result while the analytics event records the real handler outcome and duration.
220
232
 
221
- **`declareTelemetry: true`** (in the same options object) restores v1 parity for telemetry schema advertisement, matching the `/v2` adapter option of the same name: each instrumented tool's **advertised** input schema gains the optional `telemetry` property (byte-identical descriptions to the v1 integration) and the same description nudge, so fresh-schema clients are told to send `telemetry.user_intent` / `telemetry.agent_thinking`. Because fastmcp regenerates the advertised schema from the `parameters` Standard Schema it holds privately, decoration happens on the tool definition's `parameters` before `addTool` — Zod object parameters are extended with the telemetry field (fastmcp's own pre-execute validation then keeps it), and `jsonSchemaAdapter` parameters are re-wrapped so the advertised JSON declares `telemetry` and validation accepts it while delegating everything else to your original validator. The wrapper then strips the argument before `execute` and exports it (armature-owned, never customer-owned — ownership is resolved against the original schema before decoration).
233
+ **`declareTelemetry: true`** (in the same options object) restores v1 parity for telemetry schema advertisement, matching the `/v2` adapter option of the same name: each instrumented tool's **advertised** input schema gains the optional `telemetry` property (byte-identical descriptions to the v1 integration) and the same description nudge, so fresh-schema clients are told to send `telemetry.user_intent` / `telemetry.call_purpose`. Because fastmcp regenerates the advertised schema from the `parameters` Standard Schema it holds privately, decoration happens on the tool definition's `parameters` before `addTool` — Zod object parameters are extended with the telemetry field (fastmcp's own pre-execute validation then keeps it), and `jsonSchemaAdapter` parameters are re-wrapped so the advertised JSON declares `telemetry` and validation accepts it while delegating everything else to your original validator. The wrapper then strips the argument before `execute` and exports it (armature-owned, never customer-owned — ownership is resolved against the original schema before decoration).
222
234
 
223
235
  ~~~ts
224
236
  server.addTool(withFastmcpAnalytics(tool, { ...analyticsOptions, declareTelemetry: true }));
@@ -344,7 +356,7 @@ instrumentedFactory(buildServer, analyticsConfig, {
344
356
  });
345
357
  ~~~
346
358
 
347
- **`declareTelemetry: true`** restores v1 parity for telemetry schema advertisement (superseding the default no-decoration behavior described above): each instrumented tool's **advertised** input schema gains the optional `telemetry` property (byte-identical descriptions to the v1 integration) and the same description nudge, so fresh-schema v2 clients are told to send `telemetry.user_intent` / `telemetry.agent_thinking`. Mechanism: the adapter reads the SDK's own JSON conversion of the tool's schema (`toolInputSchemaJson` — works for any Standard Schema vendor: zod v4, arktype, valibot, `fromJsonSchema`), adds the telemetry property to that JSON, wraps it with `fromJsonSchema`, and swaps it in through `RegisteredTool.update({ paramsSchema })`. Because the SDK validates arguments against the registered schema *before* the analytics wrapper runs, this is what makes a sent `telemetry` argument pass validation; the wrapper then strips it from the customer arguments and exports it (armature-owned, never customer-owned — ownership is resolved against the original schema before decoration).
359
+ **`declareTelemetry: true`** restores v1 parity for telemetry schema advertisement (superseding the default no-decoration behavior described above): each instrumented tool's **advertised** input schema gains the optional `telemetry` property (byte-identical descriptions to the v1 integration) and the same description nudge, so fresh-schema v2 clients are told to send `telemetry.user_intent` / `telemetry.call_purpose`. Mechanism: the adapter reads the SDK's own JSON conversion of the tool's schema (`toolInputSchemaJson` — works for any Standard Schema vendor: zod v4, arktype, valibot, `fromJsonSchema`), adds the telemetry property to that JSON, wraps it with `fromJsonSchema`, and swaps it in through `RegisteredTool.update({ paramsSchema })`. Because the SDK validates arguments against the registered schema *before* the analytics wrapper runs, this is what makes a sent `telemetry` argument pass validation; the wrapper then strips it from the customer arguments and exports it (armature-owned, never customer-owned — ownership is resolved against the original schema before decoration).
348
360
 
349
361
  - A top-level `additionalProperties: false` in your schema is preserved: `telemetry` becomes a *declared* property (so it validates), while every other undeclared key is still rejected exactly as before.
350
362
  - Tradeoff (why this is opt-in): validation then runs against the JSON Schema projection of your schema, via the SDK's Ajv validator. Zod runtime effects that don't survive that projection — `.transform()`, `.refine()`, applied `.default()` values — no longer run inside the SDK's validation step. If your tools rely on those, leave `declareTelemetry` off (a telemetry argument sent by a client is still stripped and exported).
@@ -391,7 +403,7 @@ type McpAnalyticsConfig = {
391
403
  redact?: (value: unknown) => unknown;
392
404
  redactEvent?: (event) => typeof event | null | Promise<typeof event | null>;
393
405
  schedule?: (work: Promise<void>) => void;
394
- telemetryFieldMap?: { user_intent?: string; agent_thinking?: string; user_frustration?: string };
406
+ telemetryFieldMap?: { user_intent?: string; call_purpose?: string; user_frustration?: string };
395
407
  requestCapability?: boolean;
396
408
  };
397
409
  };
@@ -437,6 +449,13 @@ reserved: rename a customer-defined tool with the same name first. When it is on
437
449
  merely by default, a customer tool of the same name takes precedence and the SDK
438
450
  skips its own injection instead of failing.
439
451
 
452
+ While the tool is exposed, the telemetry hint appended to every instrumented
453
+ tool description also tells agents to call `request_capability` when no tool
454
+ can do what the user asks. The SDK never pushes a description past 1024
455
+ characters (UTF-8 bytes): if the full hint does not fit, it appends only the
456
+ telemetry sentence, and if that does not fit either, it leaves the description
457
+ unchanged and logs a warning.
458
+
440
459
  ```mermaid
441
460
  sequenceDiagram
442
461
  participant App
@@ -469,7 +488,7 @@ sequenceDiagram
469
488
 
470
489
  ### Telemetry capture and privacy
471
490
 
472
- The SDK injects an optional `telemetry` object (`user_intent`, `agent_thinking`, `user_frustration`) into each wrapped tool's input schema. This is conversation-derived data: if your deployment cannot disclose it — for example in a privacy policy required for an app-store submission — set **captureTelemetry: false**. With capture off, tool schemas and descriptions pass through completely untouched, and telemetry sent by clients holding an older cached schema is stripped and never delivered anywhere (ingest, `emit`, or `onError`). Tool-call and session analytics keep working without the conversational fields.
491
+ The SDK injects an optional `telemetry` object (`user_intent`, `call_purpose`, `user_frustration`) into each wrapped tool's input schema. This is conversation-derived data: if your deployment cannot disclose it — for example in a privacy policy required for an app-store submission — set **captureTelemetry: false**. With capture off, tool schemas and descriptions pass through completely untouched, and telemetry sent by clients holding an older cached schema is stripped and never delivered anywhere (ingest, `emit`, or `onError`). Tool-call and session analytics keep working without the conversational fields.
473
492
 
474
493
  Disclosure summary for privacy policies: with capture **on**, the SDK collects tool names, tool call inputs/outputs (size-capped previews), error messages, timing, a one-way hash of the actor seed, the verbatim `actorIdentifier` when configured, client name/version, and the agent-supplied `telemetry` fields above; recipients are your Armature workspace. With capture **off**, the `telemetry` fields are not collected.
475
494
 
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 `user_intent`, `agent_thinking`, `user_frustration`), strips those fields before the
17
+ agent can pass `user_intent`, `call_purpose`, `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.
@@ -10,8 +10,11 @@ const emit_js_1 = require("./emit.js");
10
10
  const request_capability_js_1 = require("./request-capability.js");
11
11
  const DEFAULT_INGEST_URL = "https://app.armature.tech/api/mcp-analytics/ingest";
12
12
  const DEFAULT_TIMEOUT_MS = 10_000;
13
- const CURRENT_TELEMETRY_MARKER = "Conversation telemetry.";
13
+ const CURRENT_TELEMETRY_MARKER = "Optional task context for usage analytics";
14
14
  const LEGACY_TELEMETRY_MARKERS = [
15
+ "Pass telemetry.agent_thinking",
16
+ "On every call, pass telemetry.agent_thinking",
17
+ "Conversation telemetry.",
15
18
  "Pass telemetry.user_intent",
16
19
  "Pass telemetry.intent",
17
20
  ];
@@ -166,12 +169,13 @@ const classifyToolInstrumentation = (tool) => {
166
169
  ? telemetry.description
167
170
  : "";
168
171
  const toolDescription = tool.description || "";
169
- if ("agent_thinking" in properties
172
+ if ("call_purpose" in properties
170
173
  && "user_intent" in properties
171
174
  && telemetryDescription.includes(CURRENT_TELEMETRY_MARKER)) {
172
175
  return "current";
173
176
  }
174
- if ("intent" in properties
177
+ if ("agent_thinking" in properties
178
+ || "intent" in properties
175
179
  || "context" in properties
176
180
  || LEGACY_TELEMETRY_MARKERS.some((marker) => toolDescription.includes(marker))) {
177
181
  return "legacy";
@@ -393,7 +397,7 @@ const runDoctor = async (options, dependencies = { inspectMcp: exports.inspectMc
393
397
  const exposed = coverage.current.length + coverage.legacy.length;
394
398
  checks.push(exposed === 0
395
399
  ? pass("tool-wrapping", "Telemetry capture", "No Armature telemetry fields are advertised, as requested. "
396
- + `Tool-call and session analytics still flow; capturing user_intent/agent_thinking requires wrapping tools with ${wrapApiFor(detectedLanguage)}.`)
400
+ + `Tool-call and session analytics still flow; capturing user_intent/call_purpose requires wrapping tools with ${wrapApiFor(detectedLanguage)}.`)
397
401
  : warn("tool-wrapping", "Telemetry capture", `${exposed}/${coverage.total} tools still advertise Armature telemetry fields.`, "Confirm captureTelemetry=false is applied before tools are registered."));
398
402
  }
399
403
  else if (coverage.missing.length > 0) {
@@ -403,7 +403,7 @@ const wrapFastmcpTool = (tool, state, runtime, options) => {
403
403
  ...tool,
404
404
  parameters: decoratedParameters,
405
405
  // Same idempotent description nudge as the v1/v2 integrations (ARM-24).
406
- description: (0, schema_js_1.appendTelemetryHint)(tool.description),
406
+ description: (0, schema_js_1.appendTelemetryHint)(tool.description, { toolName: tool.name }),
407
407
  execute: wrappedExecute,
408
408
  };
409
409
  };
@@ -1,5 +1,5 @@
1
1
  export type { ActorIdResolver, ActorIdResolverInput, ActorIdentifierResolver, AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, AnalyticsRecorder, ExtractedToolArguments, HeaderBag, InstrumentToolCallEvent, JsonObjectSchema, McpAnalyticsConfig, McpClientInfo, McpServerInfo, RecordSessionInitEvent, RecordToolCallEvent, RedactableToolCall, RedactEventHook, RedactFunction, RegisteredToolHandler, RequestExtra, TelemetryArgs, TelemetryEmitter, TelemetryFieldMap, TelemetryMode, ToolCallHandler, ToolDefinition, ToolHandlerContext, ToolRegistration, WithMcpAnalyticsResult, } from "./types.js";
2
- export { appendTelemetryHint, applyTelemetryFieldMap, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, isCaptureEnabled, normalizeTelemetryArgs, planToolTelemetry, schemaDeclaresTelemetry, type ToolTelemetryPlan, } from "./schema.js";
2
+ export { appendTelemetryHint, MAX_TOOL_DESCRIPTION_LENGTH, applyTelemetryFieldMap, createTelemetryInputSchema, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, extractTelemetryArguments, isCaptureEnabled, normalizeTelemetryArgs, planToolTelemetry, schemaDeclaresTelemetry, type ToolTelemetryPlan, } from "./schema.js";
3
3
  export { BASE64_REMOVED_PLACEHOLDER, BINARY_REMOVED_PLACEHOLDER, prepareForPreview, REDACTION_FAILED_PLACEHOLDER, sanitizeValue, SANITIZATION_BUDGET, } from "./sanitize.js";
4
4
  export { normalizeSensitiveFieldName, redactSecretsInString, redactSecretsInValue, SECRET_PATTERN_RULES, SENSITIVE_FIELD_NAMES, type SecretPatternRule, } from "./redact-secrets.js";
5
5
  export { createPrivacyQueue, PRIVACY_QUEUE_BATCH_SIZE, PRIVACY_QUEUE_CAPACITY, type PrivacyQueue, type PrivacyQueueFinalizer, } from "./queue.js";
package/dist/cjs/index.js CHANGED
@@ -1,8 +1,9 @@
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.reportEmitError = exports.postTelemetryEvent = exports.IngestRejectedError = exports.IngestDeliveryError = exports.emitTelemetryEvent = exports.defaultMcpAnalyticsConfig = exports.DEFAULT_INGEST_RETRY_DELAY_MS = exports.DEFAULT_INGEST_MAX_ATTEMPTS = exports.normalizeSessionId = exports.finalizeToolCallEvent = exports.buildToolCallEvent = exports.buildSessionInitEvent = exports.buildEventId = exports.buildActorIdentityEvent = exports.buildActorId = exports.PRIVACY_QUEUE_CAPACITY = exports.PRIVACY_QUEUE_BATCH_SIZE = exports.createPrivacyQueue = exports.SENSITIVE_FIELD_NAMES = exports.SECRET_PATTERN_RULES = exports.redactSecretsInValue = exports.redactSecretsInString = exports.normalizeSensitiveFieldName = exports.SANITIZATION_BUDGET = exports.sanitizeValue = exports.REDACTION_FAILED_PLACEHOLDER = exports.prepareForPreview = exports.BINARY_REMOVED_PLACEHOLDER = exports.BASE64_REMOVED_PLACEHOLDER = exports.schemaDeclaresTelemetry = exports.planToolTelemetry = exports.normalizeTelemetryArgs = exports.isCaptureEnabled = exports.extractTelemetryArguments = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.applyTelemetryFieldMap = exports.appendTelemetryHint = void 0;
3
+ exports.instrumentMcpServerTools = exports.withMcpAnalytics = exports.createMcpAnalyticsServer = exports.resolveStatelessHttpSession = exports.parseStatelessSessionClientInfo = exports.buildStatelessSessionId = exports.createAnalyticsRecorder = exports.reportEmitError = exports.postTelemetryEvent = exports.IngestRejectedError = exports.IngestDeliveryError = exports.emitTelemetryEvent = exports.defaultMcpAnalyticsConfig = exports.DEFAULT_INGEST_RETRY_DELAY_MS = exports.DEFAULT_INGEST_MAX_ATTEMPTS = exports.normalizeSessionId = exports.finalizeToolCallEvent = exports.buildToolCallEvent = exports.buildSessionInitEvent = exports.buildEventId = exports.buildActorIdentityEvent = exports.buildActorId = exports.PRIVACY_QUEUE_CAPACITY = exports.PRIVACY_QUEUE_BATCH_SIZE = exports.createPrivacyQueue = exports.SENSITIVE_FIELD_NAMES = exports.SECRET_PATTERN_RULES = exports.redactSecretsInValue = exports.redactSecretsInString = exports.normalizeSensitiveFieldName = exports.SANITIZATION_BUDGET = exports.sanitizeValue = exports.REDACTION_FAILED_PLACEHOLDER = exports.prepareForPreview = exports.BINARY_REMOVED_PLACEHOLDER = exports.BASE64_REMOVED_PLACEHOLDER = exports.schemaDeclaresTelemetry = exports.planToolTelemetry = exports.normalizeTelemetryArgs = exports.isCaptureEnabled = exports.extractTelemetryArguments = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.applyTelemetryFieldMap = exports.MAX_TOOL_DESCRIPTION_LENGTH = 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
+ Object.defineProperty(exports, "MAX_TOOL_DESCRIPTION_LENGTH", { enumerable: true, get: function () { return schema_js_1.MAX_TOOL_DESCRIPTION_LENGTH; } });
6
7
  Object.defineProperty(exports, "applyTelemetryFieldMap", { enumerable: true, get: function () { return schema_js_1.applyTelemetryFieldMap; } });
7
8
  Object.defineProperty(exports, "createTelemetryInputSchema", { enumerable: true, get: function () { return schema_js_1.createTelemetryInputSchema; } });
8
9
  Object.defineProperty(exports, "createTelemetryJsonSchema", { enumerable: true, get: function () { return schema_js_1.createTelemetryJsonSchema; } });
@@ -65,7 +65,7 @@ const defaultMastraResolveExtra = (mastraContext) => {
65
65
  };
66
66
  exports.defaultMastraResolveExtra = defaultMastraResolveExtra;
67
67
  const mergeExtra = utils_js_1.mergeRequestExtra;
68
- const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra) => {
68
+ const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra, requestCapability) => {
69
69
  if (typeof tool?.execute !== "function") {
70
70
  return tool;
71
71
  }
@@ -74,7 +74,7 @@ const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra) => {
74
74
  // Mastra tools without an inputSchema keep no schema (Mastra derives its own
75
75
  // default); planToolTelemetry is only consulted for decoration when the tool
76
76
  // has one, but its mode still drives extraction either way.
77
- const plan = (0, schema_js_1.planToolTelemetry)(toolName, tool.inputSchema, config);
77
+ const plan = (0, schema_js_1.planToolTelemetry)(toolName, tool.inputSchema, config, { requestCapability });
78
78
  const decoratedInputSchema = tool.inputSchema === undefined ? undefined : plan.inputSchema;
79
79
  const wrappedExecute = (inputData, mastraContext) => {
80
80
  // Always extract standard Mastra MCP context (`context.mcp.extra` or the
@@ -133,7 +133,9 @@ const wrapMastraToolsWithRecorder = (tools, recorder, config = {}, options = {})
133
133
  throw new Error(`Tool name "${request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.requestCapability is enabled.`);
134
134
  }
135
135
  for (const [key, tool] of Object.entries(tools)) {
136
- out[key] = wrapOneTool(key, tool, recorder, config, options.resolveExtra);
136
+ // Same recorder-derived answer for the hint, so it names request_capability
137
+ // exactly when the returned map carries one (ours or the customer's).
138
+ out[key] = wrapOneTool(key, tool, recorder, config, options.resolveExtra, requestCapabilityEnabled);
137
139
  }
138
140
  if (requestCapabilityEnabled && !requestCapabilityCollision) {
139
141
  out[request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME] = {
@@ -15,6 +15,11 @@ exports.SECRET_PATTERN_RULES = [
15
15
  pattern: /\b(password|passwd|pwd|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|client[_-]?secret|private[_-]?key|authorization)([=:])([^\s"'`,;&]{4,})/gi,
16
16
  replacement: "$1$2[redacted:sensitive-kv]",
17
17
  },
18
+ {
19
+ id: "aws-secret-access-key",
20
+ pattern: /(secret[ _-]?access[ _-]?key["']?[ \t]*[=:][ \t]*["']?)[A-Za-z0-9/+]{40,}/gi,
21
+ replacement: "$1[redacted:aws-secret-access-key]",
22
+ },
18
23
  {
19
24
  id: "aws-access-key-id",
20
25
  pattern: /\b(?:AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AIPA|ANPA|ANVA|AROA)[A-Z0-9]{16}\b/g,
@@ -3,7 +3,7 @@ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
3
  import type { JsonObjectSchema, McpAnalyticsConfig } from "./types.js";
4
4
  export declare const REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
5
5
  export declare const REQUEST_CAPABILITY_DESCRIPTION = "Request a capability that is not provided by the currently available tools. Use this when a capability is required to complete the user\u2019s request and no existing tool can perform it.";
6
- export declare const REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = "The capability required to complete the user's request. Omit argument values, PII, and secrets. Use English.";
6
+ export declare const REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = "One English sentence describing the missing capability needed for the user's task. Translate the summary into English even when the user writes in another language. Describe generic actions and roles. Omit names, contacts, IDs, credentials and all tool argument values.";
7
7
  export declare const REQUEST_CAPABILITY_INPUT_SCHEMA: JsonObjectSchema;
8
8
  export declare const REQUEST_CAPABILITY_ZOD_SHAPE: {
9
9
  capability: z.ZodString;
@@ -6,7 +6,7 @@ const emit_js_1 = require("./emit.js");
6
6
  const utils_js_1 = require("./utils.js");
7
7
  exports.REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
8
8
  exports.REQUEST_CAPABILITY_DESCRIPTION = "Request a capability that is not provided by the currently available tools. Use this when a capability is required to complete the user’s request and no existing tool can perform it.";
9
- exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = "The capability required to complete the user's request. Omit argument values, PII, and secrets. Use English.";
9
+ exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = "One English sentence describing the missing capability needed for the user's task. Translate the summary into English even when the user writes in another language. Describe generic actions and roles. Omit names, contacts, IDs, credentials and all tool argument values.";
10
10
  exports.REQUEST_CAPABILITY_INPUT_SCHEMA = {
11
11
  type: "object",
12
12
  properties: {
@@ -1,11 +1,16 @@
1
1
  import { z } from "zod";
2
2
  import * as zv4 from "zod/v4";
3
3
  import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs, TelemetryFieldMap, TelemetryMode } from "./types.js";
4
- export declare const TELEMETRY_PROPERTY_DESCRIPTION = "Conversation telemetry. Include `agent_thinking` on every call. Include `user_intent` and `user_frustration` only on the first tool call after each new user message; omit them on subsequent calls while continuing the same turn.";
5
- export declare const appendTelemetryHint: (description: string | undefined) => string;
6
- export declare const USER_INTENT_DESCRIPTION = "What the user asked for in their most recent message, restated in one line. Include this field only on the first tool call after each new user message; omit it on subsequent calls until the user speaks again. If a new message preserves the same goal, repeat the same intent once. Stay faithful to the user's words; do not describe your plan. Omit argument values, PII, and secrets. Use English.";
7
- 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.";
8
- 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. Include this field only on the first tool call after each new user message; omit it on subsequent calls until the user speaks again.";
4
+ export declare const TELEMETRY_PROPERTY_DESCRIPTION = "Optional task context for usage analytics, based on the visible user request and the action performed by this tool.";
5
+ export declare const MAX_TOOL_DESCRIPTION_LENGTH = 1024;
6
+ export declare const appendTelemetryHint: (description: string | undefined, options?: {
7
+ requestCapability?: boolean;
8
+ toolName?: string;
9
+ }) => string;
10
+ export declare const withoutRequestCapabilityHint: (description: string | undefined, toolName?: string, registeredDescription?: string) => string;
11
+ export declare const USER_INTENT_DESCRIPTION = "Generalized one-sentence summary of the task stated in the user's latest message. Describe actions and generic roles only. Replace all tool argument values with generic terms, including names, contacts, IDs, credentials, document titles, team names and filters. For example, 'List employees in the selected team.' Include only on the first tool call after each new user message; omit on later calls in the same turn. Use English.";
12
+ export declare const CALL_PURPOSE_DESCRIPTION = "Short public description of the action this tool performs toward the user's stated goal. Base it only on the visible request, the tool's function and its inputs. Use English. Omit names, contact details, identifiers, credentials and argument values. Generalize document titles, team names and filter values (for example, 'the selected team').";
13
+ export declare const USER_FRUSTRATION_DESCRIPTION = "Frustration expressed in the user's latest message: low when none is expressed, medium for explicit dissatisfaction, high for strong or repeated dissatisfaction. Use only the user's words. Include on the first tool call after each new user message; omit on later calls in the same turn.";
9
14
  export declare const isCaptureEnabled: (config?: InternalMcpAnalyticsConfig) => boolean;
10
15
  export declare const schemaDeclaresTelemetry: (inputSchema: unknown) => boolean;
11
16
  export type ToolTelemetryPlan = {
@@ -13,18 +18,20 @@ export type ToolTelemetryPlan = {
13
18
  inputSchema: unknown;
14
19
  applyDescription: (description: string | undefined) => string | undefined;
15
20
  };
16
- export declare const planToolTelemetry: (toolName: string, inputSchema: unknown, config?: InternalMcpAnalyticsConfig) => ToolTelemetryPlan;
21
+ export declare const planToolTelemetry: (toolName: string, inputSchema: unknown, config?: InternalMcpAnalyticsConfig, options?: {
22
+ requestCapability?: boolean;
23
+ }) => ToolTelemetryPlan;
17
24
  export declare const createTelemetryInputSchema: (_config?: InternalMcpAnalyticsConfig) => z.ZodOptional<z.ZodObject<{
18
25
  user_intent: z.ZodOptional<z.ZodString>;
19
- agent_thinking: z.ZodOptional<z.ZodString>;
26
+ call_purpose: z.ZodOptional<z.ZodString>;
20
27
  user_frustration: z.ZodOptional<z.ZodString>;
21
28
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
22
29
  user_intent: z.ZodOptional<z.ZodString>;
23
- agent_thinking: z.ZodOptional<z.ZodString>;
30
+ call_purpose: z.ZodOptional<z.ZodString>;
24
31
  user_frustration: z.ZodOptional<z.ZodString>;
25
32
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
26
33
  user_intent: z.ZodOptional<z.ZodString>;
27
- agent_thinking: z.ZodOptional<z.ZodString>;
34
+ call_purpose: z.ZodOptional<z.ZodString>;
28
35
  user_frustration: z.ZodOptional<z.ZodString>;
29
36
  }, z.ZodTypeAny, "passthrough">>>;
30
37
  export declare const createTelemetryJsonSchema: (_config?: InternalMcpAnalyticsConfig) => JsonObjectSchema;
@@ -32,7 +39,7 @@ export declare const decorateInputSchemaWithTelemetry: (inputSchema: unknown, co
32
39
  readonly [x: string]: zv4.core.$ZodType<unknown, unknown, zv4.core.$ZodTypeInternals<unknown, unknown>>;
33
40
  telemetry: zv4.ZodOptional<zv4.ZodObject<{
34
41
  user_intent: zv4.ZodOptional<zv4.ZodString>;
35
- agent_thinking: zv4.ZodOptional<zv4.ZodString>;
42
+ call_purpose: zv4.ZodOptional<zv4.ZodString>;
36
43
  user_frustration: zv4.ZodOptional<zv4.ZodString>;
37
44
  }, zv4.core.$loose>>;
38
45
  }, zv4.core.$strip> | z.ZodObject<{
@@ -40,15 +47,15 @@ export declare const decorateInputSchemaWithTelemetry: (inputSchema: unknown, co
40
47
  } & {
41
48
  telemetry: z.ZodOptional<z.ZodObject<{
42
49
  user_intent: z.ZodOptional<z.ZodString>;
43
- agent_thinking: z.ZodOptional<z.ZodString>;
50
+ call_purpose: z.ZodOptional<z.ZodString>;
44
51
  user_frustration: z.ZodOptional<z.ZodString>;
45
52
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
46
53
  user_intent: z.ZodOptional<z.ZodString>;
47
- agent_thinking: z.ZodOptional<z.ZodString>;
54
+ call_purpose: z.ZodOptional<z.ZodString>;
48
55
  user_frustration: z.ZodOptional<z.ZodString>;
49
56
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
50
57
  user_intent: z.ZodOptional<z.ZodString>;
51
- agent_thinking: z.ZodOptional<z.ZodString>;
58
+ call_purpose: z.ZodOptional<z.ZodString>;
52
59
  user_frustration: z.ZodOptional<z.ZodString>;
53
60
  }, z.ZodTypeAny, "passthrough">>>;
54
61
  }, any, any, {
@@ -33,43 +33,151 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.extractTelemetryArguments = exports.applyTelemetryFieldMap = exports.normalizeTelemetryArgs = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.planToolTelemetry = exports.schemaDeclaresTelemetry = exports.isCaptureEnabled = exports.USER_FRUSTRATION_DESCRIPTION = exports.AGENT_THINKING_DESCRIPTION = exports.USER_INTENT_DESCRIPTION = exports.appendTelemetryHint = exports.TELEMETRY_PROPERTY_DESCRIPTION = void 0;
36
+ exports.extractTelemetryArguments = exports.applyTelemetryFieldMap = exports.normalizeTelemetryArgs = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.planToolTelemetry = exports.schemaDeclaresTelemetry = exports.isCaptureEnabled = exports.USER_FRUSTRATION_DESCRIPTION = exports.CALL_PURPOSE_DESCRIPTION = exports.USER_INTENT_DESCRIPTION = exports.withoutRequestCapabilityHint = exports.appendTelemetryHint = exports.MAX_TOOL_DESCRIPTION_LENGTH = exports.TELEMETRY_PROPERTY_DESCRIPTION = void 0;
37
37
  const zod_1 = require("zod");
38
38
  const zv4 = __importStar(require("zod/v4"));
39
+ const request_capability_js_1 = require("./request-capability.js");
39
40
  const utils_js_1 = require("./utils.js");
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. Include `agent_thinking` on every call. Include `user_intent` and `user_frustration` only on the first tool call after each new user message; omit them on subsequent calls while continuing the same turn.";
45
- const TELEMETRY_DESCRIPTION_HINT = "\n\nOn every call, pass telemetry.agent_thinking with your reasoning for this specific call. Pass telemetry.user_intent only on the first tool call after a new user message.";
46
- const TELEMETRY_DESCRIPTION_HINT_MARKER = TELEMETRY_DESCRIPTION_HINT.trim();
47
- // Older hints are recognized (never emitted) so a description that reached us
48
- // through an earlier wrapper doesn't accumulate a second, mixed-generation
49
- // nudge. Same markers in the Python and Go SDKs.
50
- const TELEMETRY_DESCRIPTION_HINT_REPEAT_INTENT_MARKER = "Pass telemetry.user_intent with a one-line restatement of the user's most recent request, and telemetry.agent_thinking with your reasoning for making this specific call.";
51
- const TELEMETRY_DESCRIPTION_HINT_V1_MARKER = "Pass telemetry.user_intent with a one-line restatement of the user's most recent request.";
52
- const TELEMETRY_DESCRIPTION_HINT_LEGACY_MARKER = "Pass telemetry.intent with a one-line user intent for analytics.";
53
- // Appends the telemetry.user_intent nudge to a tool description (idempotently —
54
- // a description that already carries the hint, either generation, passes
55
- // through unchanged). Every integration shape must run tool descriptions
56
- // through this so calling agents know to pass telemetry.user_intent (ARM-24).
57
- const appendTelemetryHint = (description) => {
41
+ // Public task context is identical across all four SDKs. Legacy field names
42
+ // remain accepted on input and in storage, but are never advertised.
43
+ exports.TELEMETRY_PROPERTY_DESCRIPTION = "Optional task context for usage analytics, based on the visible user request and the action performed by this tool.";
44
+ const TELEMETRY_DESCRIPTION_HINT = "\n\nInclude telemetry.call_purpose with a short description of this action. Include telemetry.user_intent and telemetry.user_frustration only on the first tool call after each new user message.";
45
+ const TELEMETRY_SENTENCE = TELEMETRY_DESCRIPTION_HINT.trimStart();
46
+ const REQUEST_CAPABILITY_SENTENCE = "If no tool can do what the user asks, call request_capability.";
47
+ const TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY = `${TELEMETRY_DESCRIPTION_HINT} ${REQUEST_CAPABILITY_SENTENCE}`;
48
+ const TELEMETRY_SENTENCE_HINT = TELEMETRY_DESCRIPTION_HINT;
49
+ // Only exact SDK suffixes are replaced. A mention within customer prose stays.
50
+ const RECOGNIZED_HINT_MARKERS = [
51
+ `${TELEMETRY_SENTENCE} ${REQUEST_CAPABILITY_SENTENCE}`,
52
+ TELEMETRY_SENTENCE,
53
+ "Pass telemetry.agent_thinking on every call, telemetry.user_intent on the first call after each user message. If no tool can do what the user asks, call request_capability.",
54
+ "Pass telemetry.agent_thinking on every call, telemetry.user_intent on the first call after each user message.",
55
+ "On every call, pass telemetry.agent_thinking with your reasoning for this specific call. Pass telemetry.user_intent only on the first tool call after a new user message.",
56
+ "Pass telemetry.user_intent with a one-line restatement of the user's most recent request, and telemetry.agent_thinking with your reasoning for making this specific call.",
57
+ "Pass telemetry.user_intent with a one-line restatement of the user's most recent request.",
58
+ "Pass telemetry.intent with a one-line user intent for analytics.",
59
+ ];
60
+ // Some providers reject the whole request when any tool description exceeds
61
+ // 1024 characters (Azure OpenAI, some OpenAI-compatible gateways), and Claude
62
+ // Code cuts descriptions at 2048, which would drop the hint first. Measured in
63
+ // UTF-8 bytes, which never undercounts characters and matches the Python, Go,
64
+ // and PHP SDKs exactly.
65
+ exports.MAX_TOOL_DESCRIPTION_LENGTH = 1024;
66
+ const utf8 = new TextEncoder();
67
+ const fits = (text) => utf8.encode(text).length <= exports.MAX_TOOL_DESCRIPTION_LENGTH;
68
+ const warnedLongDescriptions = new Set();
69
+ const warnDescriptionTooLong = (toolName, message) => {
70
+ if (warnedLongDescriptions.has(toolName))
71
+ return;
72
+ warnedLongDescriptions.add(toolName);
73
+ // eslint-disable-next-line no-console
74
+ console.warn(`[mcp-analytics] Tool "${toolName}" description is too long ${message}`);
75
+ };
76
+ // Appends the current telemetry hint and upgrades exact SDK hint suffixes.
77
+ // Every integration shape must run tool descriptions through this
78
+ // so calling agents know to pass telemetry (ARM-24). With `requestCapability`,
79
+ // the hint also points agents to request_capability.
80
+ //
81
+ // The result never exceeds MAX_TOOL_DESCRIPTION_LENGTH because of us: when the
82
+ // full hint does not fit, only the telemetry sentence is appended (it matters
83
+ // per tool; request_capability is a list-wide instruction other tools carry);
84
+ // when that does not fit either, the description is left unchanged. Sentences
85
+ // are never cut, and the telemetry field is still advertised either way.
86
+ const appendTelemetryHint = (description, options = {}) => {
87
+ const requestCapability = options.requestCapability === true;
58
88
  if (description === undefined) {
59
- return TELEMETRY_DESCRIPTION_HINT.trimStart();
89
+ return (requestCapability
90
+ ? TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY
91
+ : TELEMETRY_DESCRIPTION_HINT).trimStart();
92
+ }
93
+ // Upgrade cached SDK suffixes before checking the size budget. Remove a
94
+ // full hint before its shorter forms, including stacked older wrappers.
95
+ let base = description;
96
+ for (;;) {
97
+ const trimmed = base.trimEnd();
98
+ const marker = RECOGNIZED_HINT_MARKERS.find((candidate) => trimmed === candidate || trimmed.endsWith(`\n\n${candidate}`));
99
+ if (marker === undefined)
100
+ break;
101
+ base = trimmed === marker ? "" : trimmed.slice(0, -marker.length - 2);
60
102
  }
61
- if (description.includes(TELEMETRY_DESCRIPTION_HINT_MARKER)
62
- || description.includes(TELEMETRY_DESCRIPTION_HINT_REPEAT_INTENT_MARKER)
63
- || description.includes(TELEMETRY_DESCRIPTION_HINT_V1_MARKER)
64
- || description.includes(TELEMETRY_DESCRIPTION_HINT_LEGACY_MARKER)) {
65
- return description;
103
+ description = base;
104
+ if (description.length === 0) {
105
+ return (requestCapability
106
+ ? TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY
107
+ : TELEMETRY_DESCRIPTION_HINT).trimStart();
66
108
  }
67
- return `${description}${TELEMETRY_DESCRIPTION_HINT}`;
109
+ // A customer who already wrote the request_capability sentence gets only the
110
+ // telemetry one, so the instruction is not repeated.
111
+ const hint = !requestCapability
112
+ ? TELEMETRY_DESCRIPTION_HINT
113
+ : description.includes(REQUEST_CAPABILITY_SENTENCE)
114
+ ? TELEMETRY_SENTENCE_HINT
115
+ : TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY;
116
+ if (fits(`${description}${hint}`)) {
117
+ return `${description}${hint}`;
118
+ }
119
+ if (fits(`${description}${TELEMETRY_SENTENCE_HINT}`)) {
120
+ if (options.toolName !== undefined) {
121
+ warnDescriptionTooLong(options.toolName, `for the full Armature telemetry hint within ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; appended only the telemetry sentence.`);
122
+ }
123
+ return `${description}${TELEMETRY_SENTENCE_HINT}`;
124
+ }
125
+ if (options.toolName !== undefined) {
126
+ warnDescriptionTooLong(options.toolName, `to append the Armature telemetry hint without exceeding ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; leaving it unchanged. Telemetry is still collected.`);
127
+ }
128
+ return description;
68
129
  };
69
130
  exports.appendTelemetryHint = appendTelemetryHint;
70
- exports.USER_INTENT_DESCRIPTION = "What the user asked for in their most recent message, restated in one line. Include this field only on the first tool call after each new user message; omit it on subsequent calls until the user speaks again. If a new message preserves the same goal, repeat the same intent once. Stay faithful to the user's words; do not describe your plan. Omit argument values, PII, and secrets. Use English.";
71
- 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.";
72
- 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. Include this field only on the first tool call after each new user message; omit it on subsequent calls until the user speaks again.";
131
+ // The factory can append customer text after the SDK's registered hint. Update
132
+ // that exact block in place when its server does not expose request_capability.
133
+ const withoutRequestCapabilityHint = (description, toolName, registeredDescription) => {
134
+ if (description !== undefined) {
135
+ // The last paragraph is the SDK suffix, even when an earlier customer
136
+ // paragraph quotes the same instruction. If the factory kept the registered
137
+ // description, anchor to its suffix so later customer quotes also survive.
138
+ const registeredIndex = registeredDescription === undefined
139
+ ? -1
140
+ : description.indexOf(registeredDescription);
141
+ const registeredMarker = registeredDescription === undefined
142
+ ? undefined
143
+ : RECOGNIZED_HINT_MARKERS.find((marker) => registeredDescription === marker || registeredDescription.endsWith(`\n\n${marker}`));
144
+ let match;
145
+ if (registeredIndex >= 0 && registeredDescription !== undefined) {
146
+ if (registeredMarker !== undefined) {
147
+ match = {
148
+ marker: registeredMarker,
149
+ index: registeredIndex + registeredDescription.length - registeredMarker.length,
150
+ };
151
+ }
152
+ }
153
+ else {
154
+ for (const marker of RECOGNIZED_HINT_MARKERS) {
155
+ const paragraph = description.lastIndexOf(`\n\n${marker}`);
156
+ const index = paragraph >= 0 ? paragraph + 2 : description.startsWith(marker) ? 0 : -1;
157
+ // Longer markers precede their shorter prefixes in the list.
158
+ if (index >= 0 && (match === undefined || index > match.index))
159
+ match = { marker, index };
160
+ }
161
+ }
162
+ if (match !== undefined) {
163
+ const { marker, index } = match;
164
+ const updated = description.slice(0, index) + TELEMETRY_SENTENCE + description.slice(index + marker.length);
165
+ if (fits(updated))
166
+ return updated;
167
+ if (toolName !== undefined) {
168
+ warnDescriptionTooLong(toolName, `to keep the Armature telemetry hint within ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; removed it. Telemetry is still collected.`);
169
+ }
170
+ return index === 0
171
+ ? description.slice(marker.length).trimStart()
172
+ : description.slice(0, index - 2) + description.slice(index + marker.length);
173
+ }
174
+ }
175
+ return (0, exports.appendTelemetryHint)(description, toolName === undefined ? {} : { toolName });
176
+ };
177
+ exports.withoutRequestCapabilityHint = withoutRequestCapabilityHint;
178
+ exports.USER_INTENT_DESCRIPTION = "Generalized one-sentence summary of the task stated in the user's latest message. Describe actions and generic roles only. Replace all tool argument values with generic terms, including names, contacts, IDs, credentials, document titles, team names and filters. For example, 'List employees in the selected team.' Include only on the first tool call after each new user message; omit on later calls in the same turn. Use English.";
179
+ exports.CALL_PURPOSE_DESCRIPTION = "Short public description of the action this tool performs toward the user's stated goal. Base it only on the visible request, the tool's function and its inputs. Use English. Omit names, contact details, identifiers, credentials and argument values. Generalize document titles, team names and filter values (for example, 'the selected team').";
180
+ exports.USER_FRUSTRATION_DESCRIPTION = "Frustration expressed in the user's latest message: low when none is expressed, medium for explicit dissatisfaction, high for strong or repeated dissatisfaction. Use only the user's words. Include on the first tool call after each new user message; omit on later calls in the same turn.";
73
181
  // Each telemetry object schema carries the object-level description via
74
182
  // `.describe(...)` so it survives zod→JSON-schema conversion in every
75
183
  // integration shape — including caller-owned McpServer registration, where no
@@ -83,7 +191,7 @@ exports.USER_FRUSTRATION_DESCRIPTION = "Frustration evident in the user's most r
83
191
  const looseTelemetryInputSchema = zod_1.z
84
192
  .object({
85
193
  user_intent: zod_1.z.string().describe(exports.USER_INTENT_DESCRIPTION).optional(),
86
- agent_thinking: zod_1.z.string().describe(exports.AGENT_THINKING_DESCRIPTION).optional(),
194
+ call_purpose: zod_1.z.string().describe(exports.CALL_PURPOSE_DESCRIPTION).optional(),
87
195
  user_frustration: zod_1.z
88
196
  .string()
89
197
  .describe(exports.USER_FRUSTRATION_DESCRIPTION)
@@ -94,9 +202,9 @@ const looseTelemetryInputSchema = zod_1.z
94
202
  const looseTelemetryInputSchemaV4 = zv4
95
203
  .looseObject({
96
204
  user_intent: zv4.string().describe(exports.USER_INTENT_DESCRIPTION).optional(),
97
- agent_thinking: zv4
205
+ call_purpose: zv4
98
206
  .string()
99
- .describe(exports.AGENT_THINKING_DESCRIPTION)
207
+ .describe(exports.CALL_PURPOSE_DESCRIPTION)
100
208
  .optional(),
101
209
  user_frustration: zv4
102
210
  .string()
@@ -170,7 +278,10 @@ const warnTelemetryCollision = (toolName) => {
170
278
  // prototype patch, Mastra adapter, custom dispatchers) must register and
171
279
  // extract with the same plan, so the advertised schema always matches runtime
172
280
  // behavior.
173
- const planToolTelemetry = (toolName, inputSchema, config = {}) => {
281
+ // `requestCapability` overrides the config-derived answer to "does this
282
+ // server list request_capability?" for adapters whose recorder, not the
283
+ // wrap-time config, is the source of truth (Mastra).
284
+ const planToolTelemetry = (toolName, inputSchema, config = {}, options = {}) => {
174
285
  if ((0, exports.schemaDeclaresTelemetry)(inputSchema)) {
175
286
  warnTelemetryCollision(toolName);
176
287
  return {
@@ -189,7 +300,10 @@ const planToolTelemetry = (toolName, inputSchema, config = {}) => {
189
300
  return {
190
301
  mode: "injected",
191
302
  inputSchema: (0, exports.decorateInputSchemaWithTelemetry)(inputSchema, config),
192
- applyDescription: exports.appendTelemetryHint,
303
+ applyDescription: (description) => (0, exports.appendTelemetryHint)(description, {
304
+ requestCapability: options.requestCapability ?? (0, request_capability_js_1.isRequestCapabilityEnabled)(config),
305
+ toolName,
306
+ }),
193
307
  };
194
308
  };
195
309
  exports.planToolTelemetry = planToolTelemetry;
@@ -211,9 +325,9 @@ const createTelemetryJsonSchema = (_config = {}) => {
211
325
  type: "string",
212
326
  description: exports.USER_INTENT_DESCRIPTION,
213
327
  },
214
- agent_thinking: {
328
+ call_purpose: {
215
329
  type: "string",
216
- description: exports.AGENT_THINKING_DESCRIPTION,
330
+ description: exports.CALL_PURPOSE_DESCRIPTION,
217
331
  },
218
332
  user_frustration: {
219
333
  type: "string",
@@ -277,7 +391,8 @@ const firstString = (...values) => {
277
391
  }
278
392
  return undefined;
279
393
  };
280
- // Canonicalizes telemetry onto the current field names. Legacy spellings
394
+ // Maps public call_purpose onto the existing agent_thinking storage field.
395
+ // Canonicalizes telemetry onto the storage field names. Legacy spellings
281
396
  // (`intent`/`context`/`frustration_level`) still arrive from clients that
282
397
  // cached a pre-V1 tool schema and from callers passing telemetry directly to
283
398
  // recordToolCall; they lose to an explicit current value when both are present.
@@ -291,7 +406,7 @@ const normalizeTelemetryArgs = (telemetry) => {
291
406
  const userIntent = firstString(telemetry.user_intent, telemetry.intent);
292
407
  if (userIntent !== undefined)
293
408
  normalized.user_intent = userIntent;
294
- const agentThinking = firstString(telemetry.agent_thinking, telemetry.context);
409
+ const agentThinking = firstString(telemetry.call_purpose, telemetry.agent_thinking, telemetry.context);
295
410
  if (agentThinking !== undefined)
296
411
  normalized.agent_thinking = agentThinking;
297
412
  const userFrustration = asFrustration(telemetry.user_frustration)
@@ -321,10 +436,10 @@ const applyTelemetryFieldMap = (telemetry, args, fieldMap) => {
321
436
  if (value !== undefined)
322
437
  merged.user_intent = value;
323
438
  }
324
- if (merged.agent_thinking === undefined && merged.context === undefined) {
325
- const value = argString(fieldMap.agent_thinking);
439
+ if (merged.call_purpose === undefined && merged.agent_thinking === undefined && merged.context === undefined) {
440
+ const value = argString(fieldMap.call_purpose) ?? argString(fieldMap.agent_thinking);
326
441
  if (value !== undefined)
327
- merged.agent_thinking = value;
442
+ merged.call_purpose = value;
328
443
  }
329
444
  if (merged.user_frustration === undefined
330
445
  && merged.frustration_level === undefined