@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.
- package/README.md +99 -4
- package/SKILL.md +29 -4
- package/dist/cjs/cli.d.ts +2 -0
- package/dist/cjs/cli.js +62 -0
- package/dist/cjs/doctor-args.d.ts +2 -0
- package/dist/cjs/doctor-args.js +101 -0
- package/dist/cjs/doctor.d.ts +65 -0
- package/dist/cjs/doctor.js +342 -0
- package/dist/cjs/emit.d.ts +3 -0
- package/dist/cjs/emit.js +18 -3
- package/dist/cjs/events.d.ts +18 -5
- package/dist/cjs/events.js +127 -41
- package/dist/cjs/index.d.ts +6 -4
- package/dist/cjs/index.js +15 -1
- package/dist/cjs/mastra.js +42 -0
- package/dist/cjs/queue.d.ts +9 -0
- package/dist/cjs/queue.js +116 -0
- package/dist/cjs/recorder.js +157 -70
- package/dist/cjs/redact-secrets.d.ts +10 -0
- package/dist/cjs/redact-secrets.js +121 -0
- package/dist/cjs/request-capability.d.ts +12 -0
- package/dist/cjs/request-capability.js +50 -0
- package/dist/cjs/sanitize.d.ts +5 -1
- package/dist/cjs/sanitize.js +51 -37
- package/dist/cjs/server.js +20 -0
- package/dist/cjs/types.d.ts +25 -1
- package/dist/esm/cli.d.ts +2 -0
- package/dist/esm/cli.js +60 -0
- package/dist/esm/doctor-args.d.ts +2 -0
- package/dist/esm/doctor-args.js +97 -0
- package/dist/esm/doctor.d.ts +65 -0
- package/dist/esm/doctor.js +331 -0
- package/dist/esm/emit.d.ts +3 -0
- package/dist/esm/emit.js +14 -1
- package/dist/esm/events.d.ts +18 -5
- package/dist/esm/events.js +124 -40
- package/dist/esm/index.d.ts +6 -4
- package/dist/esm/index.js +5 -3
- package/dist/esm/mastra.js +42 -0
- package/dist/esm/queue.d.ts +9 -0
- package/dist/esm/queue.js +112 -0
- package/dist/esm/recorder.js +159 -72
- package/dist/esm/redact-secrets.d.ts +10 -0
- package/dist/esm/redact-secrets.js +115 -0
- package/dist/esm/request-capability.d.ts +12 -0
- package/dist/esm/request-capability.js +45 -0
- package/dist/esm/sanitize.d.ts +5 -1
- package/dist/esm/sanitize.js +50 -36
- package/dist/esm/server.js +20 -0
- package/dist/esm/types.d.ts +25 -1
- package/package.json +6 -1
package/dist/esm/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createAnalyticsRecorder } from "./recorder.js";
|
|
|
5
5
|
import { planToolTelemetry } from "./schema.js";
|
|
6
6
|
import { defaultMcpAnalyticsConfig } from "./emit.js";
|
|
7
7
|
import { deriveToolResultError, isRecord } from "./utils.js";
|
|
8
|
+
import { isRequestCapabilityEnabled } from "./request-capability.js";
|
|
8
9
|
const withAnalyticsStorage = new AsyncLocalStorage();
|
|
9
10
|
let prototypePatchInstalled = false;
|
|
10
11
|
// Mirrors the SDK's `isZodTypeLike`/`isZodRawShapeCompat` checks closely enough
|
|
@@ -151,6 +152,25 @@ export const withMcpAnalytics = (config, createServer) => {
|
|
|
151
152
|
const recorder = createAnalyticsRecorder(config);
|
|
152
153
|
installPrototypePatchOnce();
|
|
153
154
|
const result = withAnalyticsStorage.run({ config, recorder }, createServer);
|
|
155
|
+
// Customer tools registered inside the factory are handled by the
|
|
156
|
+
// prototype patch above. The opt-in SDK-owned tool lives in the recorder's
|
|
157
|
+
// private registry, so attach only after leaving AsyncLocalStorage: this
|
|
158
|
+
// registers it once without adding telemetry fields or mutating its exact
|
|
159
|
+
// description.
|
|
160
|
+
if (isRequestCapabilityEnabled(config) && !(result instanceof McpServer)) {
|
|
161
|
+
throw new Error("armature.requestCapability requires the server factory to return an McpServer instance.");
|
|
162
|
+
}
|
|
163
|
+
if (isRequestCapabilityEnabled(config) && result instanceof McpServer) {
|
|
164
|
+
try {
|
|
165
|
+
recorder.attachToMcpServer(result);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error instanceof Error && /already registered/i.test(error.message)) {
|
|
169
|
+
throw new Error('Tool name "request_capability" is reserved while armature.requestCapability is enabled.', { cause: error });
|
|
170
|
+
}
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
154
174
|
return { result, recorder };
|
|
155
175
|
};
|
|
156
176
|
export const createMcpAnalyticsServer = (createServer, config = defaultMcpAnalyticsConfig) => {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -39,7 +39,20 @@ export type ActorIdResolverInput = {
|
|
|
39
39
|
telemetry?: TelemetryArgs;
|
|
40
40
|
};
|
|
41
41
|
export type ActorIdResolver = (input: ActorIdResolverInput) => string | Promise<string>;
|
|
42
|
+
export type ActorIdentifierResolver = (input: ActorIdResolverInput) => string | Promise<string>;
|
|
42
43
|
export type RedactFunction = (value: unknown) => unknown;
|
|
44
|
+
export type RedactableToolCall = {
|
|
45
|
+
kind: "tool_call";
|
|
46
|
+
toolName: string;
|
|
47
|
+
status: "ok" | "error";
|
|
48
|
+
durationMs: number;
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
input: unknown;
|
|
51
|
+
output?: unknown;
|
|
52
|
+
errorMessage?: string;
|
|
53
|
+
telemetry?: TelemetryArgs;
|
|
54
|
+
};
|
|
55
|
+
export type RedactEventHook = (event: RedactableToolCall) => RedactableToolCall | null | Promise<RedactableToolCall | null>;
|
|
43
56
|
export type TelemetryFieldMap = {
|
|
44
57
|
/** @deprecated `user_turn` is no longer collected; this mapping is ignored. */
|
|
45
58
|
user_turn?: string;
|
|
@@ -52,14 +65,23 @@ export type McpAnalyticsConfig = {
|
|
|
52
65
|
endpointUrl?: string;
|
|
53
66
|
apiKey?: string;
|
|
54
67
|
actorId?: string | ActorIdResolver;
|
|
68
|
+
/** Optional caller-provided identifier stored verbatim. */
|
|
69
|
+
actorIdentifier?: string | ActorIdentifierResolver;
|
|
55
70
|
enabled?: boolean;
|
|
56
71
|
delivery?: "background" | "await";
|
|
57
72
|
emit?: TelemetryEmitter;
|
|
58
73
|
onError?: (error: unknown, batch: AnalyticsIngestBatch) => void;
|
|
59
74
|
timeoutMs?: number;
|
|
60
75
|
captureTelemetry?: boolean;
|
|
76
|
+
/** Built-in high-confidence secret detection. Enabled by default. */
|
|
77
|
+
redactSecrets?: boolean;
|
|
78
|
+
/** @deprecated Prefer redactEvent for event context and async support. */
|
|
61
79
|
redact?: RedactFunction;
|
|
80
|
+
redactEvent?: RedactEventHook;
|
|
81
|
+
/** Register background work with a platform lifecycle primitive (for example waitUntil). */
|
|
82
|
+
schedule?: (work: Promise<void>) => void;
|
|
62
83
|
telemetryFieldMap?: TelemetryFieldMap;
|
|
84
|
+
requestCapability?: boolean;
|
|
63
85
|
};
|
|
64
86
|
};
|
|
65
87
|
export type TelemetryMode = "injected" | "owned" | "scrub";
|
|
@@ -127,6 +149,7 @@ export type RecordToolCallEvent = {
|
|
|
127
149
|
error?: unknown;
|
|
128
150
|
clientInfo?: McpClientInfo;
|
|
129
151
|
workflowRunId?: string;
|
|
152
|
+
capabilityRequest?: boolean;
|
|
130
153
|
};
|
|
131
154
|
export type InstrumentToolCallEvent = {
|
|
132
155
|
name: string;
|
|
@@ -140,6 +163,7 @@ export type InstrumentToolCallEvent = {
|
|
|
140
163
|
clientInfo?: McpClientInfo;
|
|
141
164
|
workflowRunId?: string;
|
|
142
165
|
telemetryMode?: TelemetryMode;
|
|
166
|
+
capabilityRequest?: boolean;
|
|
143
167
|
};
|
|
144
168
|
export type ToolCallHandler<T> = (args: unknown) => T | Promise<T>;
|
|
145
169
|
export type ToolHandlerContext = {
|
|
@@ -178,7 +202,7 @@ export type AnalyticsRecorder = {
|
|
|
178
202
|
createMcpServer: (info: McpServerInfo) => McpServer;
|
|
179
203
|
flush: () => Promise<void>;
|
|
180
204
|
};
|
|
181
|
-
export type AnalyticsEventKind = "tool_call" | "session_init";
|
|
205
|
+
export type AnalyticsEventKind = "tool_call" | "session_init" | "actor_identity";
|
|
182
206
|
export type AnalyticsIngestEvent = {
|
|
183
207
|
event_id: string;
|
|
184
208
|
kind: AnalyticsEventKind;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armature-tech/mcp-analytics",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP analytics wrapper SDK that instruments MCP tool declarations with telemetry.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
],
|
|
26
26
|
"main": "./dist/cjs/index.js",
|
|
27
27
|
"types": "./dist/cjs/index.d.ts",
|
|
28
|
+
"bin": {
|
|
29
|
+
"mcp-analytics": "./dist/esm/cli.js"
|
|
30
|
+
},
|
|
28
31
|
"exports": {
|
|
29
32
|
".": {
|
|
30
33
|
"import": {
|
|
@@ -60,9 +63,11 @@
|
|
|
60
63
|
"dev:server": "tsx experimental/mock-env/mock-example-mcp-server.ts",
|
|
61
64
|
"demo": "tsx experimental/mock-env/demo-client.ts",
|
|
62
65
|
"demo:instrumented": "tsx experimental/mock-env/instrumented-demo-client.ts",
|
|
66
|
+
"benchmark:redaction": "tsx scripts/benchmark-redaction.ts",
|
|
63
67
|
"test": "tsx --test tests/*.test.ts",
|
|
64
68
|
"test:artifact-canary": "npm run build && node scripts/run-publish-canary.mjs",
|
|
65
69
|
"test:platform-canary": "node scripts/run-publish-canary.mjs --require-platform",
|
|
70
|
+
"doctor": "tsx src/cli.ts doctor",
|
|
66
71
|
"typecheck": "tsc --noEmit",
|
|
67
72
|
"typecheck:all": "tsc --noEmit -p tsconfig.test.json",
|
|
68
73
|
"check": "npm run typecheck:all && npm test",
|