@armature-tech/mcp-analytics 0.6.18 → 0.6.20

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.
Files changed (51) hide show
  1. package/README.md +99 -4
  2. package/SKILL.md +29 -4
  3. package/dist/cjs/cli.d.ts +2 -0
  4. package/dist/cjs/cli.js +62 -0
  5. package/dist/cjs/doctor-args.d.ts +2 -0
  6. package/dist/cjs/doctor-args.js +101 -0
  7. package/dist/cjs/doctor.d.ts +65 -0
  8. package/dist/cjs/doctor.js +342 -0
  9. package/dist/cjs/emit.d.ts +3 -0
  10. package/dist/cjs/emit.js +18 -3
  11. package/dist/cjs/events.d.ts +18 -5
  12. package/dist/cjs/events.js +127 -41
  13. package/dist/cjs/index.d.ts +6 -4
  14. package/dist/cjs/index.js +15 -1
  15. package/dist/cjs/mastra.js +42 -0
  16. package/dist/cjs/queue.d.ts +9 -0
  17. package/dist/cjs/queue.js +116 -0
  18. package/dist/cjs/recorder.js +157 -70
  19. package/dist/cjs/redact-secrets.d.ts +10 -0
  20. package/dist/cjs/redact-secrets.js +121 -0
  21. package/dist/cjs/request-capability.d.ts +12 -0
  22. package/dist/cjs/request-capability.js +50 -0
  23. package/dist/cjs/sanitize.d.ts +5 -1
  24. package/dist/cjs/sanitize.js +51 -37
  25. package/dist/cjs/server.js +20 -0
  26. package/dist/cjs/types.d.ts +25 -1
  27. package/dist/esm/cli.d.ts +2 -0
  28. package/dist/esm/cli.js +60 -0
  29. package/dist/esm/doctor-args.d.ts +2 -0
  30. package/dist/esm/doctor-args.js +97 -0
  31. package/dist/esm/doctor.d.ts +65 -0
  32. package/dist/esm/doctor.js +331 -0
  33. package/dist/esm/emit.d.ts +3 -0
  34. package/dist/esm/emit.js +14 -1
  35. package/dist/esm/events.d.ts +18 -5
  36. package/dist/esm/events.js +124 -40
  37. package/dist/esm/index.d.ts +6 -4
  38. package/dist/esm/index.js +5 -3
  39. package/dist/esm/mastra.js +42 -0
  40. package/dist/esm/queue.d.ts +9 -0
  41. package/dist/esm/queue.js +112 -0
  42. package/dist/esm/recorder.js +159 -72
  43. package/dist/esm/redact-secrets.d.ts +10 -0
  44. package/dist/esm/redact-secrets.js +115 -0
  45. package/dist/esm/request-capability.d.ts +12 -0
  46. package/dist/esm/request-capability.js +45 -0
  47. package/dist/esm/sanitize.d.ts +5 -1
  48. package/dist/esm/sanitize.js +50 -36
  49. package/dist/esm/server.js +20 -0
  50. package/dist/esm/types.d.ts +25 -1
  51. package/package.json +6 -1
@@ -9,6 +9,8 @@ const utils_js_1 = require("./utils.js");
9
9
  const stdio_session_js_1 = require("./stdio-session.js");
10
10
  const client_info_cache_js_1 = require("./client-info-cache.js");
11
11
  const stateless_http_js_1 = require("./stateless-http.js");
12
+ const request_capability_js_1 = require("./request-capability.js");
13
+ const queue_js_1 = require("./queue.js");
12
14
  const nudgeTelemetryDescriptions = (schema) => {
13
15
  if (!(0, utils_js_1.isJsonObjectSchema)(schema))
14
16
  return schema;
@@ -34,11 +36,13 @@ const nudgeTelemetryDescriptions = (schema) => {
34
36
  };
35
37
  };
36
38
  const createAnalyticsContext = async (config, input) => {
37
- const actorSeed = await (0, emit_js_1.resolveActorSeed)(config, input);
38
- return { actorId: (0, events_js_1.buildActorId)({ actorSeed }) };
39
+ const actorIdentifier = await (0, emit_js_1.resolveActorIdentifier)(config, input);
40
+ const actorSeed = actorIdentifier ?? await (0, emit_js_1.resolveActorSeed)(config, input);
41
+ return { actorId: (0, events_js_1.buildActorId)({ actorSeed }), actorIdentifier };
39
42
  };
