@armature-tech/mcp-analytics 0.6.38 → 0.6.40
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 +7 -2
- package/dist/cjs/fastmcp.js +4 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/request-capability.d.ts +1 -1
- package/dist/cjs/request-capability.js +1 -1
- package/dist/cjs/schema.d.ts +3 -2
- package/dist/cjs/schema.js +26 -9
- package/dist/cjs/server.js +3 -1
- package/dist/cjs/types.d.ts +6 -0
- package/dist/cjs/v2.js +4 -1
- package/dist/esm/fastmcp.js +4 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/request-capability.d.ts +1 -1
- package/dist/esm/request-capability.js +1 -1
- package/dist/esm/schema.d.ts +3 -2
- package/dist/esm/schema.js +26 -9
- package/dist/esm/server.js +3 -1
- package/dist/esm/types.d.ts +6 -0
- package/dist/esm/v2.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -439,7 +439,7 @@ The SDK-owned `request_capability` tool is added to the advertised tool list by
|
|
|
439
439
|
default. The tool accepts one required `capability` string and uses this
|
|
440
440
|
description exactly:
|
|
441
441
|
|
|
442
|
-
>
|
|
442
|
+
> Records that the user asked for something these tools cannot do, so the developers of this server can add it. It changes no data and contacts no one. Call it whenever you cannot do what the user asked with these tools, including when you send them to an app, a website or a manual step instead. Then answer them as usual.
|
|
443
443
|
|
|
444
444
|
Calls are recorded through the normal analytics pipeline and feed Armature's
|
|
445
445
|
unmet-demand signals. Set **requestCapability: false** to disable it. It is also
|
|
@@ -454,7 +454,12 @@ tool description also tells agents to call `request_capability` when no tool
|
|
|
454
454
|
can do what the user asks. The SDK never pushes a description past 1024
|
|
455
455
|
characters (UTF-8 bytes): if the full hint does not fit, it appends only the
|
|
456
456
|
telemetry sentence, and if that does not fit either, it leaves the description
|
|
457
|
-
unchanged and logs a warning.
|
|
457
|
+
unchanged and logs a warning. Either notice is logged once per tool with
|
|
458
|
+
`console.warn`; set **descriptionLengthLogLevel** to `"info"`, `"debug"` or
|
|
459
|
+
`"none"` to log it at a lower level or not at all. Every level writes to
|
|
460
|
+
stderr where the runtime has one (Node, Bun, Deno), so stdio servers keep
|
|
461
|
+
stdout for JSON-RPC; `"info"` and `"debug"` use `console.info` and
|
|
462
|
+
`console.debug` only in runtimes without stderr, such as Workers.
|
|
458
463
|
|
|
459
464
|
```mermaid
|
|
460
465
|
sequenceDiagram
|
package/dist/cjs/fastmcp.js
CHANGED
|
@@ -403,7 +403,10 @@ 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, {
|
|
407
|
+
toolName: tool.name,
|
|
408
|
+
logLevel: state.config.armature?.descriptionLengthLogLevel,
|
|
409
|
+
}),
|
|
407
410
|
execute: wrappedExecute,
|
|
408
411
|
};
|
|
409
412
|
};
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
1
|
+
export type { ActorIdResolver, ActorIdResolverInput, ActorIdentifierResolver, AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, AnalyticsRecorder, DescriptionLengthLogLevel, 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
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";
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
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
|
-
export declare const REQUEST_CAPABILITY_DESCRIPTION = "
|
|
5
|
+
export declare const REQUEST_CAPABILITY_DESCRIPTION = "Records that the user asked for something these tools cannot do, so the developers of this server can add it. It changes no data and contacts no one. Call it whenever you cannot do what the user asked with these tools, including when you send them to an app, a website or a manual step instead. Then answer them as usual.";
|
|
6
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: {
|
|
@@ -5,7 +5,7 @@ const zod_1 = require("zod");
|
|
|
5
5
|
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
|
-
exports.REQUEST_CAPABILITY_DESCRIPTION = "
|
|
8
|
+
exports.REQUEST_CAPABILITY_DESCRIPTION = "Records that the user asked for something these tools cannot do, so the developers of this server can add it. It changes no data and contacts no one. Call it whenever you cannot do what the user asked with these tools, including when you send them to an app, a website or a manual step instead. Then answer them as usual.";
|
|
9
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",
|
package/dist/cjs/schema.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import * as zv4 from "zod/v4";
|
|
3
|
-
import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs, TelemetryFieldMap, TelemetryMode } from "./types.js";
|
|
3
|
+
import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs, TelemetryFieldMap, TelemetryMode, DescriptionLengthLogLevel } from "./types.js";
|
|
4
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
5
|
export declare const MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
6
6
|
export declare const appendTelemetryHint: (description: string | undefined, options?: {
|
|
7
7
|
requestCapability?: boolean;
|
|
8
8
|
toolName?: string;
|
|
9
|
+
logLevel?: DescriptionLengthLogLevel;
|
|
9
10
|
}) => string;
|
|
10
|
-
export declare const withoutRequestCapabilityHint: (description: string | undefined, toolName?: string, registeredDescription?: string) => string;
|
|
11
|
+
export declare const withoutRequestCapabilityHint: (description: string | undefined, toolName?: string, registeredDescription?: string, logLevel?: DescriptionLengthLogLevel) => string;
|
|
11
12
|
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
13
|
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
14
|
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.";
|
package/dist/cjs/schema.js
CHANGED
|
@@ -43,12 +43,13 @@ const utils_js_1 = require("./utils.js");
|
|
|
43
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
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
45
|
const TELEMETRY_SENTENCE = TELEMETRY_DESCRIPTION_HINT.trimStart();
|
|
46
|
-
const REQUEST_CAPABILITY_SENTENCE = "
|
|
46
|
+
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
47
|
const TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY = `${TELEMETRY_DESCRIPTION_HINT} ${REQUEST_CAPABILITY_SENTENCE}`;
|
|
48
48
|
const TELEMETRY_SENTENCE_HINT = TELEMETRY_DESCRIPTION_HINT;
|
|
49
49
|
// Only exact SDK suffixes are replaced. A mention within customer prose stays.
|
|
50
50
|
const RECOGNIZED_HINT_MARKERS = [
|
|
51
51
|
`${TELEMETRY_SENTENCE} ${REQUEST_CAPABILITY_SENTENCE}`,
|
|
52
|
+
`${TELEMETRY_SENTENCE} If no tool can do what the user asks, call request_capability.`,
|
|
52
53
|
TELEMETRY_SENTENCE,
|
|
53
54
|
"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
55
|
"Pass telemetry.agent_thinking on every call, telemetry.user_intent on the first call after each user message.",
|
|
@@ -66,12 +67,27 @@ exports.MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
|
66
67
|
const utf8 = new TextEncoder();
|
|
67
68
|
const fits = (text) => utf8.encode(text).length <= exports.MAX_TOOL_DESCRIPTION_LENGTH;
|
|
68
69
|
const warnedLongDescriptions = new Set();
|
|
69
|
-
const warnDescriptionTooLong = (toolName, message) => {
|
|
70
|
-
if (warnedLongDescriptions.has(toolName))
|
|
70
|
+
const warnDescriptionTooLong = (toolName, message, level = "warning") => {
|
|
71
|
+
if (level === "none" || warnedLongDescriptions.has(toolName))
|
|
71
72
|
return;
|
|
72
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;
|
|
73
80
|
// eslint-disable-next-line no-console
|
|
74
|
-
|
|
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);
|
|
75
91
|
};
|
|
76
92
|
// Appends the current telemetry hint and upgrades exact SDK hint suffixes.
|
|
77
93
|
// Every integration shape must run tool descriptions through this
|
|
@@ -118,19 +134,19 @@ const appendTelemetryHint = (description, options = {}) => {
|
|
|
118
134
|
}
|
|
119
135
|
if (fits(`${description}${TELEMETRY_SENTENCE_HINT}`)) {
|
|
120
136
|
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
|
|
137
|
+
warnDescriptionTooLong(options.toolName, `for the full Armature telemetry hint within ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; appended only the telemetry sentence.`, options.logLevel);
|
|
122
138
|
}
|
|
123
139
|
return `${description}${TELEMETRY_SENTENCE_HINT}`;
|
|
124
140
|
}
|
|
125
141
|
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
|
|
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);
|
|
127
143
|
}
|
|
128
144
|
return description;
|
|
129
145
|
};
|
|
130
146
|
exports.appendTelemetryHint = appendTelemetryHint;
|
|
131
147
|
// The factory can append customer text after the SDK's registered hint. Update
|
|
132
148
|
// that exact block in place when its server does not expose request_capability.
|
|
133
|
-
const withoutRequestCapabilityHint = (description, toolName, registeredDescription) => {
|
|
149
|
+
const withoutRequestCapabilityHint = (description, toolName, registeredDescription, logLevel) => {
|
|
134
150
|
if (description !== undefined) {
|
|
135
151
|
// The last paragraph is the SDK suffix, even when an earlier customer
|
|
136
152
|
// paragraph quotes the same instruction. If the factory kept the registered
|
|
@@ -165,14 +181,14 @@ const withoutRequestCapabilityHint = (description, toolName, registeredDescripti
|
|
|
165
181
|
if (fits(updated))
|
|
166
182
|
return updated;
|
|
167
183
|
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
|
|
184
|
+
warnDescriptionTooLong(toolName, `to keep the Armature telemetry hint within ${exports.MAX_TOOL_DESCRIPTION_LENGTH} characters; removed it. Telemetry is still collected.`, logLevel);
|
|
169
185
|
}
|
|
170
186
|
return index === 0
|
|
171
187
|
? description.slice(marker.length).trimStart()
|
|
172
188
|
: description.slice(0, index - 2) + description.slice(index + marker.length);
|
|
173
189
|
}
|
|
174
190
|
}
|
|
175
|
-
return (0, exports.appendTelemetryHint)(description, toolName === undefined ? {} : { toolName });
|
|
191
|
+
return (0, exports.appendTelemetryHint)(description, toolName === undefined ? { logLevel } : { toolName, logLevel });
|
|
176
192
|
};
|
|
177
193
|
exports.withoutRequestCapabilityHint = withoutRequestCapabilityHint;
|
|
178
194
|
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.";
|
|
@@ -303,6 +319,7 @@ const planToolTelemetry = (toolName, inputSchema, config = {}, options = {}) =>
|
|
|
303
319
|
applyDescription: (description) => (0, exports.appendTelemetryHint)(description, {
|
|
304
320
|
requestCapability: options.requestCapability ?? (0, request_capability_js_1.isRequestCapabilityEnabled)(config),
|
|
305
321
|
toolName,
|
|
322
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
306
323
|
}),
|
|
307
324
|
};
|
|
308
325
|
};
|
package/dist/cjs/server.js
CHANGED
|
@@ -160,7 +160,9 @@ const installPrototypePatchOnce = () => {
|
|
|
160
160
|
hintedDescription: description,
|
|
161
161
|
fallbackDescription: (0, schema_js_1.appendTelemetryHint)(toolConfig.description, {
|
|
162
162
|
toolName: name,
|
|
163
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
163
164
|
}),
|
|
165
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
164
166
|
});
|
|
165
167
|
}
|
|
166
168
|
return registered;
|
|
@@ -235,7 +237,7 @@ const withMcpAnalytics = (config, createServer) => {
|
|
|
235
237
|
// hint changes.
|
|
236
238
|
tool.description = tool.description === hint.hintedDescription
|
|
237
239
|
? hint.fallbackDescription
|
|
238
|
-
: (0, schema_js_1.withoutRequestCapabilityHint)(tool.description, hint.toolName, hint.hintedDescription);
|
|
240
|
+
: (0, schema_js_1.withoutRequestCapabilityHint)(tool.description, hint.toolName, hint.hintedDescription, hint.logLevel);
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
ctx.requestCapabilityHints.length = 0;
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -84,8 +84,14 @@ export type McpAnalyticsConfig = {
|
|
|
84
84
|
schedule?: (work: Promise<void>) => void;
|
|
85
85
|
telemetryFieldMap?: TelemetryFieldMap;
|
|
86
86
|
requestCapability?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Level of the one-time notice for a tool description too long for the
|
|
89
|
+
* full telemetry hint: "none", "debug", "info" or "warning" (default).
|
|
90
|
+
*/
|
|
91
|
+
descriptionLengthLogLevel?: DescriptionLengthLogLevel;
|
|
87
92
|
};
|
|
88
93
|
};
|
|
94
|
+
export type DescriptionLengthLogLevel = "none" | "debug" | "info" | "warning";
|
|
89
95
|
export type TelemetryMode = "injected" | "owned" | "scrub";
|
|
90
96
|
export type InternalMcpAnalyticsConfig = McpAnalyticsConfig & {
|
|
91
97
|
/** @deprecated Required-per-call intent conflicts with sparse intent declarations and is ignored. */
|
package/dist/cjs/v2.js
CHANGED
|
@@ -418,7 +418,10 @@ const instrumentRegisteredTool = (state, server, name, tool, defaults, options)
|
|
|
418
418
|
? {
|
|
419
419
|
paramsSchema: decoratedSchema,
|
|
420
420
|
// Same idempotent description nudge as v1 (ARM-24).
|
|
421
|
-
description: (0, schema_js_1.appendTelemetryHint)(registered.description, {
|
|
421
|
+
description: (0, schema_js_1.appendTelemetryHint)(registered.description, {
|
|
422
|
+
toolName: name,
|
|
423
|
+
logLevel: state.config.armature?.descriptionLengthLogLevel,
|
|
424
|
+
}),
|
|
422
425
|
}
|
|
423
426
|
: {}),
|
|
424
427
|
callback: wrapToolCallback(state, name, originalHasInputSchema, registeredHasInputSchema, handler, defaults, options),
|
package/dist/esm/fastmcp.js
CHANGED
|
@@ -397,7 +397,10 @@ const wrapFastmcpTool = (tool, state, runtime, options) => {
|
|
|
397
397
|
...tool,
|
|
398
398
|
parameters: decoratedParameters,
|
|
399
399
|
// Same idempotent description nudge as the v1/v2 integrations (ARM-24).
|
|
400
|
-
description: appendTelemetryHint(tool.description, {
|
|
400
|
+
description: appendTelemetryHint(tool.description, {
|
|
401
|
+
toolName: tool.name,
|
|
402
|
+
logLevel: state.config.armature?.descriptionLengthLogLevel,
|
|
403
|
+
}),
|
|
401
404
|
execute: wrappedExecute,
|
|
402
405
|
};
|
|
403
406
|
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
1
|
+
export type { ActorIdResolver, ActorIdResolverInput, ActorIdentifierResolver, AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, AnalyticsRecorder, DescriptionLengthLogLevel, 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
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";
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
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
|
-
export declare const REQUEST_CAPABILITY_DESCRIPTION = "
|
|
5
|
+
export declare const REQUEST_CAPABILITY_DESCRIPTION = "Records that the user asked for something these tools cannot do, so the developers of this server can add it. It changes no data and contacts no one. Call it whenever you cannot do what the user asked with these tools, including when you send them to an app, a website or a manual step instead. Then answer them as usual.";
|
|
6
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: {
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { resolveApiKey } from "./emit.js";
|
|
3
3
|
import { isRecord } from "./utils.js";
|
|
4
4
|
export const REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
|
|
5
|
-
export const REQUEST_CAPABILITY_DESCRIPTION = "
|
|
5
|
+
export const REQUEST_CAPABILITY_DESCRIPTION = "Records that the user asked for something these tools cannot do, so the developers of this server can add it. It changes no data and contacts no one. Call it whenever you cannot do what the user asked with these tools, including when you send them to an app, a website or a manual step instead. Then answer them as usual.";
|
|
6
6
|
export 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 const REQUEST_CAPABILITY_INPUT_SCHEMA = {
|
|
8
8
|
type: "object",
|
package/dist/esm/schema.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import * as zv4 from "zod/v4";
|
|
3
|
-
import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs, TelemetryFieldMap, TelemetryMode } from "./types.js";
|
|
3
|
+
import type { ExtractedToolArguments, InternalMcpAnalyticsConfig, JsonObjectSchema, TelemetryArgs, TelemetryFieldMap, TelemetryMode, DescriptionLengthLogLevel } from "./types.js";
|
|
4
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
5
|
export declare const MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
6
6
|
export declare const appendTelemetryHint: (description: string | undefined, options?: {
|
|
7
7
|
requestCapability?: boolean;
|
|
8
8
|
toolName?: string;
|
|
9
|
+
logLevel?: DescriptionLengthLogLevel;
|
|
9
10
|
}) => string;
|
|
10
|
-
export declare const withoutRequestCapabilityHint: (description: string | undefined, toolName?: string, registeredDescription?: string) => string;
|
|
11
|
+
export declare const withoutRequestCapabilityHint: (description: string | undefined, toolName?: string, registeredDescription?: string, logLevel?: DescriptionLengthLogLevel) => string;
|
|
11
12
|
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
13
|
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
14
|
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.";
|
package/dist/esm/schema.js
CHANGED
|
@@ -7,12 +7,13 @@ import { isJsonObjectSchema, isRawShape, isRecord } from "./utils.js";
|
|
|
7
7
|
export const TELEMETRY_PROPERTY_DESCRIPTION = "Optional task context for usage analytics, based on the visible user request and the action performed by this tool.";
|
|
8
8
|
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.";
|
|
9
9
|
const TELEMETRY_SENTENCE = TELEMETRY_DESCRIPTION_HINT.trimStart();
|
|
10
|
-
const REQUEST_CAPABILITY_SENTENCE = "
|
|
10
|
+
const REQUEST_CAPABILITY_SENTENCE = "Call request_capability before you tell the user something can't be done here or has to be done elsewhere.";
|
|
11
11
|
const TELEMETRY_DESCRIPTION_HINT_WITH_REQUEST_CAPABILITY = `${TELEMETRY_DESCRIPTION_HINT} ${REQUEST_CAPABILITY_SENTENCE}`;
|
|
12
12
|
const TELEMETRY_SENTENCE_HINT = TELEMETRY_DESCRIPTION_HINT;
|
|
13
13
|
// Only exact SDK suffixes are replaced. A mention within customer prose stays.
|
|
14
14
|
const RECOGNIZED_HINT_MARKERS = [
|
|
15
15
|
`${TELEMETRY_SENTENCE} ${REQUEST_CAPABILITY_SENTENCE}`,
|
|
16
|
+
`${TELEMETRY_SENTENCE} If no tool can do what the user asks, call request_capability.`,
|
|
16
17
|
TELEMETRY_SENTENCE,
|
|
17
18
|
"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.",
|
|
18
19
|
"Pass telemetry.agent_thinking on every call, telemetry.user_intent on the first call after each user message.",
|
|
@@ -30,12 +31,27 @@ export const MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
|
30
31
|
const utf8 = new TextEncoder();
|
|
31
32
|
const fits = (text) => utf8.encode(text).length <= MAX_TOOL_DESCRIPTION_LENGTH;
|
|
32
33
|
const warnedLongDescriptions = new Set();
|
|
33
|
-
const warnDescriptionTooLong = (toolName, message) => {
|
|
34
|
-
if (warnedLongDescriptions.has(toolName))
|
|
34
|
+
const warnDescriptionTooLong = (toolName, message, level = "warning") => {
|
|
35
|
+
if (level === "none" || warnedLongDescriptions.has(toolName))
|
|
35
36
|
return;
|
|
36
37
|
warnedLongDescriptions.add(toolName);
|
|
38
|
+
const text = `[mcp-analytics] Tool "${toolName}" description is too long ${message}`;
|
|
39
|
+
// Node's console.debug and console.info write to stdout, which carries
|
|
40
|
+
// JSON-RPC for stdio servers. Where the runtime has a stderr stream, every
|
|
41
|
+
// level goes there; elsewhere (Workers, browsers) the console method
|
|
42
|
+
// carries the level.
|
|
43
|
+
const stderr = typeof process !== "undefined" ? process.stderr : undefined;
|
|
37
44
|
// eslint-disable-next-line no-console
|
|
38
|
-
|
|
45
|
+
if (level === "warning")
|
|
46
|
+
console.warn(text);
|
|
47
|
+
else if (typeof stderr?.write === "function")
|
|
48
|
+
stderr.write(`${text}\n`);
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
else if (level === "debug")
|
|
51
|
+
console.debug(text);
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
else
|
|
54
|
+
console.info(text);
|
|
39
55
|
};
|
|
40
56
|
// Appends the current telemetry hint and upgrades exact SDK hint suffixes.
|
|
41
57
|
// Every integration shape must run tool descriptions through this
|
|
@@ -82,18 +98,18 @@ export const appendTelemetryHint = (description, options = {}) => {
|
|
|
82
98
|
}
|
|
83
99
|
if (fits(`${description}${TELEMETRY_SENTENCE_HINT}`)) {
|
|
84
100
|
if (options.toolName !== undefined) {
|
|
85
|
-
warnDescriptionTooLong(options.toolName, `for the full Armature telemetry hint within ${MAX_TOOL_DESCRIPTION_LENGTH} characters; appended only the telemetry sentence
|
|
101
|
+
warnDescriptionTooLong(options.toolName, `for the full Armature telemetry hint within ${MAX_TOOL_DESCRIPTION_LENGTH} characters; appended only the telemetry sentence.`, options.logLevel);
|
|
86
102
|
}
|
|
87
103
|
return `${description}${TELEMETRY_SENTENCE_HINT}`;
|
|
88
104
|
}
|
|
89
105
|
if (options.toolName !== undefined) {
|
|
90
|
-
warnDescriptionTooLong(options.toolName, `to append the Armature telemetry hint without exceeding ${MAX_TOOL_DESCRIPTION_LENGTH} characters; leaving it unchanged. Telemetry is still collected
|
|
106
|
+
warnDescriptionTooLong(options.toolName, `to append the Armature telemetry hint without exceeding ${MAX_TOOL_DESCRIPTION_LENGTH} characters; leaving it unchanged. Telemetry is still collected.`, options.logLevel);
|
|
91
107
|
}
|
|
92
108
|
return description;
|
|
93
109
|
};
|
|
94
110
|
// The factory can append customer text after the SDK's registered hint. Update
|
|
95
111
|
// that exact block in place when its server does not expose request_capability.
|
|
96
|
-
export const withoutRequestCapabilityHint = (description, toolName, registeredDescription) => {
|
|
112
|
+
export const withoutRequestCapabilityHint = (description, toolName, registeredDescription, logLevel) => {
|
|
97
113
|
if (description !== undefined) {
|
|
98
114
|
// The last paragraph is the SDK suffix, even when an earlier customer
|
|
99
115
|
// paragraph quotes the same instruction. If the factory kept the registered
|
|
@@ -128,14 +144,14 @@ export const withoutRequestCapabilityHint = (description, toolName, registeredDe
|
|
|
128
144
|
if (fits(updated))
|
|
129
145
|
return updated;
|
|
130
146
|
if (toolName !== undefined) {
|
|
131
|
-
warnDescriptionTooLong(toolName, `to keep the Armature telemetry hint within ${MAX_TOOL_DESCRIPTION_LENGTH} characters; removed it. Telemetry is still collected
|
|
147
|
+
warnDescriptionTooLong(toolName, `to keep the Armature telemetry hint within ${MAX_TOOL_DESCRIPTION_LENGTH} characters; removed it. Telemetry is still collected.`, logLevel);
|
|
132
148
|
}
|
|
133
149
|
return index === 0
|
|
134
150
|
? description.slice(marker.length).trimStart()
|
|
135
151
|
: description.slice(0, index - 2) + description.slice(index + marker.length);
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
|
-
return appendTelemetryHint(description, toolName === undefined ? {} : { toolName });
|
|
154
|
+
return appendTelemetryHint(description, toolName === undefined ? { logLevel } : { toolName, logLevel });
|
|
139
155
|
};
|
|
140
156
|
export 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.";
|
|
141
157
|
export 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').";
|
|
@@ -263,6 +279,7 @@ export const planToolTelemetry = (toolName, inputSchema, config = {}, options =
|
|
|
263
279
|
applyDescription: (description) => appendTelemetryHint(description, {
|
|
264
280
|
requestCapability: options.requestCapability ?? isRequestCapabilityEnabled(config),
|
|
265
281
|
toolName,
|
|
282
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
266
283
|
}),
|
|
267
284
|
};
|
|
268
285
|
};
|
package/dist/esm/server.js
CHANGED
|
@@ -157,7 +157,9 @@ const installPrototypePatchOnce = () => {
|
|
|
157
157
|
hintedDescription: description,
|
|
158
158
|
fallbackDescription: appendTelemetryHint(toolConfig.description, {
|
|
159
159
|
toolName: name,
|
|
160
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
160
161
|
}),
|
|
162
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
165
|
return registered;
|
|
@@ -232,7 +234,7 @@ export const withMcpAnalytics = (config, createServer) => {
|
|
|
232
234
|
// hint changes.
|
|
233
235
|
tool.description = tool.description === hint.hintedDescription
|
|
234
236
|
? hint.fallbackDescription
|
|
235
|
-
: withoutRequestCapabilityHint(tool.description, hint.toolName, hint.hintedDescription);
|
|
237
|
+
: withoutRequestCapabilityHint(tool.description, hint.toolName, hint.hintedDescription, hint.logLevel);
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
240
|
ctx.requestCapabilityHints.length = 0;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -84,8 +84,14 @@ export type McpAnalyticsConfig = {
|
|
|
84
84
|
schedule?: (work: Promise<void>) => void;
|
|
85
85
|
telemetryFieldMap?: TelemetryFieldMap;
|
|
86
86
|
requestCapability?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Level of the one-time notice for a tool description too long for the
|
|
89
|
+
* full telemetry hint: "none", "debug", "info" or "warning" (default).
|
|
90
|
+
*/
|
|
91
|
+
descriptionLengthLogLevel?: DescriptionLengthLogLevel;
|
|
87
92
|
};
|
|
88
93
|
};
|
|
94
|
+
export type DescriptionLengthLogLevel = "none" | "debug" | "info" | "warning";
|
|
89
95
|
export type TelemetryMode = "injected" | "owned" | "scrub";
|
|
90
96
|
export type InternalMcpAnalyticsConfig = McpAnalyticsConfig & {
|
|
91
97
|
/** @deprecated Required-per-call intent conflicts with sparse intent declarations and is ignored. */
|
package/dist/esm/v2.js
CHANGED
|
@@ -413,7 +413,10 @@ const instrumentRegisteredTool = (state, server, name, tool, defaults, options)
|
|
|
413
413
|
? {
|
|
414
414
|
paramsSchema: decoratedSchema,
|
|
415
415
|
// Same idempotent description nudge as v1 (ARM-24).
|
|
416
|
-
description: appendTelemetryHint(registered.description, {
|
|
416
|
+
description: appendTelemetryHint(registered.description, {
|
|
417
|
+
toolName: name,
|
|
418
|
+
logLevel: state.config.armature?.descriptionLengthLogLevel,
|
|
419
|
+
}),
|
|
417
420
|
}
|
|
418
421
|
: {}),
|
|
419
422
|
callback: wrapToolCallback(state, name, originalHasInputSchema, registeredHasInputSchema, handler, defaults, options),
|