@armature-tech/mcp-analytics 0.6.41 → 0.6.43
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 +39 -42
- package/SKILL.md +6 -5
- package/dist/cjs/doctor.js +10 -6
- package/dist/cjs/events.js +3 -2
- package/dist/cjs/fastmcp.js +2 -5
- package/dist/cjs/mastra.js +6 -10
- package/dist/cjs/recorder.js +3 -5
- package/dist/cjs/request-capability.d.ts +5 -2
- package/dist/cjs/request-capability.js +27 -12
- package/dist/cjs/schema.d.ts +13 -12
- package/dist/cjs/schema.js +41 -172
- package/dist/cjs/server.js +8 -62
- package/dist/cjs/types.d.ts +7 -3
- package/dist/cjs/v2.js +2 -5
- package/dist/esm/doctor.js +11 -7
- package/dist/esm/events.js +3 -2
- package/dist/esm/fastmcp.js +3 -6
- package/dist/esm/mastra.js +7 -11
- package/dist/esm/recorder.js +3 -5
- package/dist/esm/request-capability.d.ts +5 -2
- package/dist/esm/request-capability.js +26 -11
- package/dist/esm/schema.d.ts +13 -12
- package/dist/esm/schema.js +39 -170
- package/dist/esm/server.js +9 -63
- package/dist/esm/types.d.ts +7 -3
- package/dist/esm/v2.js +3 -6
- package/package.json +1 -1
package/dist/cjs/schema.js
CHANGED
|
@@ -33,20 +33,24 @@ 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.
|
|
36
|
+
exports.extractTelemetryArguments = exports.applyTelemetryFieldMap = exports.normalizeTelemetryArgs = exports.decorateInputSchemaWithTelemetry = exports.createTelemetryJsonSchema = exports.createTelemetryInputSchema = exports.planToolTelemetry = exports.schemaDeclaresTelemetry = exports.isCaptureEnabled = exports.CALL_PURPOSE_DESCRIPTION = exports.USER_INTENT_DESCRIPTION = exports.appendTelemetryHint = exports.stripSdkDescriptionHint = 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");
|
|
40
39
|
const utils_js_1 = require("./utils.js");
|
|
41
40
|
// Public task context is identical across all four SDKs. Legacy field names
|
|
42
41
|
// remain accepted on input and in storage, but are never advertised.
|
|
43
42
|
exports.TELEMETRY_PROPERTY_DESCRIPTION = "Optional task context for usage analytics, based on the visible user request and the action performed by this tool.";
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
// Earlier releases appended these sentences to every tool description. The SDK
|
|
44
|
+
// no longer adds text to a tool description (TELEMETRY-CONTRACT.md, "Tool
|
|
45
|
+
// descriptions"): what the agent is asked for lives in the injected
|
|
46
|
+
// parameters' own descriptions, as in the PostHog and AgentCat SDKs.
|
|
47
|
+
// Anthropic's connector directory review asked for exactly this. Exact SDK
|
|
48
|
+
// suffixes from those releases are still removed, so a description registered
|
|
49
|
+
// through an older wrapper or a cached factory comes out clean.
|
|
50
|
+
const TELEMETRY_SENTENCE = "Include 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.";
|
|
46
51
|
const REQUEST_CAPABILITY_SENTENCE = "Call request_capability before you tell the user something can't be done here or has to be done elsewhere.";
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// Only exact SDK suffixes are replaced. A mention within customer prose stays.
|
|
52
|
+
// Only exact SDK suffixes are removed. A mention within customer prose stays.
|
|
53
|
+
// Longer markers precede their shorter prefixes.
|
|
50
54
|
const RECOGNIZED_HINT_MARKERS = [
|
|
51
55
|
`${TELEMETRY_SENTENCE} ${REQUEST_CAPABILITY_SENTENCE}`,
|
|
52
56
|
`${TELEMETRY_SENTENCE} If no tool can do what the user asks, call request_capability.`,
|
|
@@ -58,160 +62,51 @@ const RECOGNIZED_HINT_MARKERS = [
|
|
|
58
62
|
"Pass telemetry.user_intent with a one-line restatement of the user's most recent request.",
|
|
59
63
|
"Pass telemetry.intent with a one-line user intent for analytics.",
|
|
60
64
|
];
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// and PHP SDKs exactly.
|
|
65
|
+
/**
|
|
66
|
+
* Kept for compatibility: the SDK no longer appends anything to tool
|
|
67
|
+
* descriptions, so no description can grow past this because of us.
|
|
68
|
+
*/
|
|
66
69
|
exports.MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
return;
|
|
73
|
-
warnedLongDescriptions.add(toolName);
|
|
74
|
-
const text = `[mcp-analytics] Tool "${toolName}" description is too long ${message}`;
|
|
75
|
-
// Node's console.debug and console.info write to stdout, which carries
|
|
76
|
-
// JSON-RPC for stdio servers. Where the runtime has a stderr stream, every
|
|
77
|
-
// level goes there; elsewhere (Workers, browsers) the console method
|
|
78
|
-
// carries the level.
|
|
79
|
-
const stderr = typeof process !== "undefined" ? process.stderr : undefined;
|
|
80
|
-
// eslint-disable-next-line no-console
|
|
81
|
-
if (level === "warning")
|
|
82
|
-
console.warn(text);
|
|
83
|
-
else if (typeof stderr?.write === "function")
|
|
84
|
-
stderr.write(`${text}\n`);
|
|
85
|
-
// eslint-disable-next-line no-console
|
|
86
|
-
else if (level === "debug")
|
|
87
|
-
console.debug(text);
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
else
|
|
90
|
-
console.info(text);
|
|
91
|
-
};
|
|
92
|
-
// Appends the current telemetry hint and upgrades exact SDK hint suffixes.
|
|
93
|
-
// Every integration shape must run tool descriptions through this
|
|
94
|
-
// so calling agents know to pass telemetry (ARM-24). With `requestCapability`,
|
|
95
|
-
// the hint also points agents to request_capability.
|
|
96
|
-
//
|
|
97
|
-
// The result never exceeds MAX_TOOL_DESCRIPTION_LENGTH because of us: when the
|
|
98
|
-
// full hint does not fit, only the telemetry sentence is appended (it matters
|
|
99
|
-
// per tool; request_capability is a list-wide instruction other tools carry);
|
|
100
|
-
// when that does not fit either, the description is left unchanged. Sentences
|
|
101
|
-
// are never cut, and the telemetry field is still advertised either way.
|
|
102
|
-
const appendTelemetryHint = (description, options = {}) => {
|
|
103
|
-
const requestCapability = options.requestCapability === true;
|
|
104
|
-
if (description === undefined) {
|
|
105
|
-
return (requestCapability
|
|
106
|
-
? TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY
|
|
107
|
-
: TELEMETRY_DESCRIPTION_HINT).trimStart();
|
|
108
|
-
}
|
|
109
|
-
// Upgrade cached SDK suffixes before checking the size budget. Remove a
|
|
110
|
-
// full hint before its shorter forms, including stacked older wrappers.
|
|
70
|
+
// Removes the SDK's own trailing hint paragraph(s), stacked older wrappers
|
|
71
|
+
// included. A description that was only an SDK hint becomes empty; a tool with
|
|
72
|
+
// no description keeps none.
|
|
73
|
+
const stripSdkDescriptionHint = (description) => {
|
|
74
|
+
if (description === undefined)
|
|
75
|
+
return undefined;
|
|
111
76
|
let base = description;
|
|
112
77
|
for (;;) {
|
|
113
78
|
const trimmed = base.trimEnd();
|
|
114
79
|
const marker = RECOGNIZED_HINT_MARKERS.find((candidate) => trimmed === candidate || trimmed.endsWith(`\n\n${candidate}`));
|
|
115
80
|
if (marker === undefined)
|
|
116
|
-
|
|
81
|
+
return base;
|
|
117
82
|
base = trimmed === marker ? "" : trimmed.slice(0, -marker.length - 2);
|
|
118
83
|
}
|
|
119
|
-
description = base;
|
|
120
|
-
if (description.length === 0) {
|
|
121
|
-
return (requestCapability
|
|
122
|
-
? TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY
|
|
123
|
-
: TELEMETRY_DESCRIPTION_HINT).trimStart();
|
|
124
|
-
}
|
|
125
|
-
// A customer who already wrote the request_capability sentence gets only the
|
|
126
|
-
// telemetry one, so the instruction is not repeated.
|
|
127
|
-
const hint = !requestCapability
|
|
128
|
-
? TELEMETRY_DESCRIPTION_HINT
|
|
129
|
-
: description.includes(REQUEST_CAPABILITY_SENTENCE)
|
|
130
|
-
? TELEMETRY_SENTENCE_HINT
|
|
131
|
-
: TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY;
|
|
132
|
-
if (fits(`${description}${hint}`)) {
|
|
133
|
-
return `${description}${hint}`;
|
|
134
|
-
}
|
|
135
|
-
if (fits(`${description}${TELEMETRY_SENTENCE_HINT}`)) {
|
|
136
|
-
if (options.toolName !== undefined) {
|
|
137
|
-
warnDescriptionTooLong(options.toolName, `for the full Armature telemetry hint within ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; appended only the telemetry sentence.`, options.logLevel);
|
|
138
|
-
}
|
|
139
|
-
return `${description}${TELEMETRY_SENTENCE_HINT}`;
|
|
140
|
-
}
|
|
141
|
-
if (options.toolName !== undefined) {
|
|
142
|
-
warnDescriptionTooLong(options.toolName, `to append the Armature telemetry hint without exceeding ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; leaving it unchanged. Telemetry is still collected.`, options.logLevel);
|
|
143
|
-
}
|
|
144
|
-
return description;
|
|
145
84
|
};
|
|
85
|
+
exports.stripSdkDescriptionHint = stripSdkDescriptionHint;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Appends nothing. The SDK no longer adds text to tool
|
|
88
|
+
* descriptions; this only removes SDK hint suffixes from earlier releases.
|
|
89
|
+
* The options are accepted and ignored.
|
|
90
|
+
*/
|
|
91
|
+
const appendTelemetryHint = (description, _options = {}) => (0, exports.stripSdkDescriptionHint)(description);
|
|
146
92
|
exports.appendTelemetryHint = appendTelemetryHint;
|
|
147
|
-
// The factory can append customer text after the SDK's registered hint. Update
|
|
148
|
-
// that exact block in place when its server does not expose request_capability.
|
|
149
|
-
const withoutRequestCapabilityHint = (description, toolName, registeredDescription, logLevel) => {
|
|
150
|
-
if (description !== undefined) {
|
|
151
|
-
// The last paragraph is the SDK suffix, even when an earlier customer
|
|
152
|
-
// paragraph quotes the same instruction. If the factory kept the registered
|
|
153
|
-
// description, anchor to its suffix so later customer quotes also survive.
|
|
154
|
-
const registeredIndex = registeredDescription === undefined
|
|
155
|
-
? -1
|
|
156
|
-
: description.indexOf(registeredDescription);
|
|
157
|
-
const registeredMarker = registeredDescription === undefined
|
|
158
|
-
? undefined
|
|
159
|
-
: RECOGNIZED_HINT_MARKERS.find((marker) => registeredDescription === marker || registeredDescription.endsWith(`\n\n${marker}`));
|
|
160
|
-
let match;
|
|
161
|
-
if (registeredIndex >= 0 && registeredDescription !== undefined) {
|
|
162
|
-
if (registeredMarker !== undefined) {
|
|
163
|
-
match = {
|
|
164
|
-
marker: registeredMarker,
|
|
165
|
-
index: registeredIndex + registeredDescription.length - registeredMarker.length,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
for (const marker of RECOGNIZED_HINT_MARKERS) {
|
|
171
|
-
const paragraph = description.lastIndexOf(`\n\n${marker}`);
|
|
172
|
-
const index = paragraph >= 0 ? paragraph + 2 : description.startsWith(marker) ? 0 : -1;
|
|
173
|
-
// Longer markers precede their shorter prefixes in the list.
|
|
174
|
-
if (index >= 0 && (match === undefined || index > match.index))
|
|
175
|
-
match = { marker, index };
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (match !== undefined) {
|
|
179
|
-
const { marker, index } = match;
|
|
180
|
-
const updated = description.slice(0, index) + TELEMETRY_SENTENCE + description.slice(index + marker.length);
|
|
181
|
-
if (fits(updated))
|
|
182
|
-
return updated;
|
|
183
|
-
if (toolName !== undefined) {
|
|
184
|
-
warnDescriptionTooLong(toolName, `to keep the Armature telemetry hint within ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; removed it. Telemetry is still collected.`, logLevel);
|
|
185
|
-
}
|
|
186
|
-
return index === 0
|
|
187
|
-
? description.slice(marker.length).trimStart()
|
|
188
|
-
: description.slice(0, index - 2) + description.slice(index + marker.length);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return (0, exports.appendTelemetryHint)(description, toolName === undefined ? { logLevel } : { toolName, logLevel });
|
|
192
|
-
};
|
|
193
|
-
exports.withoutRequestCapabilityHint = withoutRequestCapabilityHint;
|
|
194
93
|
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.";
|
|
195
94
|
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').";
|
|
196
|
-
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.";
|
|
197
95
|
// Each telemetry object schema carries the object-level description via
|
|
198
96
|
// `.describe(...)` so it survives zod→JSON-schema conversion in every
|
|
199
97
|
// integration shape — including caller-owned McpServer registration, where no
|
|
200
98
|
// post-hoc JSON-schema nudge runs (ARM-24).
|
|
201
99
|
//
|
|
202
|
-
// `.passthrough()` keeps unknown keys: a client that cached
|
|
203
|
-
// schema may still send `intent`/`context
|
|
204
|
-
//
|
|
205
|
-
//
|
|
100
|
+
// `.passthrough()` keeps unknown keys: a client that cached an older tool
|
|
101
|
+
// schema may still send `intent`/`context`, and stripping them here would
|
|
102
|
+
// silently drop its telemetry before normalizeTelemetryArgs can translate the
|
|
103
|
+
// legacy spelling. A cached `user_frustration`/`frustration_level` passes
|
|
104
|
+
// validation too and is then dropped.
|
|
206
105
|
//
|
|
207
106
|
const looseTelemetryInputSchema = zod_1.z
|
|
208
107
|
.object({
|
|
209
108
|
user_intent: zod_1.z.string().describe(exports.USER_INTENT_DESCRIPTION).optional(),
|
|
210
109
|
call_purpose: zod_1.z.string().describe(exports.CALL_PURPOSE_DESCRIPTION).optional(),
|
|
211
|
-
user_frustration: zod_1.z
|
|
212
|
-
.string()
|
|
213
|
-
.describe(exports.USER_FRUSTRATION_DESCRIPTION)
|
|
214
|
-
.optional(),
|
|
215
110
|
})
|
|
216
111
|
.passthrough()
|
|
217
112
|
.describe(exports.TELEMETRY_PROPERTY_DESCRIPTION);
|
|
@@ -222,10 +117,6 @@ const looseTelemetryInputSchemaV4 = zv4
|
|
|
222
117
|
.string()
|
|
223
118
|
.describe(exports.CALL_PURPOSE_DESCRIPTION)
|
|
224
119
|
.optional(),
|
|
225
|
-
user_frustration: zv4
|
|
226
|
-
.string()
|
|
227
|
-
.describe(exports.USER_FRUSTRATION_DESCRIPTION)
|
|
228
|
-
.optional(),
|
|
229
120
|
})
|
|
230
121
|
.describe(exports.TELEMETRY_PROPERTY_DESCRIPTION);
|
|
231
122
|
// v4 Zod schemas carry a `_zod` brand on every type; v3 only has `_def`.
|
|
@@ -294,10 +185,9 @@ const warnTelemetryCollision = (toolName) => {
|
|
|
294
185
|
// prototype patch, Mastra adapter, custom dispatchers) must register and
|
|
295
186
|
// extract with the same plan, so the advertised schema always matches runtime
|
|
296
187
|
// behavior.
|
|
297
|
-
// `
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
-
const planToolTelemetry = (toolName, inputSchema, config = {}, options = {}) => {
|
|
188
|
+
// `_options` is accepted for adapters built against earlier releases; no
|
|
189
|
+
// description mentions request_capability any more.
|
|
190
|
+
const planToolTelemetry = (toolName, inputSchema, config = {}, _options = {}) => {
|
|
301
191
|
if ((0, exports.schemaDeclaresTelemetry)(inputSchema)) {
|
|
302
192
|
warnTelemetryCollision(toolName);
|
|
303
193
|
return {
|
|
@@ -316,11 +206,7 @@ const planToolTelemetry = (toolName, inputSchema, config = {}, options = {}) =>
|
|
|
316
206
|
return {
|
|
317
207
|
mode: "injected",
|
|
318
208
|
inputSchema: (0, exports.decorateInputSchemaWithTelemetry)(inputSchema, config),
|
|
319
|
-
applyDescription:
|
|
320
|
-
requestCapability: options.requestCapability ?? (0, request_capability_js_1.isRequestCapabilityEnabled)(config),
|
|
321
|
-
toolName,
|
|
322
|
-
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
323
|
-
}),
|
|
209
|
+
applyDescription: exports.stripSdkDescriptionHint,
|
|
324
210
|
};
|
|
325
211
|
};
|
|
326
212
|
exports.planToolTelemetry = planToolTelemetry;
|
|
@@ -346,10 +232,6 @@ const createTelemetryJsonSchema = (_config = {}) => {
|
|
|
346
232
|
type: "string",
|
|
347
233
|
description: exports.CALL_PURPOSE_DESCRIPTION,
|
|
348
234
|
},
|
|
349
|
-
user_frustration: {
|
|
350
|
-
type: "string",
|
|
351
|
-
description: exports.USER_FRUSTRATION_DESCRIPTION,
|
|
352
|
-
},
|
|
353
235
|
},
|
|
354
236
|
};
|
|
355
237
|
};
|
|
@@ -393,11 +275,6 @@ const decorateInputSchemaWithTelemetry = (inputSchema, config = {}) => {
|
|
|
393
275
|
throw new Error("MCP analytics can only decorate undefined, Zod object, JSON object, or raw-shape input schemas.");
|
|
394
276
|
};
|
|
395
277
|
exports.decorateInputSchemaWithTelemetry = decorateInputSchemaWithTelemetry;
|
|
396
|
-
const asFrustration = (value) => {
|
|
397
|
-
return value === "low" || value === "medium" || value === "high"
|
|
398
|
-
? value
|
|
399
|
-
: undefined;
|
|
400
|
-
};
|
|
401
278
|
// First value that is actually a string — mirrors Python's _first_str so both
|
|
402
279
|
// SDKs resolve mixed V1/legacy inputs identically (a non-string V1 value never
|
|
403
280
|
// shadows a usable legacy string).
|
|
@@ -426,10 +303,8 @@ const normalizeTelemetryArgs = (telemetry) => {
|
|
|
426
303
|
const agentThinking = firstString(telemetry.call_purpose, telemetry.agent_thinking, telemetry.context);
|
|
427
304
|
if (agentThinking !== undefined)
|
|
428
305
|
normalized.agent_thinking = agentThinking;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if (userFrustration !== undefined)
|
|
432
|
-
normalized.user_frustration = userFrustration;
|
|
306
|
+
// `user_frustration`/`frustration_level` from cached schemas are dropped:
|
|
307
|
+
// the SDK no longer asks agents to rate the user.
|
|
433
308
|
return normalized;
|
|
434
309
|
};
|
|
435
310
|
exports.normalizeTelemetryArgs = normalizeTelemetryArgs;
|
|
@@ -458,13 +333,7 @@ const applyTelemetryFieldMap = (telemetry, args, fieldMap) => {
|
|
|
458
333
|
if (value !== undefined)
|
|
459
334
|
merged.call_purpose = value;
|
|
460
335
|
}
|
|
461
|
-
|
|
462
|
-
&& merged.frustration_level === undefined
|
|
463
|
-
&& fieldMap.user_frustration !== undefined) {
|
|
464
|
-
const value = asFrustration(args[fieldMap.user_frustration]);
|
|
465
|
-
if (value !== undefined)
|
|
466
|
-
merged.user_frustration = value;
|
|
467
|
-
}
|
|
336
|
+
// A `user_frustration` mapping is accepted and ignored.
|
|
468
337
|
return Object.keys(merged).length > 0 ? merged : telemetry;
|
|
469
338
|
};
|
|
470
339
|
exports.applyTelemetryFieldMap = applyTelemetryFieldMap;
|
package/dist/cjs/server.js
CHANGED
|
@@ -11,20 +11,6 @@ const utils_js_1 = require("./utils.js");
|
|
|
11
11
|
const request_capability_js_1 = require("./request-capability.js");
|
|
12
12
|
const withAnalyticsStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
13
13
|
let prototypePatchInstalled = false;
|
|
14
|
-
// Servers a tool named request_capability was registered on: the SDK-owned
|
|
15
|
-
// one the recorder attaches, or a customer's own. Only the fallback for an
|
|
16
|
-
// SDK build without the tool registry below.
|
|
17
|
-
const serversListingRequestCapability = new WeakSet();
|
|
18
|
-
// Whether tools/list on `server` currently carries request_capability. Reads
|
|
19
|
-
// the SDK's registry (the same map and `enabled` filter tools/list uses), so
|
|
20
|
-
// a tool removed or disabled after registration no longer counts.
|
|
21
|
-
const listsRequestCapability = (server) => {
|
|
22
|
-
const registry = server._registeredTools;
|
|
23
|
-
if (registry !== null && typeof registry === "object") {
|
|
24
|
-
return registry[request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME]?.enabled === true;
|
|
25
|
-
}
|
|
26
|
-
return serversListingRequestCapability.has(server);
|
|
27
|
-
};
|
|
28
14
|
// Mirrors the SDK's `isZodTypeLike`/`isZodRawShapeCompat` checks closely enough
|
|
29
15
|
// to disambiguate the overloads of `server.tool(...)`: a raw shape is a plain
|
|
30
16
|
// object whose values include at least one Zod schema, while a Zod schema
|
|
@@ -131,16 +117,11 @@ const installPrototypePatchOnce = () => {
|
|
|
131
117
|
prototype.registerTool = function patchedRegisterTool(name, toolConfig, cb) {
|
|
132
118
|
const ctx = withAnalyticsStorage.getStore();
|
|
133
119
|
if (!ctx) {
|
|
134
|
-
|
|
135
|
-
if (name === request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME)
|
|
136
|
-
serversListingRequestCapability.add(this);
|
|
137
|
-
return registered;
|
|
120
|
+
return originalRegisterTool.call(this, name, toolConfig, cb);
|
|
138
121
|
}
|
|
139
122
|
const { config } = ctx;
|
|
140
123
|
const originalHasInputSchema = toolConfig.inputSchema !== undefined;
|
|
141
|
-
const plan = (0, schema_js_1.planToolTelemetry)(name, toolConfig.inputSchema, config
|
|
142
|
-
? { requestCapability: listsRequestCapability(this) }
|
|
143
|
-
: {});
|
|
124
|
+
const plan = (0, schema_js_1.planToolTelemetry)(name, toolConfig.inputSchema, config);
|
|
144
125
|
const registeredHasInputSchema = plan.inputSchema !== undefined;
|
|
145
126
|
const description = plan.applyDescription(toolConfig.description);
|
|
146
127
|
const instrumentedConfig = {
|
|
@@ -149,23 +130,7 @@ const installPrototypePatchOnce = () => {
|
|
|
149
130
|
...(registeredHasInputSchema ? { inputSchema: plan.inputSchema } : {}),
|
|
150
131
|
};
|
|
151
132
|
const wrappedCallback = wrapCallbackWithAnalytics(name, cb, originalHasInputSchema, registeredHasInputSchema, plan.mode, ctx);
|
|
152
|
-
|
|
153
|
-
if (name === request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME)
|
|
154
|
-
serversListingRequestCapability.add(this);
|
|
155
|
-
if (!ctx.resolved && plan.mode === "injected" && (0, request_capability_js_1.isRequestCapabilityEnabled)(config)) {
|
|
156
|
-
ctx.requestCapabilityHints.push({
|
|
157
|
-
server: this,
|
|
158
|
-
tool: registered,
|
|
159
|
-
toolName: name,
|
|
160
|
-
hintedDescription: description,
|
|
161
|
-
fallbackDescription: (0, schema_js_1.appendTelemetryHint)(toolConfig.description, {
|
|
162
|
-
toolName: name,
|
|
163
|
-
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
164
|
-
}),
|
|
165
|
-
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
return registered;
|
|
133
|
+
return originalRegisterTool.call(this, name, instrumentedConfig, wrappedCallback);
|
|
169
134
|
};
|
|
170
135
|
// PRIA and other older codebases still use the deprecated `server.tool(...)`
|
|
171
136
|
// overloads. Patch them too — we normalise into our patched `registerTool`
|
|
@@ -192,8 +157,6 @@ const withMcpAnalytics = (config, createServer) => {
|
|
|
192
157
|
const ctx = {
|
|
193
158
|
config,
|
|
194
159
|
recorder,
|
|
195
|
-
resolved: false,
|
|
196
|
-
requestCapabilityHints: [],
|
|
197
160
|
};
|
|
198
161
|
const result = withAnalyticsStorage.run(ctx, createServer);
|
|
199
162
|
// Customer tools registered inside the factory are handled by the
|
|
@@ -203,10 +166,10 @@ const withMcpAnalytics = (config, createServer) => {
|
|
|
203
166
|
// description.
|
|
204
167
|
if ((0, request_capability_js_1.isRequestCapabilityEnabled)(config) && !(result instanceof mcp_js_1.McpServer)) {
|
|
205
168
|
// Only a hard error when the caller explicitly opted in. A server that is
|
|
206
|
-
//
|
|
207
|
-
//
|
|
169
|
+
// on merely by default and doesn't return an McpServer silently skips
|
|
170
|
+
// injection instead of breaking on upgrade.
|
|
208
171
|
if ((0, request_capability_js_1.isRequestCapabilityExplicit)(config)) {
|
|
209
|
-
throw new Error("armature.
|
|
172
|
+
throw new Error("armature.sendFeedback requires the server factory to return an McpServer instance.");
|
|
210
173
|
}
|
|
211
174
|
}
|
|
212
175
|
if ((0, request_capability_js_1.isRequestCapabilityEnabled)(config) && result instanceof mcp_js_1.McpServer) {
|
|
@@ -216,31 +179,14 @@ const withMcpAnalytics = (config, createServer) => {
|
|
|
216
179
|
catch (error) {
|
|
217
180
|
const collision = error instanceof Error && /already registered/i.test(error.message);
|
|
218
181
|
// A pre-existing tool of the same name is reserved only when the caller
|
|
219
|
-
// explicitly opted in; on
|
|
182
|
+
// explicitly opted in; on by default yields to the customer's tool.
|
|
220
183
|
if (collision && (0, request_capability_js_1.isRequestCapabilityExplicit)(config)) {
|
|
221
|
-
throw new Error(
|
|
184
|
+
throw new Error(`Tool name "${request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.sendFeedback is enabled.`, { cause: error });
|
|
222
185
|
}
|
|
223
186
|
if (!collision)
|
|
224
187
|
throw error;
|
|
225
188
|
}
|
|
226
189
|
}
|
|
227
|
-
// Tools registered on a server that does not list request_capability (the
|
|
228
|
-
// factory returned something else, or registered on another server) must
|
|
229
|
-
// not point agents at it.
|
|
230
|
-
ctx.resolved = true;
|
|
231
|
-
for (const hint of ctx.requestCapabilityHints) {
|
|
232
|
-
if (!listsRequestCapability(hint.server)
|
|
233
|
-
&& hint.tool !== null
|
|
234
|
-
&& typeof hint.tool === "object") {
|
|
235
|
-
const tool = hint.tool;
|
|
236
|
-
// Keep a description the factory updated after registration; only its
|
|
237
|
-
// hint changes.
|
|
238
|
-
tool.description = tool.description === hint.hintedDescription
|
|
239
|
-
? hint.fallbackDescription
|
|
240
|
-
: (0, schema_js_1.withoutRequestCapabilityHint)(tool.description, hint.toolName, hint.hintedDescription, hint.logLevel);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
ctx.requestCapabilityHints.length = 0;
|
|
244
190
|
return { result, recorder };
|
|
245
191
|
};
|
|
246
192
|
exports.withMcpAnalytics = withMcpAnalytics;
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export type TelemetryFieldMap = {
|
|
|
60
60
|
call_purpose?: string;
|
|
61
61
|
/** @deprecated Accepted for compatibility. Prefer call_purpose. */
|
|
62
62
|
agent_thinking?: string;
|
|
63
|
+
/** @deprecated `user_frustration` is no longer collected; this mapping is ignored. */
|
|
63
64
|
user_frustration?: string;
|
|
64
65
|
};
|
|
65
66
|
export type McpAnalyticsConfig = {
|
|
@@ -83,10 +84,12 @@ export type McpAnalyticsConfig = {
|
|
|
83
84
|
/** Register background work with a platform lifecycle primitive (for example waitUntil). */
|
|
84
85
|
schedule?: (work: Promise<void>) => void;
|
|
85
86
|
telemetryFieldMap?: TelemetryFieldMap;
|
|
87
|
+
sendFeedback?: boolean;
|
|
88
|
+
/** @deprecated Earlier name of `sendFeedback`; `sendFeedback` wins when both are set. */
|
|
86
89
|
requestCapability?: boolean;
|
|
87
90
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
91
|
+
* @deprecated The SDK no longer adds text to tool descriptions, so there
|
|
92
|
+
* is no length notice. Accepted and ignored.
|
|
90
93
|
*/
|
|
91
94
|
descriptionLengthLogLevel?: DescriptionLengthLogLevel;
|
|
92
95
|
};
|
|
@@ -108,12 +111,13 @@ export type TelemetryArgs = {
|
|
|
108
111
|
call_purpose?: string;
|
|
109
112
|
/** @deprecated Accepted for compatibility. Prefer call_purpose. */
|
|
110
113
|
agent_thinking?: string;
|
|
114
|
+
/** @deprecated No longer collected: accepted from cached clients and dropped. */
|
|
111
115
|
user_frustration?: "low" | "medium" | "high";
|
|
112
116
|
/** @deprecated Pre-V1 spelling of `user_intent`; still accepted. */
|
|
113
117
|
intent?: string;
|
|
114
118
|
/** @deprecated Pre-V1 spelling of `agent_thinking`; still accepted. */
|
|
115
119
|
context?: string;
|
|
116
|
-
/** @deprecated
|
|
120
|
+
/** @deprecated No longer collected: accepted from cached clients and dropped. */
|
|
117
121
|
frustration_level?: "low" | "medium" | "high";
|
|
118
122
|
};
|
|
119
123
|
export type ExtractedToolArguments = {
|
package/dist/cjs/v2.js
CHANGED
|
@@ -417,11 +417,8 @@ const instrumentRegisteredTool = (state, server, name, tool, defaults, options)
|
|
|
417
417
|
...(decoratedSchema !== undefined
|
|
418
418
|
? {
|
|
419
419
|
paramsSchema: decoratedSchema,
|
|
420
|
-
//
|
|
421
|
-
description: (0, schema_js_1.
|
|
422
|
-
toolName: name,
|
|
423
|
-
logLevel: state.config.armature?.descriptionLengthLogLevel,
|
|
424
|
-
}),
|
|
420
|
+
// Never adds text; removes SDK hint suffixes from earlier releases.
|
|
421
|
+
description: (0, schema_js_1.stripSdkDescriptionHint)(registered.description),
|
|
425
422
|
}
|
|
426
423
|
: {}),
|
|
427
424
|
callback: wrapToolCallback(state, name, originalHasInputSchema, registeredHasInputSchema, handler, defaults, options),
|
package/dist/esm/doctor.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
4
4
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
5
5
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
6
|
import { SDK_IDENTITY, SDK_USER_AGENT } from "./emit.js";
|
|
7
|
-
import { REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_TOOL_NAME, } from "./request-capability.js";
|
|
7
|
+
import { PAST_REQUEST_CAPABILITY_DESCRIPTIONS, REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_TOOL_NAME, LEGACY_REQUEST_CAPABILITY_TOOL_NAME, } from "./request-capability.js";
|
|
8
8
|
const DEFAULT_INGEST_URL = "https://app.armature.tech/api/mcp-analytics/ingest";
|
|
9
9
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
10
10
|
const CURRENT_TELEMETRY_MARKER = "Optional task context for usage analytics";
|
|
@@ -176,13 +176,17 @@ export const classifyToolInstrumentation = (tool) => {
|
|
|
176
176
|
}
|
|
177
177
|
return ownsTelemetryField ? "owned" : "missing";
|
|
178
178
|
};
|
|
179
|
-
// The SDK's own
|
|
180
|
-
// block on purpose (its input is already
|
|
179
|
+
// The SDK's own send_feedback tool (request_capability in earlier releases) is
|
|
180
|
+
// registered without a telemetry block on purpose (its input is already
|
|
181
|
+
// conversation-derived), so the
|
|
181
182
|
// wrapping check must not count it as an unwrapped customer tool. Match on
|
|
182
|
-
// the exact advertised description as well as the reserved
|
|
183
|
-
// customer-defined tool that merely shadows the name is still
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
// the exact advertised description (any release's) as well as the reserved
|
|
184
|
+
// name so a customer-defined tool that merely shadows the name is still
|
|
185
|
+
// checked.
|
|
186
|
+
const SDK_CAPABILITY_DESCRIPTIONS = new Set([REQUEST_CAPABILITY_DESCRIPTION, ...PAST_REQUEST_CAPABILITY_DESCRIPTIONS]);
|
|
187
|
+
export const isSdkOwnedCapabilityTool = (tool) => (tool.name === REQUEST_CAPABILITY_TOOL_NAME
|
|
188
|
+
|| tool.name === LEGACY_REQUEST_CAPABILITY_TOOL_NAME)
|
|
189
|
+
&& SDK_CAPABILITY_DESCRIPTIONS.has(tool.description || "");
|
|
186
190
|
export const inspectToolCoverage = (tools) => {
|
|
187
191
|
const current = [];
|
|
188
192
|
const legacy = [];
|
package/dist/esm/events.js
CHANGED
|
@@ -152,12 +152,13 @@ const assembleToolCallEvent = (candidate, input) => {
|
|
|
152
152
|
tool_name: candidate.toolName,
|
|
153
153
|
user_intent: t?.user_intent ?? null,
|
|
154
154
|
agent_thinking: t?.agent_thinking ?? null,
|
|
155
|
-
|
|
155
|
+
// No longer collected; kept null so older ingests read the same shape.
|
|
156
|
+
user_frustration: null,
|
|
156
157
|
// Legacy mirrors (pre-V1 key names) so an ingest that hasn't picked up
|
|
157
158
|
// the V1 schema keeps reading events from this SDK.
|
|
158
159
|
intent: t?.user_intent ?? null,
|
|
159
160
|
context: t?.agent_thinking ?? null,
|
|
160
|
-
frustration_level:
|
|
161
|
+
frustration_level: null,
|
|
161
162
|
input_preview: inputPreview.value,
|
|
162
163
|
...(input.capabilityRequest ? { capability_request: true } : {}),
|
|
163
164
|
},
|
package/dist/esm/fastmcp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createAnalyticsRecorderCore, } from "./recorder-core.js";
|
|
2
2
|
import { defaultMcpAnalyticsConfig } from "./emit.js";
|
|
3
|
-
import {
|
|
3
|
+
import { stripSdkDescriptionHint, createTelemetryJsonSchema, decorateInputSchemaWithTelemetry, isCaptureEnabled, schemaDeclaresTelemetry, } from "./schema.js";
|
|
4
4
|
import { headerValue, isRecord, mergeRequestExtra } from "./utils.js";
|
|
5
5
|
// Adapter for punkpeye/fastmcp (npm `fastmcp`, v1-SDK based). fastmcp routes
|
|
6
6
|
// tool calls through its own low-level `new Server(...)` +
|
|
@@ -396,11 +396,8 @@ const wrapFastmcpTool = (tool, state, runtime, options) => {
|
|
|
396
396
|
return {
|
|
397
397
|
...tool,
|
|
398
398
|
parameters: decoratedParameters,
|
|
399
|
-
//
|
|
400
|
-
description:
|
|
401
|
-
toolName: tool.name,
|
|
402
|
-
logLevel: state.config.armature?.descriptionLengthLogLevel,
|
|
403
|
-
}),
|
|
399
|
+
// Never adds text; removes SDK hint suffixes from earlier releases.
|
|
400
|
+
description: stripSdkDescriptionHint(tool.description),
|
|
404
401
|
execute: wrappedExecute,
|
|
405
402
|
};
|
|
406
403
|
};
|
package/dist/esm/mastra.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createAnalyticsRecorder } from "./recorder.js";
|
|
|
2
2
|
import { planToolTelemetry } from "./schema.js";
|
|
3
3
|
import { isRecord, mergeRequestExtra } from "./utils.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
5
|
+
import { REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION, REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_TOOL_NAME, isRequestCapabilityExplicit, } from "./request-capability.js";
|
|
6
6
|
const readMcpExtra = (mastraContext) => {
|
|
7
7
|
if (!isRecord(mastraContext))
|
|
8
8
|
return undefined;
|
|
@@ -61,7 +61,7 @@ export const defaultMastraResolveExtra = (mastraContext) => {
|
|
|
61
61
|
return Object.keys(result).length > 0 ? result : undefined;
|
|
62
62
|
};
|
|
63
63
|
const mergeExtra = mergeRequestExtra;
|
|
64
|
-
const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra
|
|
64
|
+
const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra) => {
|
|
65
65
|
if (typeof tool?.execute !== "function") {
|
|
66
66
|
return tool;
|
|
67
67
|
}
|
|
@@ -70,7 +70,7 @@ const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra, requestCapab
|
|
|
70
70
|
// Mastra tools without an inputSchema keep no schema (Mastra derives its own
|
|
71
71
|
// default); planToolTelemetry is only consulted for decoration when the tool
|
|
72
72
|
// has one, but its mode still drives extraction either way.
|
|
73
|
-
const plan = planToolTelemetry(toolName, tool.inputSchema, config
|
|
73
|
+
const plan = planToolTelemetry(toolName, tool.inputSchema, config);
|
|
74
74
|
const decoratedInputSchema = tool.inputSchema === undefined ? undefined : plan.inputSchema;
|
|
75
75
|
const wrappedExecute = (inputData, mastraContext) => {
|
|
76
76
|
// Always extract standard Mastra MCP context (`context.mcp.extra` or the
|
|
@@ -114,11 +114,9 @@ const wrapOneTool = (toolKey, tool, recorder, config, resolveExtra, requestCapab
|
|
|
114
114
|
// passes the constraint without a cast.
|
|
115
115
|
export const wrapMastraToolsWithRecorder = (tools, recorder, config = {}, options = {}) => {
|
|
116
116
|
const out = {};
|
|
117
|
-
// The recorder is the source of truth for whether
|
|
117
|
+
// The recorder is the source of truth for whether send_feedback exists:
|
|
118
118
|
// the high-level wrapMastraTools builds it from the same config, and direct
|
|
119
|
-
// callers may pass a lean wrap-time config that omits the delivery sink.
|
|
120
|
-
// that the tool is on by default, re-deriving enablement from that lean
|
|
121
|
-
// config would spuriously disagree with a recorder that has it.
|
|
119
|
+
// callers may pass a lean wrap-time config that omits the delivery sink.
|
|
122
120
|
const requestCapabilityEnabled = recorder.hasTool(REQUEST_CAPABILITY_TOOL_NAME);
|
|
123
121
|
const requestCapabilityCollision = requestCapabilityEnabled
|
|
124
122
|
&& Object.entries(tools).some(([key, tool]) => key === REQUEST_CAPABILITY_TOOL_NAME
|
|
@@ -126,12 +124,10 @@ export const wrapMastraToolsWithRecorder = (tools, recorder, config = {}, option
|
|
|
126
124
|
// A customer tool of the same name is reserved only when the caller
|
|
127
125
|
// explicitly opted in; when on by default it wins and the SDK skips its own.
|
|
128
126
|
if (requestCapabilityCollision && isRequestCapabilityExplicit(config)) {
|
|
129
|
-
throw new Error(`Tool name "${REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.
|
|
127
|
+
throw new Error(`Tool name "${REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.sendFeedback is enabled.`);
|
|
130
128
|
}
|
|
131
129
|
for (const [key, tool] of Object.entries(tools)) {
|
|
132
|
-
|
|
133
|
-
// exactly when the returned map carries one (ours or the customer's).
|
|
134
|
-
out[key] = wrapOneTool(key, tool, recorder, config, options.resolveExtra, requestCapabilityEnabled);
|
|
130
|
+
out[key] = wrapOneTool(key, tool, recorder, config, options.resolveExtra);
|
|
135
131
|
}
|
|
136
132
|
if (requestCapabilityEnabled && !requestCapabilityCollision) {
|
|
137
133
|
out[REQUEST_CAPABILITY_TOOL_NAME] = {
|
package/dist/esm/recorder.js
CHANGED
|
@@ -103,10 +103,8 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
103
103
|
// positional juggling below keys on what we actually registered, which for
|
|
104
104
|
// owned/scrub tools is the caller's original (possibly absent) schema.
|
|
105
105
|
const registeredHasInputSchema = plan.inputSchema !== undefined;
|
|
106
|
-
// Same
|
|
107
|
-
//
|
|
108
|
-
// telemetry.user_intent, or sessions arrive with no intent (ARM-24).
|
|
109
|
-
// Owned/scrub tools keep their original description untouched.
|
|
106
|
+
// Same description handling as `decorateDefinitions`: no added text, only
|
|
107
|
+
// earlier SDK hint suffixes removed. Owned/scrub tools keep theirs as is.
|
|
110
108
|
const description = plan.applyDescription(registration.description);
|
|
111
109
|
server.registerTool(registration.name, {
|
|
112
110
|
...(registration.title !== undefined ? { title: registration.title } : {}),
|
|
@@ -140,7 +138,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
140
138
|
// Reserved only when the caller explicitly opted in. When the tool is on
|
|
141
139
|
// merely by default, a customer tool of the same name takes precedence:
|
|
142
140
|
// fall through so this registration overwrites the SDK-owned entry.
|
|
143
|
-
throw new Error(`Tool name "${REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.
|
|
141
|
+
throw new Error(`Tool name "${REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.sendFeedback is enabled.`);
|
|
144
142
|
}
|
|
145
143
|
registeredTools.set(registration.name, {
|
|
146
144
|
registration,
|