40
43
  const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) => {
41
- const { emitBatch, flush } = (0, emit_js_1.createFlushableEmitter)(config);
44
+ const privacyQueue = (0, queue_js_1.createPrivacyQueue)(config);
45
+ const flush = privacyQueue.flush;
42
46
  // Tracks which (actorId, sessionId) pairs have already emitted a session_init,
43
47
  // so we emit it at most once per session. Bounded with FIFO eviction: MCP
44
48
  // gives no reliable session-closed signal, so an unbounded set would leak on
@@ -46,6 +50,26 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
46
50
  // session_init event_id is now stable per (actorId, sessionId), so a re-emit
47
51
  // after eviction collapses to the same id at ingest. 10k × ~60 bytes ≈ 600KB.
48
52
  const sessionInitKeys = (0, utils_js_1.createBoundedKeySet)(10_000);
53
+ // Per-process change detection. Event ids are content-addressed, so an
54
+ // identical re-emit after restart is harmless and converges at ingest.
55
+ const actorIdentifiers = new Map();
56
+ const identityEventFor = (context, startedAt) => {
57
+ if (context.actorIdentifier === undefined)
58
+ return undefined;
59
+ if (actorIdentifiers.get(context.actorId) === context.actorIdentifier)
60
+ return undefined;
61
+ actorIdentifiers.set(context.actorId, context.actorIdentifier);
62
+ if (actorIdentifiers.size > 10_000) {
63
+ const oldest = actorIdentifiers.keys().next().value;
64
+ if (oldest !== undefined)
65
+ actorIdentifiers.delete(oldest);
66
+ }
67
+ return (0, events_js_1.buildActorIdentityEvent)({
68
+ actorId: context.actorId,
69
+ identifier: context.actorIdentifier,
70
+ startedAt,
71
+ });
72
+ };
49
73
  // Patch the SDK's Server.prototype the first time any recorder is created
50
74
  // so that the very next `initialize` handshake feeds the per-session client
51
75
  // info cache. Without this the dashboard's "Client" column would stay at
@@ -105,30 +129,33 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
105
129
  const sessionId = resolveSessionId(event);
106
130
  if (!sessionId)
107
131
  return;
108
- const context = await analyticsContextFor({
109
- ctx: event.ctx,
110
- extra: event.extra,
111
- headers: event.headers ?? event.extra?.requestInfo?.headers,
112
- authInfo: event.authInfo ?? event.extra?.authInfo,
113
- });
114
132
  const finishedAtMs = Date.now();
115
133
  const startedAt = (0, events_js_1.normalizeStartedAt)({
116
134
  startedAt: event.startedAt,
117
135
  finishedAtMs,
118
136
  });
119
- const batch = (0, events_js_1.buildSessionInitBatch)({
120
- actorId: context.actorId,
121
- sessionId,
122
- startedAt,
123
- extra: event.extra,
124
- sessionInitKeys,
125
- clientInfo: event.clientInfo
126
- ?? (0, client_info_cache_js_1.getClientInfoForSessionId)(sessionId)
127
- ?? (0, stateless_http_js_1.parseStatelessSessionClientInfo)(sessionId),
128
- workflowRunId: resolveWorkflowRunId(event),
137
+ const workflowRunId = resolveWorkflowRunId(event);
138
+ return privacyQueue.enqueue(async () => {
139
+ const context = await analyticsContextFor({
140
+ ctx: event.ctx,
141
+ extra: event.extra,
142
+ headers: event.headers ?? event.extra?.requestInfo?.headers,
143
+ authInfo: event.authInfo ?? event.extra?.authInfo,
144
+ });
145
+ const batch = (0, events_js_1.buildSessionInitBatch)({
146
+ actorId: context.actorId,
147
+ sessionId,
148
+ startedAt,
149
+ extra: event.extra,
150
+ sessionInitKeys,
151
+ clientInfo: event.clientInfo
152
+ ?? (0, client_info_cache_js_1.getClientInfoForSessionId)(sessionId)
153
+ ?? (0, stateless_http_js_1.parseStatelessSessionClientInfo)(sessionId),
154
+ workflowRunId,
155
+ identityEvent: identityEventFor(context, startedAt),
156
+ });
157
+ return batch?.events ?? null;
129
158
  });
130
- if (batch)
131
- await emitBatch(batch);
132
159
  };
133
160
  const recordToolCall = async (event) => {
134
161
  // Single choke point for capture-off and field ownership
@@ -142,14 +169,6 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
142
169
  const telemetry = (0, schema_js_1.isCaptureEnabled)(config)
143
170
  ? (0, schema_js_1.applyTelemetryFieldMap)(ownedTool ? undefined : event.telemetry, event.args, config.armature?.telemetryFieldMap)
144
171
  : undefined;
145
- const context = await analyticsContextFor({
146
- ctx: event.ctx,
147
- extra: event.extra,
148
- headers: event.headers ?? event.extra?.requestInfo?.headers,
149
- authInfo: event.authInfo ?? event.extra?.authInfo,
150
- toolName: event.name,
151
- telemetry,
152
- });
153
172
  const finishedAtMs = Date.now();
154
173
  const finishedAt = new Date(finishedAtMs).toISOString();
155
174
  const durationMs = event.durationMs ?? 0;
@@ -166,40 +185,68 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
166
185
  ? event.error.message
167
186
  : String(event.error);
168
187
  const workflowRunId = resolveWorkflowRunId(event);
169
- const toolCallEvent = (0, events_js_1.buildToolCallEvent)({
170
- toolName: event.name,
171
- telemetry,
172
- input: event.args,
173
- output: event.result,
174
- status: event.status,
175
- durationMs,
176
- errorMessage,
177
- actorId: context.actorId,
178
- sessionId,
179
- requestId,
180
- startedAt,
181
- finishedAt,
182
- workflowRunId,
183
- redact: config.armature?.redact,
184
- });
185
- // An explicit clientInfo on the event always wins; otherwise look up
186
- // whatever the initialize-handshake patch captured for this sessionId; as a
187
- // last resort, identity-bearing session ids (stateless HTTP) are parseable.
188
- const effectiveClientInfo = event.clientInfo
189
- ?? (0, client_info_cache_js_1.getClientInfoForSessionId)(sessionId)
190
- ?? (0, stateless_http_js_1.parseStatelessSessionClientInfo)(sessionId);
191
- await emitBatch((0, events_js_1.buildBatch)({
192
- event: toolCallEvent,
193
- extra: {
188
+ return privacyQueue.enqueue(async () => {
189
+ const context = await analyticsContextFor({
190
+ ctx: event.ctx,
191
+ extra: event.extra,
192
+ headers: event.headers ?? event.extra?.requestInfo?.headers,
193
+ authInfo: event.authInfo ?? event.extra?.authInfo,
194
+ toolName: event.name,
195
+ telemetry,
196
+ });
197
+ const toolCallEvent = await (0, events_js_1.finalizeToolCallEvent)({
198
+ toolName: event.name,
199
+ telemetry,
200
+ input: event.args,
201
+ output: event.result,
202
+ status: event.status,
203
+ durationMs,
204
+ errorMessage,
205
+ actorId: context.actorId,
206
+ sessionId,
207
+ requestId,
208
+ startedAt,
209
+ finishedAt,
210
+ workflowRunId,
211
+ capabilityRequest: event.capabilityRequest,
212
+ redact: config.armature?.redact,
213
+ redactSecrets: config.armature?.redactSecrets,
214
+ redactEvent: config.armature?.redactEvent,
215
+ });
216
+ const effectiveClientInfo = event.clientInfo
217
+ ?? (0, client_info_cache_js_1.getClientInfoForSessionId)(sessionId)
218
+ ?? (0, stateless_http_js_1.parseStatelessSessionClientInfo)(sessionId);
219
+ const identityEvent = identityEventFor(context, startedAt);
220
+ const extra = {
194
221
  ...(event.extra ?? {}),
195
222
  ...(sessionId ? { sessionId } : {}),
196
- },
197
- actorId: context.actorId,
198
- startedAt,
199
- sessionInitKeys,
200
- clientInfo: effectiveClientInfo,
201
- workflowRunId,
202
- }));
223
+ };
224
+ if (toolCallEvent) {
225
+ return (0, events_js_1.buildBatch)({
226
+ event: toolCallEvent,
227
+ extra,
228
+ actorId: context.actorId,
229
+ startedAt,
230
+ sessionInitKeys,
231
+ clientInfo: effectiveClientInfo,
232
+ workflowRunId,
233
+ identityEvent,
234
+ }).events;
235
+ }
236
+ if (sessionId) {
237
+ return (0, events_js_1.buildSessionInitBatch)({
238
+ actorId: context.actorId,
239
+ sessionId,
240
+ startedAt,
241
+ extra,
242
+ sessionInitKeys,
243
+ clientInfo: effectiveClientInfo,
244
+ workflowRunId,
245
+ identityEvent,
246
+ })?.events ?? null;
247
+ }
248
+ return identityEvent ? [identityEvent] : null;
249
+ });
203
250
  };
204
251
  const registeredTools = new Map();
205
252
  const instrumentToolCall = async (event, handler) => {
@@ -242,7 +289,13 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
242
289
  if (!tool) {
243
290
  throw new Error(`Unknown tool: ${name}`);
244
291
  }
245
- return instrumentToolCall({ name, args: rawArgs, telemetryMode: tool.telemetryMode, ...context }, (args) => tool.handler(args, context));
292
+ return instrumentToolCall({
293
+ name,
294
+ args: rawArgs,
295
+ telemetryMode: tool.telemetryMode,
296
+ capabilityRequest: tool.internal,
297
+ ...context,
298
+ }, (args) => tool.handler(args, context));
246
299
  };
247
300
  let attachedServer = null;
248
301
  const buildHandlerContext = (extra) => ({
@@ -258,9 +311,15 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
258
311
  headers: extra?.requestInfo?.headers,
259
312
  ctx: extra,
260
313
  });
261
- const registerWithServer = (server, registration, handler) => {
314
+ const registerWithServer = (server, registration, handler, internal = false) => {
262
315
  const originalHasInputSchema = registration.inputSchema !== undefined;
263
- const plan = (0, schema_js_1.planToolTelemetry)(registration.name, registration.inputSchema, config);
316
+ const plan = internal
317
+ ? {
318
+ mode: "scrub",
319
+ inputSchema: registration.inputSchema,
320
+ applyDescription: (description) => description,
321
+ }
322
+ : (0, schema_js_1.planToolTelemetry)(registration.name, registration.inputSchema, config);
264
323
  // The MCP SDK passes (args, extra) to the callback whenever the registered
265
324
  // tool has an input schema, and just (extra) when it has none — so the
266
325
  // positional juggling below keys on what we actually registered, which for
@@ -286,17 +345,23 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
286
345
  extra,
287
346
  sessionId: extra?.sessionId,
288
347
  telemetryMode: plan.mode,
348
+ capabilityRequest: internal,
289
349
  }, (strippedArgs) => handler(originalHasInputSchema ? strippedArgs : {}, buildHandlerContext(extra)));
290
350
  }));
