@armature-tech/mcp-analytics 0.6.19 → 0.6.21

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.
@@ -50,11 +50,13 @@ export type DoctorDependencies = {
50
50
  };
51
51
  export declare const inspectMcp: (options: DoctorOptions) => Promise<McpInspection>;
52
52
  export declare const classifyToolInstrumentation: (tool: DoctorTool) => "current" | "legacy" | "owned" | "missing";
53
+ export declare const isSdkOwnedCapabilityTool: (tool: DoctorTool) => boolean;
53
54
  export declare const inspectToolCoverage: (tools: DoctorTool[]) => {
54
55
  current: string[];
55
56
  legacy: string[];
56
57
  owned: string[];
57
58
  missing: string[];
59
+ sdkOwned: string[];
58
60
  total: number;
59
61
  };
60
62
  export declare const detectLocalSdks: (cwd: string) => Promise<LocalSdk[]>;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultDoctorOptions = exports.runDoctor = exports.verifyIngest = exports.detectLocalSdks = exports.inspectToolCoverage = exports.classifyToolInstrumentation = exports.inspectMcp = void 0;
3
+ exports.defaultDoctorOptions = exports.runDoctor = exports.verifyIngest = exports.detectLocalSdks = exports.inspectToolCoverage = exports.isSdkOwnedCapabilityTool = exports.classifyToolInstrumentation = exports.inspectMcp = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
5
  const node_path_1 = require("node:path");
6
6
  const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
7
7
  const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
8
8
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
9
+ const request_capability_js_1 = require("./request-capability.js");
9
10
  const DEFAULT_INGEST_URL = "https://app.armature.tech/api/mcp-analytics/ingest";
10
11
  const DEFAULT_TIMEOUT_MS = 10_000;
11
12
  const CURRENT_TELEMETRY_MARKER = "Conversation telemetry.";
@@ -127,12 +128,25 @@ const classifyToolInstrumentation = (tool) => {
127
128
  return ownsTelemetryField ? "owned" : "missing";
128
129
  };
129
130
  exports.classifyToolInstrumentation = classifyToolInstrumentation;
