@armature-tech/mcp-analytics 0.6.39 → 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 +6 -1
- package/dist/cjs/fastmcp.js +4 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/schema.d.ts +3 -2
- package/dist/cjs/schema.js +24 -8
- 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/schema.d.ts +3 -2
- package/dist/esm/schema.js +24 -8
- 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
|
@@ -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";
|
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
|
@@ -67,12 +67,27 @@ exports.MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
|
67
67
|
const utf8 = new TextEncoder();
|
|
68
68
|
const fits = (text) => utf8.encode(text).length <= exports.MAX_TOOL_DESCRIPTION_LENGTH;
|
|
69
69
|
const warnedLongDescriptions = new Set();
|
|
70
|
-
const warnDescriptionTooLong = (toolName, message) => {
|
|
71
|
-
if (warnedLongDescriptions.has(toolName))
|
|
70
|
+
const warnDescriptionTooLong = (toolName, message, level = "warning") => {
|
|
71
|
+
if (level === "none" || warnedLongDescriptions.has(toolName))
|
|
72
72
|
return;
|
|
73
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;
|
|
74
80
|
// eslint-disable-next-line no-console
|
|
75
|
-
|
|
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);
|
|
76
91
|
};
|
|
77
92
|
// Appends the current telemetry hint and upgrades exact SDK hint suffixes.
|
|
78
93
|
// Every integration shape must run tool descriptions through this
|
|
@@ -119,19 +134,19 @@ const appendTelemetryHint = (description, options = {}) => {
|
|
|
119
134
|
}
|
|
120
135
|
if (fits(`${description}${TELEMETRY_SENTENCE_HINT}`)) {
|
|
121
136
|
if (options.toolName !== undefined) {
|
|
122
|
-
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);
|
|
123
138
|
}
|
|
124
139
|
return `${description}${TELEMETRY_SENTENCE_HINT}`;
|
|
125
140
|
}
|
|
126
141
|
if (options.toolName !== undefined) {
|
|
127
|
-
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);
|
|
128
143
|
}
|
|
129
144
|
return description;
|
|
130
145
|
};
|
|
131
146
|
exports.appendTelemetryHint = appendTelemetryHint;
|
|
132
147
|
// The factory can append customer text after the SDK's registered hint. Update
|
|
133
148
|
// that exact block in place when its server does not expose request_capability.
|
|
134
|
-
const withoutRequestCapabilityHint = (description, toolName, registeredDescription) => {
|
|
149
|
+
const withoutRequestCapabilityHint = (description, toolName, registeredDescription, logLevel) => {
|
|
135
150
|
if (description !== undefined) {
|
|
136
151
|
// The last paragraph is the SDK suffix, even when an earlier customer
|
|
137
152
|
// paragraph quotes the same instruction. If the factory kept the registered
|
|
@@ -166,14 +181,14 @@ const withoutRequestCapabilityHint = (description, toolName, registeredDescripti
|
|
|
166
181
|
if (fits(updated))
|
|
167
182
|
return updated;
|
|
168
183
|
if (toolName !== undefined) {
|
|
169
|
-
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);
|
|
170
185
|
}
|
|
171
186
|
return index === 0
|
|
172
187
|
? description.slice(marker.length).trimStart()
|
|
173
188
|
: description.slice(0, index - 2) + description.slice(index + marker.length);
|
|
174
189
|
}
|
|
175
190
|
}
|
|
176
|
-
return (0, exports.appendTelemetryHint)(description, toolName === undefined ? {} : { toolName });
|
|
191
|
+
return (0, exports.appendTelemetryHint)(description, toolName === undefined ? { logLevel } : { toolName, logLevel });
|
|
177
192
|
};
|
|
178
193
|
exports.withoutRequestCapabilityHint = withoutRequestCapabilityHint;
|
|
179
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.";
|
|
@@ -304,6 +319,7 @@ const planToolTelemetry = (toolName, inputSchema, config = {}, options = {}) =>
|
|
|
304
319
|
applyDescription: (description) => (0, exports.appendTelemetryHint)(description, {
|
|
305
320
|
requestCapability: options.requestCapability ?? (0, request_capability_js_1.isRequestCapabilityEnabled)(config),
|
|
306
321
|
toolName,
|
|
322
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
307
323
|
}),
|
|
308
324
|
};
|
|
309
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";
|
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
|
@@ -31,12 +31,27 @@ export const MAX_TOOL_DESCRIPTION_LENGTH = 1024;
|
|
|
31
31
|
const utf8 = new TextEncoder();
|
|
32
32
|
const fits = (text) => utf8.encode(text).length <= MAX_TOOL_DESCRIPTION_LENGTH;
|
|
33
33
|
const warnedLongDescriptions = new Set();
|
|
34
|
-
const warnDescriptionTooLong = (toolName, message) => {
|
|
35
|
-
if (warnedLongDescriptions.has(toolName))
|
|
34
|
+
const warnDescriptionTooLong = (toolName, message, level = "warning") => {
|
|
35
|
+
if (level === "none" || warnedLongDescriptions.has(toolName))
|
|
36
36
|
return;
|
|
37
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;
|
|
38
44
|
// eslint-disable-next-line no-console
|
|
39
|
-
|
|
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);
|
|
40
55
|
};
|
|
41
56
|
// Appends the current telemetry hint and upgrades exact SDK hint suffixes.
|
|
42
57
|
// Every integration shape must run tool descriptions through this
|
|
@@ -83,18 +98,18 @@ export const appendTelemetryHint = (description, options = {}) => {
|
|
|
83
98
|
}
|
|
84
99
|
if (fits(`${description}${TELEMETRY_SENTENCE_HINT}`)) {
|
|
85
100
|
if (options.toolName !== undefined) {
|
|
86
|
-
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);
|
|
87
102
|
}
|
|
88
103
|
return `${description}${TELEMETRY_SENTENCE_HINT}`;
|
|
89
104
|
}
|
|
90
105
|
if (options.toolName !== undefined) {
|
|
91
|
-
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);
|
|
92
107
|
}
|
|
93
108
|
return description;
|
|
94
109
|
};
|
|
95
110
|
// The factory can append customer text after the SDK's registered hint. Update
|
|
96
111
|
// that exact block in place when its server does not expose request_capability.
|
|
97
|
-
export const withoutRequestCapabilityHint = (description, toolName, registeredDescription) => {
|
|
112
|
+
export const withoutRequestCapabilityHint = (description, toolName, registeredDescription, logLevel) => {
|
|
98
113
|
if (description !== undefined) {
|
|
99
114
|
// The last paragraph is the SDK suffix, even when an earlier customer
|
|
100
115
|
// paragraph quotes the same instruction. If the factory kept the registered
|
|
@@ -129,14 +144,14 @@ export const withoutRequestCapabilityHint = (description, toolName, registeredDe
|
|
|
129
144
|
if (fits(updated))
|
|
130
145
|
return updated;
|
|
131
146
|
if (toolName !== undefined) {
|
|
132
|
-
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);
|
|
133
148
|
}
|
|
134
149
|
return index === 0
|
|
135
150
|
? description.slice(marker.length).trimStart()
|
|
136
151
|
: description.slice(0, index - 2) + description.slice(index + marker.length);
|
|
137
152
|
}
|
|
138
153
|
}
|
|
139
|
-
return appendTelemetryHint(description, toolName === undefined ? {} : { toolName });
|
|
154
|
+
return appendTelemetryHint(description, toolName === undefined ? { logLevel } : { toolName, logLevel });
|
|
140
155
|
};
|
|
141
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.";
|
|
142
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').";
|
|
@@ -264,6 +279,7 @@ export const planToolTelemetry = (toolName, inputSchema, config = {}, options =
|
|
|
264
279
|
applyDescription: (description) => appendTelemetryHint(description, {
|
|
265
280
|
requestCapability: options.requestCapability ?? isRequestCapabilityEnabled(config),
|
|
266
281
|
toolName,
|
|
282
|
+
logLevel: config.armature?.descriptionLengthLogLevel,
|
|
267
283
|
}),
|
|
268
284
|
};
|
|
269
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),
|