291
351
  };
292
352
  const tool = (registration, handler) => {
353
+ if ((0, request_capability_js_1.isRequestCapabilityEnabled)(config)
354
+ && registration.name === request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME) {
355
+ throw new Error(`Tool name "${request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME}" is reserved while armature.requestCapability is enabled.`);
356
+ }
293
357
  registeredTools.set(registration.name, {
294
358
  registration,
295
359
  handler: handler,
296
360
  telemetryMode: (0, schema_js_1.planToolTelemetry)(registration.name, registration.inputSchema, config).mode,
361
+ internal: false,
297
362
  });
298
363
  if (attachedServer) {
299
- registerWithServer(attachedServer, registration, handler);
364
+ registerWithServer(attachedServer, registration, handler, false);
300
365
  }
301
366
  return (rawArgs, context = {}) => dispatch(registration.name, rawArgs, context);
302
367
  };
@@ -305,8 +370,8 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
305
370
  throw new Error("This recorder is already attached to an McpServer.");
306
371
  }
307
372
  attachedServer = server;
308
- for (const { registration, handler } of registeredTools.values()) {
309
- registerWithServer(server, registration, handler);
373
+ for (const { registration, handler, internal } of registeredTools.values()) {
374
+ registerWithServer(server, registration, handler, internal);
310
375
  }
311
376
  return server;
312
377
  };