131
+ // The SDK's own request_capability tool is registered without a telemetry
132
+ // block on purpose (its input is already conversation-derived), so the
133
+ // wrapping check must not count it as an unwrapped customer tool. Match on
134
+ // the exact advertised description as well as the reserved name so a
135
+ // customer-defined tool that merely shadows the name is still checked.
136
+ const isSdkOwnedCapabilityTool = (tool) => tool.name === request_capability_js_1.REQUEST_CAPABILITY_TOOL_NAME
137
+ && (tool.description || "") === request_capability_js_1.REQUEST_CAPABILITY_DESCRIPTION;
138
+ exports.isSdkOwnedCapabilityTool = isSdkOwnedCapabilityTool;
130
139
  const inspectToolCoverage = (tools) => {
131
140
  const current = [];
132
141
  const legacy = [];
133
142
  const owned = [];
134
143
  const missing = [];
144
+ const sdkOwned = [];
135
145
  for (const tool of tools) {
146
+ if ((0, exports.isSdkOwnedCapabilityTool)(tool)) {
147
+ sdkOwned.push(tool.name);
148
+ continue;
149
+ }
136
150
  const classification = (0, exports.classifyToolInstrumentation)(tool);
137
151
  if (classification === "current")
138
152
  current.push(tool.name);
@@ -143,7 +157,7 @@ const inspectToolCoverage = (tools) => {
143
157
  else
144
158
  missing.push(tool.name);
145
159
  }
146
- return { current, legacy, owned, missing, total: tools.length };
160
+ return { current, legacy, owned, missing, sdkOwned, total: tools.length - sdkOwned.length };
147
161
  };
148
162
  exports.inspectToolCoverage = inspectToolCoverage;
149
163
  const readIfPresent = async (path) => {
@@ -279,7 +293,10 @@ const runDoctor = async (options, dependencies = { inspectMcp: exports.inspectMc
279
293
  checks.push(warn("tool-wrapping", "Tool wrapping", `${coverage.current.length}/${coverage.total} tools expose the current Armature telemetry contract; ${coverage.owned.length} own a top-level telemetry field and are intentionally untouched${sample ? `: ${sample}` : ""}.`, "Rename the tool-owned telemetry input if you want Armature analytics for that tool, then restart the MCP server."));
280
294
  }
281
295
  else {
282
- checks.push(pass("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools expose the current Armature telemetry contract.`));
296
+ checks.push(pass("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools expose the current Armature telemetry contract.`
297
+ + (coverage.sdkOwned.length > 0
298
+ ? ` The SDK-owned ${coverage.sdkOwned.join(", ")} tool carries no telemetry block by design and is exempt.`
299
+ : "")));
283
300
  }
284
301
  }
285
302
  }
@@ -10,6 +10,9 @@ exports.SANITIZATION_BUDGET = 65_536;
10
10
  const DATA_URI_MIN_CHARS = 64;
11
11
  const BASE64_MIN_CHARS = 512;
12
12
  const BASE64_RE = /^[A-Za-z0-9+/_-]+={0,2}$/;
13
+ // Base64-alphabet runs long enough to be payloads embedded inside a larger
14
+ // string, e.g. a blob echoed within a JSON-serialized tool result.
15
+ const EMBEDDED_BASE64_RE = /[A-Za-z0-9+/_-]{512,}={0,2}/g;
13
16
  const isBase64Payload = (value) => {
14
17
  if (value.length >= DATA_URI_MIN_CHARS && value.startsWith("data:") && value.includes(";base64,")) {
15
18
  return true;
@@ -17,7 +20,12 @@ const isBase64Payload = (value) => {
17
20
  return value.length >= BASE64_MIN_CHARS && BASE64_RE.test(value);
18
21
  };
19
22
  const sanitizeString = (value) => {
20
- return isBase64Payload(value) ? exports.BASE64_REMOVED_PLACEHOLDER : value;
23
+ if (isBase64Payload(value))
24
+ return exports.BASE64_REMOVED_PLACEHOLDER;
25
+ if (value.length >= BASE64_MIN_CHARS) {
26
+ return value.replace(EMBEDDED_BASE64_RE, exports.BASE64_REMOVED_PLACEHOLDER);
27
+ }
28
+ return value;
21
29
  };
22
30
  const charge = (budget, units) => {
23
31
  if (budget.remaining < units) {
@@ -29,7 +37,11 @@ const charge = (budget, units) => {
29
37
  };
30
38
  const sanitizeValueBounded = (value, seen, budget) => {
31
39
  if (typeof value === "string") {
32
- const sanitized = sanitizeString(value);
40
+ // Bound pattern work to the retainable window first: previews are
41
+ // truncated anyway, so scanning beyond the budget is pure waste on
42
+ // large payloads.
43
+ const bounded = value.length > budget.remaining ? value.slice(0, budget.remaining) : value;
44
+ const sanitized = sanitizeString(bounded);
33
45
  if (sanitized.length <= budget.remaining) {
34
46
  budget.remaining -= sanitized.length;
35
47
  return sanitized;
@@ -50,11 +50,13 @@ export type DoctorDependencies = {
50
50
  };
51
51
  export declare const inspectMcp: (options: DoctorOptions) => Promise<McpInspection>;
52
52
  export declare const classifyToolInstrumentation: (tool: DoctorTool) => "current" | "legacy" | "owned" | "missing";
53
+ export declare const isSdkOwnedCapabilityTool: (tool: DoctorTool) => boolean;
53
54
  export declare const inspectToolCoverage: (tools: DoctorTool[]) => {
54
55
  current: string[];
55
56
  legacy: string[];
56
57
  owned: string[];
57
58
  missing: string[];
59
+ sdkOwned: string[];
58
60
  total: number;
59
61
  };
60
62
  export declare const detectLocalSdks: (cwd: string) => Promise<LocalSdk[]>;
@@ -3,6 +3,7 @@ import { resolve } from "node:path";
3
3
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
4
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5
5
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
6
+ import { REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_TOOL_NAME, } from "./request-capability.js";
6
7
  const DEFAULT_INGEST_URL = "https://app.armature.tech/api/mcp-analytics/ingest";
7
8
  const DEFAULT_TIMEOUT_MS = 10_000;
8
9
  const CURRENT_TELEMETRY_MARKER = "Conversation telemetry.";
@@ -122,12 +123,24 @@ export const classifyToolInstrumentation = (tool) => {
122
123
  }
123
124
  return ownsTelemetryField ? "owned" : "missing";
124
125
  };
126
+ // The SDK's own request_capability tool is registered without a telemetry
127
+ // block on purpose (its input is already conversation-derived), so the
128
+ // wrapping check must not count it as an unwrapped customer tool. Match on
129
+ // the exact advertised description as well as the reserved name so a
130
+ // customer-defined tool that merely shadows the name is still checked.
131
+ export const isSdkOwnedCapabilityTool = (tool) => tool.name === REQUEST_CAPABILITY_TOOL_NAME
132
+ && (tool.description || "") === REQUEST_CAPABILITY_DESCRIPTION;
125
133
  export const inspectToolCoverage = (tools) => {
126
134
  const current = [];
127
135
  const legacy = [];
128
136
  const owned = [];
129
137
  const missing = [];
138
+ const sdkOwned = [];
130
139
  for (const tool of tools) {
140
+ if (isSdkOwnedCapabilityTool(tool)) {
141
+ sdkOwned.push(tool.name);
142
+ continue;
143
+ }
131
144
  const classification = classifyToolInstrumentation(tool);
132
145
  if (classification === "current")
133
146
  current.push(tool.name);
@@ -138,7 +151,7 @@ export const inspectToolCoverage = (tools) => {
138
151
  else
139
152
  missing.push(tool.name);
140
153
  }
141
- return { current, legacy, owned, missing, total: tools.length };
154
+ return { current, legacy, owned, missing, sdkOwned, total: tools.length - sdkOwned.length };
142
155
  };
143
156
  const readIfPresent = async (path) => {
144
157
  try {
@@ -271,7 +284,10 @@ export const runDoctor = async (options, dependencies = { inspectMcp, detectLoca
271
284
  checks.push(warn("tool-wrapping", "Tool wrapping", `${coverage.current.length}/${coverage.total} tools expose the current Armature telemetry contract; ${coverage.owned.length} own a top-level telemetry field and are intentionally untouched${sample ? `: ${sample}` : ""}.`, "Rename the tool-owned telemetry input if you want Armature analytics for that tool, then restart the MCP server."));
272
285
  }
273
286
  else {
274
- checks.push(pass("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools expose the current Armature telemetry contract.`));
287
+ checks.push(pass("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools expose the current Armature telemetry contract.`
288
+ + (coverage.sdkOwned.length > 0
289
+ ? ` The SDK-owned ${coverage.sdkOwned.join(", ")} tool carries no telemetry block by design and is exempt.`
290
+ : "")));
275
291
  }
276
292
  }
277
293
  }
@@ -7,6 +7,9 @@ export const SANITIZATION_BUDGET = 65_536;
7
7
  const DATA_URI_MIN_CHARS = 64;
8
8
  const BASE64_MIN_CHARS = 512;
9
9
  const BASE64_RE = /^[A-Za-z0-9+/_-]+={0,2}$/;
10
+ // Base64-alphabet runs long enough to be payloads embedded inside a larger
11
+ // string, e.g. a blob echoed within a JSON-serialized tool result.
12
+ const EMBEDDED_BASE64_RE = /[A-Za-z0-9+/_-]{512,}={0,2}/g;
10
13
  const isBase64Payload = (value) => {
11
14
  if (value.length >= DATA_URI_MIN_CHARS && value.startsWith("data:") && value.includes(";base64,")) {
12
15
  return true;
@@ -14,7 +17,12 @@ const isBase64Payload = (value) => {
14
17
  return value.length >= BASE64_MIN_CHARS && BASE64_RE.test(value);
15
18
  };
16
19
  const sanitizeString = (value) => {
17
- return isBase64Payload(value) ? BASE64_REMOVED_PLACEHOLDER : value;
20
+ if (isBase64Payload(value))
21
+ return BASE64_REMOVED_PLACEHOLDER;
22
+ if (value.length >= BASE64_MIN_CHARS) {
23
+ return value.replace(EMBEDDED_BASE64_RE, BASE64_REMOVED_PLACEHOLDER);
24
+ }
25
+ return value;
18
26
  };
19
27
  const charge = (budget, units) => {
20
28
  if (budget.remaining < units) {
@@ -26,7 +34,11 @@ const charge = (budget, units) => {
26
34
  };
27
35
  const sanitizeValueBounded = (value, seen, budget) => {
28
36
  if (typeof value === "string") {
29
- const sanitized = sanitizeString(value);
37
+ // Bound pattern work to the retainable window first: previews are
38
+ // truncated anyway, so scanning beyond the budget is pure waste on
39
+ // large payloads.
40
+ const bounded = value.length > budget.remaining ? value.slice(0, budget.remaining) : value;
41
+ const sanitized = sanitizeString(bounded);
30
42
  if (sanitized.length <= budget.remaining) {
31
43
  budget.remaining -= sanitized.length;
32
44
  return sanitized;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armature-tech/mcp-analytics",
3
- "version": "0.6.19",
3
+ "version": "0.6.21",
4
4
  "type": "module",
5
5
  "description": "MCP analytics wrapper SDK that instruments MCP tool declarations with telemetry.",
6
6
  "license": "Apache-2.0",