@armature-tech/mcp-analytics 0.6.39 → 0.6.41
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 +11 -1
- package/dist/cjs/fastmcp.js +4 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/recorder.js +2 -0
- package/dist/cjs/request-capability.d.ts +7 -0
- package/dist/cjs/request-capability.js +12 -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/recorder.js +3 -1
- package/dist/esm/request-capability.d.ts +7 -0
- package/dist/esm/request-capability.js +11 -0
- 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
|
@@ -441,6 +441,11 @@ 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
|
+
It declares the annotations app directories such as ChatGPT's require:
|
|
445
|
+
`readOnlyHint: false` (it records an analytics event), `destructiveHint: false`
|
|
446
|
+
(it changes no user data) and `openWorldHint: false` (it contacts no one), plus
|
|
447
|
+
`idempotentHint: false` and the title "Request capability".
|
|
448
|
+
|
|
444
449
|
Calls are recorded through the normal analytics pipeline and feed Armature's
|
|
445
450
|
unmet-demand signals. Set **requestCapability: false** to disable it. It is also
|
|
446
451
|
suppressed when **enabled: false** or no API key/custom **emit** delivery is
|
|
@@ -454,7 +459,12 @@ tool description also tells agents to call `request_capability` when no tool
|
|
|
454
459
|
can do what the user asks. The SDK never pushes a description past 1024
|
|
455
460
|
characters (UTF-8 bytes): if the full hint does not fit, it appends only the
|
|
456
461
|
telemetry sentence, and if that does not fit either, it leaves the description
|
|
457
|
-
unchanged and logs a warning.
|
|
462
|
+
unchanged and logs a warning. Either notice is logged once per tool with
|
|
463
|
+
`console.warn`; set **descriptionLengthLogLevel** to `"info"`, `"debug"` or
|
|
464
|
+
`"none"` to log it at a lower level or not at all. Every level writes to
|
|
465
|
+
stderr where the runtime has one (Node, Bun, Deno), so stdio servers keep
|
|
466
|
+
stdout for JSON-RPC; `"info"` and `"debug"` use `console.info` and
|
|
467
|
+
`console.debug` only in runtimes without stderr, such as Workers.
|
|
458
468
|
|
|
459
469
|
```mermaid
|
|
460
470
|
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/recorder.js
CHANGED
|
@@ -177,6 +177,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
177
177
|
name: request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME,
|
|
178
178
|
description: request_capability_js_1.REQUEST_CAPABILITY_DESCRIPTION,
|
|
179
179
|
inputSchema: request_capability_js_1.REQUEST_CAPABILITY_INPUT_SCHEMA,
|
|
180
|
+
annotations: request_capability_js_1.REQUEST_CAPABILITY_ANNOTATIONS,
|
|
180
181
|
});
|
|
181
182
|
continue;
|
|
182
183
|
}
|
|
@@ -206,6 +207,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
206
207
|
name: request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME,
|
|
207
208
|
description: request_capability_js_1.REQUEST_CAPABILITY_DESCRIPTION,
|
|
208
209
|
inputSchema: request_capability_js_1.REQUEST_CAPABILITY_ZOD_SHAPE,
|
|
210
|
+
annotations: request_capability_js_1.REQUEST_CAPABILITY_ANNOTATIONS,
|
|
209
211
|
},
|
|
210
212
|
handler: request_capability_js_1.handleRequestCapability,
|
|
211
213
|
telemetryMode: "scrub",
|
|
@@ -5,6 +5,13 @@ export declare const REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
|
|
|
5
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
|
+
export declare const REQUEST_CAPABILITY_ANNOTATIONS: {
|
|
9
|
+
title: string;
|
|
10
|
+
readOnlyHint: boolean;
|
|
11
|
+
destructiveHint: boolean;
|
|
12
|
+
idempotentHint: boolean;
|
|
13
|
+
openWorldHint: boolean;
|
|
14
|
+
};
|
|
8
15
|
export declare const REQUEST_CAPABILITY_ZOD_SHAPE: {
|
|
9
16
|
capability: z.ZodString;
|
|
10
17
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleRequestCapability = exports.isRequestCapabilityExplicit = exports.isRequestCapabilityEnabled = exports.REQUEST_CAPABILITY_ZOD_SHAPE = exports.REQUEST_CAPABILITY_INPUT_SCHEMA = exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = exports.REQUEST_CAPABILITY_DESCRIPTION = exports.REQUEST_CAPABILITY_TOOL_NAME = void 0;
|
|
3
|
+
exports.handleRequestCapability = exports.isRequestCapabilityExplicit = exports.isRequestCapabilityEnabled = exports.REQUEST_CAPABILITY_ZOD_SHAPE = exports.REQUEST_CAPABILITY_ANNOTATIONS = exports.REQUEST_CAPABILITY_INPUT_SCHEMA = exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = exports.REQUEST_CAPABILITY_DESCRIPTION = exports.REQUEST_CAPABILITY_TOOL_NAME = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const emit_js_1 = require("./emit.js");
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
@@ -20,6 +20,17 @@ exports.REQUEST_CAPABILITY_INPUT_SCHEMA = {
|
|
|
20
20
|
required: ["capability"],
|
|
21
21
|
additionalProperties: false,
|
|
22
22
|
};
|
|
23
|
+
// Directories such as ChatGPT's reject tools without explicit readOnlyHint,
|
|
24
|
+
// destructiveHint and openWorldHint. The tool records an analytics event (not
|
|
25
|
+
// read-only), changes no user data and reaches no one outside the server.
|
|
26
|
+
// Matches the hosted Armature MCP (lib/mcp/index.js).
|
|
27
|
+
exports.REQUEST_CAPABILITY_ANNOTATIONS = {
|
|
28
|
+
title: "Request capability",
|
|
29
|
+
readOnlyHint: false,
|
|
30
|
+
destructiveHint: false,
|
|
31
|
+
idempotentHint: false,
|
|
32
|
+
openWorldHint: false,
|
|
33
|
+
};
|
|
23
34
|
// McpServer.registerTool accepts a Zod raw shape, while custom dispatchers
|
|
24
35
|
// consume the JSON Schema above from recorder.toolDefinitions().
|
|
25
36
|
exports.REQUEST_CAPABILITY_ZOD_SHAPE = {
|
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/recorder.js
CHANGED
|
@@ -3,7 +3,7 @@ import { defaultMcpAnalyticsConfig } from "./emit.js";
|
|
|
3
3
|
import { planToolTelemetry, TELEMETRY_PROPERTY_DESCRIPTION, USER_INTENT_DESCRIPTION, } from "./schema.js";
|
|
4
4
|
import { isJsonObjectSchema, isRecord } from "./utils.js";
|
|
5
5
|
import { getClientInfoForSessionId, installClientInfoCapture, } from "./client-info-cache.js";
|
|
6
|
-
import { handleRequestCapability, isRequestCapabilityEnabled, isRequestCapabilityExplicit, REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_INPUT_SCHEMA, REQUEST_CAPABILITY_TOOL_NAME, REQUEST_CAPABILITY_ZOD_SHAPE, } from "./request-capability.js";
|
|
6
|
+
import { handleRequestCapability, isRequestCapabilityEnabled, isRequestCapabilityExplicit, REQUEST_CAPABILITY_ANNOTATIONS, REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_INPUT_SCHEMA, REQUEST_CAPABILITY_TOOL_NAME, REQUEST_CAPABILITY_ZOD_SHAPE, } from "./request-capability.js";
|
|
7
7
|
import { createAnalyticsRecorderCore } from "./recorder-core.js";
|
|
8
8
|
const nudgeTelemetryDescriptions = (schema) => {
|
|
9
9
|
if (!isJsonObjectSchema(schema))
|
|
@@ -174,6 +174,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
174
174
|
name: REQUEST_CAPABILITY_TOOL_NAME,
|
|
175
175
|
description: REQUEST_CAPABILITY_DESCRIPTION,
|
|
176
176
|
inputSchema: REQUEST_CAPABILITY_INPUT_SCHEMA,
|
|
177
|
+
annotations: REQUEST_CAPABILITY_ANNOTATIONS,
|
|
177
178
|
});
|
|
178
179
|
continue;
|
|
179
180
|
}
|
|
@@ -203,6 +204,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
203
204
|
name: REQUEST_CAPABILITY_TOOL_NAME,
|
|
204
205
|
description: REQUEST_CAPABILITY_DESCRIPTION,
|
|
205
206
|
inputSchema: REQUEST_CAPABILITY_ZOD_SHAPE,
|
|
207
|
+
annotations: REQUEST_CAPABILITY_ANNOTATIONS,
|
|
206
208
|
},
|
|
207
209
|
handler: handleRequestCapability,
|
|
208
210
|
telemetryMode: "scrub",
|
|
@@ -5,6 +5,13 @@ export declare const REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
|
|
|
5
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
|
+
export declare const REQUEST_CAPABILITY_ANNOTATIONS: {
|
|
9
|
+
title: string;
|
|
10
|
+
readOnlyHint: boolean;
|
|
11
|
+
destructiveHint: boolean;
|
|
12
|
+
idempotentHint: boolean;
|
|
13
|
+
openWorldHint: boolean;
|
|
14
|
+
};
|
|
8
15
|
export declare const REQUEST_CAPABILITY_ZOD_SHAPE: {
|
|
9
16
|
capability: z.ZodString;
|
|
10
17
|
};
|
|
@@ -17,6 +17,17 @@ export const REQUEST_CAPABILITY_INPUT_SCHEMA = {
|
|
|
17
17
|
required: ["capability"],
|
|
18
18
|
additionalProperties: false,
|
|
19
19
|
};
|
|
20
|
+
// Directories such as ChatGPT's reject tools without explicit readOnlyHint,
|
|
21
|
+
// destructiveHint and openWorldHint. The tool records an analytics event (not
|
|
22
|
+
// read-only), changes no user data and reaches no one outside the server.
|
|
23
|
+
// Matches the hosted Armature MCP (lib/mcp/index.js).
|
|
24
|
+
export const REQUEST_CAPABILITY_ANNOTATIONS = {
|
|
25
|
+
title: "Request capability",
|
|
26
|
+
readOnlyHint: false,
|
|
27
|
+
destructiveHint: false,
|
|
28
|
+
idempotentHint: false,
|
|
29
|
+
openWorldHint: false,
|
|
30
|
+
};
|
|
20
31
|
// McpServer.registerTool accepts a Zod raw shape, while custom dispatchers
|
|
21
32
|
// consume the JSON Schema above from recorder.toolDefinitions().
|
|
22
33
|
export const REQUEST_CAPABILITY_ZOD_SHAPE = {
|
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),
|