@@ -314,7 +379,16 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
314
379
  return attachToMcpServer(new mcp_js_1.McpServer(info));
315
380
  };
316
381
  const toolDefinitions = () => {
317
- return decorateDefinitions(Array.from(registeredTools.values()).map(({ registration }) => {
382
+ const definitions = [];
383
+ for (const { registration, internal } of registeredTools.values()) {
384
+ if (internal) {
385
+ definitions.push({
386
+ name: request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME,
387
+ description: request_capability_js_1.REQUEST_CAPABILITY_DESCRIPTION,
388
+ inputSchema: request_capability_js_1.REQUEST_CAPABILITY_INPUT_SCHEMA,
389
+ });
390
+ continue;
391
+ }
318
392
  const definition = { name: registration.name };
319
393
  if (registration.title !== undefined)
320
394
  definition.title = registration.title;
@@ -324,10 +398,23 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
324
398
  if (registration.inputSchema !== undefined) {
325
399
  definition.inputSchema = registration.inputSchema;
326
400
  }
327
- return definition;
328
- }));
401
+ definitions.push(...decorateDefinitions([definition]));
402
+ }
403
+ return definitions;
329
404
  };
330
405
  const hasTool = (name) => registeredTools.has(name);
406
+ if ((0, request_capability_js_1.isRequestCapabilityEnabled)(config)) {
407
+ registeredTools.set(request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME, {
408
+ registration: {
409
+ name: request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME,
410
+ description: request_capability_js_1.REQUEST_CAPABILITY_DESCRIPTION,
411
+ inputSchema: request_capability_js_1.REQUEST_CAPABILITY_ZOD_SHAPE,
412
+ },
413
+ handler: request_capability_js_1.handleRequestCapability,
414
+ telemetryMode: "scrub",
415
+ internal: true,
416
+ });
417
+ }
331
418
  return {
332
419
  decorateDefinitions,
333
420
  extractTelemetry: schema_js_1.extractTelemetryArguments,
@@ -0,0 +1,10 @@
1
+ export type SecretPatternRule = {
2
+ id: string;
3
+ pattern: RegExp;
4
+ replacement: string;
5
+ };
6
+ export declare const SECRET_PATTERN_RULES: readonly SecretPatternRule[];
7
+ export declare const SENSITIVE_FIELD_NAMES: Set<string>;
8
+ export declare const normalizeSensitiveFieldName: (key: string) => string;
9
+ export declare const redactSecretsInString: (value: string) => string;
10
+ export declare const redactSecretsInValue: (value: unknown, seen?: WeakSet<object>) => unknown;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redactSecretsInValue = exports.redactSecretsInString = exports.normalizeSensitiveFieldName = exports.SENSITIVE_FIELD_NAMES = exports.SECRET_PATTERN_RULES = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ // Contract order is significant. Keep these expressions RE2-compatible so
6
+ // the TypeScript, Python, and Go implementations continue to agree.
7
+ exports.SECRET_PATTERN_RULES = [
8
+ {
9
+ id: "pem",
10
+ pattern: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
11
+ replacement: "[redacted:pem]",
12
+ },
13
+ {
14
+ id: "sensitive-kv",
15
+ pattern: /\b(password|passwd|pwd|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|client[_-]?secret|private[_-]?key|authorization)([=:])([^\s"'`,;&]{4,})/gi,
16
+ replacement: "$1$2[redacted:sensitive-kv]",
17
+ },
18
+ {
19
+ id: "aws-access-key-id",
20
+ pattern: /\b(?:AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AIPA|ANPA|ANVA|AROA)[A-Z0-9]{16}\b/g,
21
+ replacement: "[redacted:aws-access-key-id]",
22
+ },
23
+ {
24
+ id: "github-token",
25
+ pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{22,255})\b/g,
26
+ replacement: "[redacted:github-token]",
27
+ },
28
+ {
29
+ id: "google-api-key",
30
+ pattern: /\bAIza[0-9A-Za-z_-]{35}\b/g,
31
+ replacement: "[redacted:google-api-key]",
32
+ },
33
+ {
34
+ id: "slack-token",
35
+ pattern: /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
36
+ replacement: "[redacted:slack-token]",
37
+ },
38
+ {
39
+ id: "stripe-key",
40
+ pattern: /\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}\b/g,
41
+ replacement: "[redacted:stripe-key]",
42
+ },
43
+ {
44
+ id: "anthropic-api-key",
45
+ pattern: /\bsk-ant-[A-Za-z0-9_-]{16,}\b/g,
46
+ replacement: "[redacted:anthropic-api-key]",
47
+ },
48
+ {
49
+ id: "openai-api-key",
50
+ pattern: /\bsk-[A-Za-z0-9_-]{20,}\b/g,
51
+ replacement: "[redacted:openai-api-key]",
52
+ },
53
+ {
54
+ id: "jwt",
55
+ pattern: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{10,}\b/g,
56
+ replacement: "[redacted:jwt]",
57
+ },
58
+ {
59
+ id: "connection-string",
60
+ pattern: /\b([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s:/@]+):([^\s@]+)@/g,
61
+ replacement: "$1:[redacted:connection-string]@",
62
+ },
63
+ {
64
+ id: "bearer",
65
+ pattern: /\b[Bb]earer +[A-Za-z0-9._~+/=-]{16,}/g,
66
+ replacement: "Bearer [redacted:bearer]",
67
+ },
68
+ {
69
+ id: "basic",
70
+ pattern: /\b[Bb]asic +[A-Za-z0-9+/=]{16,}/g,
71
+ replacement: "Basic [redacted:basic]",
72
+ },
73
+ ];
74
+ exports.SENSITIVE_FIELD_NAMES = new Set([
75
+ "password", "passwd", "pwd", "secret", "apikey", "accesskey",
76
+ "secretkey", "secretaccesskey", "token", "accesstoken", "refreshtoken",
77
+ "idtoken", "sessiontoken", "authorization", "auth", "clientsecret",
78
+ "privatekey", "credential", "credentials", "connectionstring",
79
+ "databaseurl", "dsn",
80
+ ]);
81
+ const normalizeSensitiveFieldName = (key) => {
82
+ return key.toLowerCase().replace(/[_-]/g, "");
83
+ };
84
+ exports.normalizeSensitiveFieldName = normalizeSensitiveFieldName;
85
+ const redactSecretsInString = (value) => {
86
+ let redacted = value;
87
+ for (const rule of exports.SECRET_PATTERN_RULES) {
88
+ redacted = redacted.replace(rule.pattern, rule.replacement);
89
+ }
90
+ return redacted;
91
+ };
92
+ exports.redactSecretsInString = redactSecretsInString;
93
+ const redactSecretsInValue = (value, seen) => {
94
+ if (typeof value === "string")
95
+ return (0, exports.redactSecretsInString)(value);
96
+ if (typeof value !== "object" || value === null)
97
+ return value;
98
+ const tracked = seen ?? new WeakSet();
99
+ if (tracked.has(value))
100
+ return "[circular]";
101
+ tracked.add(value);
102
+ try {
103
+ if (Array.isArray(value)) {
104
+ return value.map((item) => (0, exports.redactSecretsInValue)(item, tracked));
105
+ }
106
+ if (!(0, utils_js_1.isRecord)(value))
107
+ return value;
108
+ const out = {};
109
+ for (const [key, entry] of Object.entries(value)) {
110
+ out[key] = typeof entry === "string"
111
+ && exports.SENSITIVE_FIELD_NAMES.has((0, exports.normalizeSensitiveFieldName)(key))
112
+ ? "[redacted:sensitive-field]"
113
+ : (0, exports.redactSecretsInValue)(entry, tracked);
114
+ }
115
+ return out;
116
+ }
117
+ finally {
118
+ tracked.delete(value);
119
+ }
120
+ };
121
+ exports.redactSecretsInValue = redactSecretsInValue;
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { JsonObjectSchema, McpAnalyticsConfig } from "./types.js";
4
+ export declare const REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
5
+ export declare const REQUEST_CAPABILITY_DESCRIPTION = "Request a capability that is not provided by the currently available tools. Use this when a capability is required to complete the user\u2019s request and no existing tool can perform it.";
6
+ export declare const REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = "The capability required to complete the user's request. Omit argument values, PII, and secrets. Use English.";
7
+ export declare const REQUEST_CAPABILITY_INPUT_SCHEMA: JsonObjectSchema;
8
+ export declare const REQUEST_CAPABILITY_ZOD_SHAPE: {
9
+ capability: z.ZodString;
10
+ };
11
+ export declare const isRequestCapabilityEnabled: (config: McpAnalyticsConfig) => boolean;
12
+ export declare const handleRequestCapability: (args: unknown) => CallToolResult;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRequestCapability = 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;
4
+ const zod_1 = require("zod");
5
+ const emit_js_1 = require("./emit.js");
6
+ const utils_js_1 = require("./utils.js");
7
+ exports.REQUEST_CAPABILITY_TOOL_NAME = "request_capability";
8
+ exports.REQUEST_CAPABILITY_DESCRIPTION = "Request a capability that is not provided by the currently available tools. Use this when a capability is required to complete the user’s request and no existing tool can perform it.";
9
+ exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION = "The capability required to complete the user's request. Omit argument values, PII, and secrets. Use English.";
10
+ exports.REQUEST_CAPABILITY_INPUT_SCHEMA = {
11
+ type: "object",
12
+ properties: {
13
+ capability: {
14
+ type: "string",
15
+ description: exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION,
16
+ minLength: 1,
17
+ maxLength: 1000,
18
+ },
19
+ },
20
+ required: ["capability"],
21
+ additionalProperties: false,
22
+ };
23
+ // McpServer.registerTool accepts a Zod raw shape, while custom dispatchers
24
+ // consume the JSON Schema above from recorder.toolDefinitions().
25
+ exports.REQUEST_CAPABILITY_ZOD_SHAPE = {
26
+ capability: zod_1.z
27
+ .string()
28
+ .min(1)
29
+ .max(1000)
30
+ .describe(exports.REQUEST_CAPABILITY_ARGUMENT_DESCRIPTION),
31
+ };
32
+ const isRequestCapabilityEnabled = (config) => config.armature?.requestCapability === true
33
+ && config.armature?.enabled !== false
34
+ && (typeof config.armature?.emit === "function" || Boolean((0, emit_js_1.resolveApiKey)(config)));
35
+ exports.isRequestCapabilityEnabled = isRequestCapabilityEnabled;
36
+ const handleRequestCapability = (args) => {
37
+ if (!(0, utils_js_1.isRecord)(args)
38
+ || typeof args.capability !== "string"
39
+ || args.capability.trim().length === 0
40
+ || args.capability.length > 1000) {
41
+ return {
42
+ isError: true,
43
+ content: [{ type: "text", text: "capability must be a non-empty string" }],
44
+ };
45
+ }
46
+ return {
47
+ content: [{ type: "text", text: "Capability request acknowledged." }],
48
+ };
49
+ };
50
+ exports.handleRequestCapability = handleRequestCapability;
@@ -2,5 +2,9 @@ import type { RedactFunction } from "./types.js";
2
2
  export declare const BINARY_REMOVED_PLACEHOLDER = "[binary removed]";
3
3
  export declare const BASE64_REMOVED_PLACEHOLDER = "[base64 removed]";
4
4
  export declare const REDACTION_FAILED_PLACEHOLDER = "[redaction failed]";
5
+ export declare const SANITIZATION_BUDGET = 65536;
5
6
  export declare const sanitizeValue: (value: unknown, seen?: WeakSet<object>) => unknown;
6
- export declare const prepareForPreview: (value: unknown, redact: RedactFunction | undefined) => unknown;
7
+ export type PrepareForPreviewOptions = {
8
+ redactSecrets?: boolean;
9
+ };
10
+ export declare const prepareForPreview: (value: unknown, redact?: RedactFunction, options?: PrepareForPreviewOptions) => unknown;