@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
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
5
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
|
+
import { REQUEST_CAPABILITY_DESCRIPTION, REQUEST_CAPABILITY_TOOL_NAME, } from "./request-capability.js";
|
|
7
|
+
const DEFAULT_INGEST_URL = "https://app.armature.tech/api/mcp-analytics/ingest";
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
9
|
+
const CURRENT_TELEMETRY_MARKER = "Conversation telemetry.";
|
|
10
|
+
const LEGACY_TELEMETRY_MARKERS = [
|
|
11
|
+
"Pass telemetry.user_intent",
|
|
12
|
+
"Pass telemetry.intent",
|
|
13
|
+
];
|
|
14
|
+
const isRecord = (value) => (typeof value === "object" && value !== null && !Array.isArray(value));
|
|
15
|
+
const errorMessage = (error) => {
|
|
16
|
+
if (error instanceof Error && error.message)
|
|
17
|
+
return error.message;
|
|
18
|
+
return String(error || "unknown error");
|
|
19
|
+
};
|
|
20
|
+
const withTimeout = async (promise, timeoutMs, label) => {
|
|
21
|
+
let timer;
|
|
22
|
+
try {
|
|
23
|
+
return await Promise.race([
|
|
24
|
+
promise,
|
|
25
|
+
new Promise((_resolve, reject) => {
|
|
26
|
+
timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
if (timer)
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const currentProcessEnvironment = () => {
|
|
36
|
+
const out = {};
|
|
37
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
38
|
+
if (typeof value === "string")
|
|
39
|
+
out[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
export const inspectMcp = async (options) => {
|
|
44
|
+
const client = new Client({ name: "armature-mcp-doctor", version: "1" });
|
|
45
|
+
const transport = options.target.kind === "http"
|
|
46
|
+
? new StreamableHTTPClientTransport(new URL(options.target.url), {
|
|
47
|
+
requestInit: { headers: options.target.headers },
|
|
48
|
+
})
|
|
49
|
+
: new StdioClientTransport({
|
|
50
|
+
command: options.target.command,
|
|
51
|
+
args: options.target.args,
|
|
52
|
+
cwd: options.target.cwd,
|
|
53
|
+
env: currentProcessEnvironment(),
|
|
54
|
+
stderr: "pipe",
|
|
55
|
+
});
|
|
56
|
+
if (transport instanceof StdioClientTransport) {
|
|
57
|
+
// The SDK exposes the PassThrough before spawning the child, so start
|
|
58
|
+
// draining immediately. Otherwise a chatty server can fill the bounded
|
|
59
|
+
// stderr pipe and block before it answers the MCP handshake.
|
|
60
|
+
transport.stderr?.on("data", () => undefined);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await withTimeout(client.connect(transport), options.timeoutMs, "MCP initialize");
|
|
64
|
+
const listed = await withTimeout(client.listTools(), options.timeoutMs, "MCP tools/list");
|
|
65
|
+
const server = client.getServerVersion();
|
|
66
|
+
return {
|
|
67
|
+
serverName: server?.name,
|
|
68
|
+
serverVersion: server?.version,
|
|
69
|
+
tools: listed.tools.map((tool) => ({
|
|
70
|
+
name: tool.name,
|
|
71
|
+
description: tool.description,
|
|
72
|
+
inputSchema: tool.inputSchema,
|
|
73
|
+
})),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// Some stdio servers do not exit promptly after stdin closes. Diagnostics
|
|
78
|
+
// must still return a result instead of hanging on cleanup.
|
|
79
|
+
await withTimeout(client.close(), Math.min(options.timeoutMs, 1_000), "MCP close")
|
|
80
|
+
.catch(() => {
|
|
81
|
+
if (transport instanceof StdioClientTransport && transport.pid) {
|
|
82
|
+
try {
|
|
83
|
+
process.kill(transport.pid, "SIGTERM");
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// The child may already have exited between the pid read and kill.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const telemetryShape = (tool) => {
|
|
93
|
+
if (!isRecord(tool.inputSchema))
|
|
94
|
+
return null;
|
|
95
|
+
const properties = tool.inputSchema.properties;
|
|
96
|
+
if (!isRecord(properties))
|
|
97
|
+
return null;
|
|
98
|
+
return isRecord(properties.telemetry) ? properties.telemetry : null;
|
|
99
|
+
};
|
|
100
|
+
export const classifyToolInstrumentation = (tool) => {
|
|
101
|
+
const inputProperties = isRecord(tool.inputSchema)
|
|
102
|
+
&& isRecord(tool.inputSchema.properties)
|
|
103
|
+
? tool.inputSchema.properties
|
|
104
|
+
: null;
|
|
105
|
+
const ownsTelemetryField = Boolean(inputProperties && "telemetry" in inputProperties);
|
|
106
|
+
const telemetry = telemetryShape(tool);
|
|
107
|
+
if (!telemetry)
|
|
108
|
+
return ownsTelemetryField ? "owned" : "missing";
|
|
109
|
+
const properties = isRecord(telemetry.properties) ? telemetry.properties : {};
|
|
110
|
+
const telemetryDescription = typeof telemetry.description === "string"
|
|
111
|
+
? telemetry.description
|
|
112
|
+
: "";
|
|
113
|
+
const toolDescription = tool.description || "";
|
|
114
|
+
if ("agent_thinking" in properties
|
|
115
|
+
&& "user_intent" in properties
|
|
116
|
+
&& telemetryDescription.includes(CURRENT_TELEMETRY_MARKER)) {
|
|
117
|
+
return "current";
|
|
118
|
+
}
|
|
119
|
+
if ("intent" in properties
|
|
120
|
+
|| "context" in properties
|
|
121
|
+
|| LEGACY_TELEMETRY_MARKERS.some((marker) => toolDescription.includes(marker))) {
|
|
122
|
+
return "legacy";
|
|
123
|
+
}
|
|
124
|
+
return ownsTelemetryField ? "owned" : "missing";
|
|
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;
|
|
133
|
+
export const inspectToolCoverage = (tools) => {
|
|
134
|
+
const current = [];
|
|
135
|
+
const legacy = [];
|
|
136
|
+
const owned = [];
|
|
137
|
+
const missing = [];
|
|
138
|
+
const sdkOwned = [];
|
|
139
|
+
for (const tool of tools) {
|
|
140
|
+
if (isSdkOwnedCapabilityTool(tool)) {
|
|
141
|
+
sdkOwned.push(tool.name);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const classification = classifyToolInstrumentation(tool);
|
|
145
|
+
if (classification === "current")
|
|
146
|
+
current.push(tool.name);
|
|
147
|
+
else if (classification === "legacy")
|
|
148
|
+
legacy.push(tool.name);
|
|
149
|
+
else if (classification === "owned")
|
|
150
|
+
owned.push(tool.name);
|
|
151
|
+
else
|
|
152
|
+
missing.push(tool.name);
|
|
153
|
+
}
|
|
154
|
+
return { current, legacy, owned, missing, sdkOwned, total: tools.length - sdkOwned.length };
|
|
155
|
+
};
|
|
156
|
+
const readIfPresent = async (path) => {
|
|
157
|
+
try {
|
|
158
|
+
return await readFile(path, "utf8");
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const code = isRecord(error) ? error.code : undefined;
|
|
162
|
+
if (code === "ENOENT")
|
|
163
|
+
return null;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
export const detectLocalSdks = async (cwd) => {
|
|
168
|
+
const found = [];
|
|
169
|
+
const packageJson = await readIfPresent(resolve(cwd, "package.json"));
|
|
170
|
+
if (packageJson) {
|
|
171
|
+
try {
|
|
172
|
+
const parsed = JSON.parse(packageJson);
|
|
173
|
+
const sections = [parsed.dependencies, parsed.devDependencies, parsed.peerDependencies];
|
|
174
|
+
for (const section of sections) {
|
|
175
|
+
if (isRecord(section) && typeof section["@armature-tech/mcp-analytics"] === "string") {
|
|
176
|
+
found.push({
|
|
177
|
+
language: "typescript",
|
|
178
|
+
declaration: `@armature-tech/mcp-analytics ${section["@armature-tech/mcp-analytics"]}`,
|
|
179
|
+
});
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// A malformed package.json will be reported by the customer's package manager.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const pyproject = await readIfPresent(resolve(cwd, "pyproject.toml"));
|
|
189
|
+
const requirements = await readIfPresent(resolve(cwd, "requirements.txt"));
|
|
190
|
+
const pythonDeclaration = [pyproject, requirements]
|
|
191
|
+
.filter((value) => Boolean(value))
|
|
192
|
+
.join("\n")
|
|
193
|
+
.match(/armature-mcp-analytics(?:\[[^\]]+\])?(?:\s*[<>=~!]+\s*[^\s"',\]]+)?/i)?.[0];
|
|
194
|
+
if (pythonDeclaration) {
|
|
195
|
+
found.push({ language: "python", declaration: pythonDeclaration.replace(/["',]/g, "") });
|
|
196
|
+
}
|
|
197
|
+
const goMod = await readIfPresent(resolve(cwd, "go.mod"));
|
|
198
|
+
const goDeclaration = goMod
|
|
199
|
+
?.match(/github\.com\/armature-tech\/mcp-analytics-go(?:\/[^\s]+)?\s+v[^\s)]+/)?.[0];
|
|
200
|
+
if (goDeclaration)
|
|
201
|
+
found.push({ language: "go", declaration: goDeclaration });
|
|
202
|
+
return found;
|
|
203
|
+
};
|
|
204
|
+
export const verifyIngest = async (endpoint, apiKey, timeoutMs) => {
|
|
205
|
+
const url = new URL(endpoint);
|
|
206
|
+
if (!["http:", "https:"].includes(url.protocol)) {
|
|
207
|
+
throw new Error("ingest URL must use http or https");
|
|
208
|
+
}
|
|
209
|
+
const controller = new AbortController();
|
|
210
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
211
|
+
try {
|
|
212
|
+
// The ingest route resolves bearer auth before accepting an empty batch,
|
|
213
|
+
// so this validates reachability and the key without creating a session or
|
|
214
|
+
// sending tool, user, or response content. Keep that server contract covered
|
|
215
|
+
// by test/api-mcp-analytics-ingest-doctor.test.js.
|
|
216
|
+
const response = await fetch(url, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
headers: {
|
|
219
|
+
"content-type": "application/json",
|
|
220
|
+
authorization: `Bearer ${apiKey}`,
|
|
221
|
+
},
|
|
222
|
+
body: JSON.stringify({ schema_version: 1, events: [] }),
|
|
223
|
+
signal: controller.signal,
|
|
224
|
+
});
|
|
225
|
+
// Drain the body so undici can release its pooled connection promptly and
|
|
226
|
+
// the one-shot CLI does not appear to hang after printing the report.
|
|
227
|
+
await response.arrayBuffer();
|
|
228
|
+
if (!response.ok) {
|
|
229
|
+
throw new Error(`Armature ingest returned HTTP ${response.status}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
clearTimeout(timer);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const pass = (id, label, detail) => ({
|
|
237
|
+
id, label, detail, status: "pass",
|
|
238
|
+
});
|
|
239
|
+
const warn = (id, label, detail, remediation) => ({
|
|
240
|
+
id, label, detail, status: "warn", ...(remediation ? { remediation } : {}),
|
|
241
|
+
});
|
|
242
|
+
const fail = (id, label, detail, remediation) => ({
|
|
243
|
+
id, label, detail, status: "fail", ...(remediation ? { remediation } : {}),
|
|
244
|
+
});
|
|
245
|
+
export const runDoctor = async (options, dependencies = { inspectMcp, detectLocalSdks, verifyIngest }, environment = process.env) => {
|
|
246
|
+
const checks = [];
|
|
247
|
+
try {
|
|
248
|
+
const sdks = await dependencies.detectLocalSdks(options.cwd);
|
|
249
|
+
if (sdks.length === 0) {
|
|
250
|
+
checks.push(warn("sdk-declaration", "SDK dependency", "No Armature SDK declaration was found in this directory.", "Run the doctor from the MCP project root, or confirm the SDK is installed in the deployed project."));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
checks.push(pass("sdk-declaration", "SDK dependency", sdks.map((sdk) => `${sdk.language}: ${sdk.declaration}`).join("; ")));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
checks.push(warn("sdk-declaration", "SDK dependency", errorMessage(error)));
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
const inspection = await dependencies.inspectMcp(options);
|
|
261
|
+
const identity = [inspection.serverName, inspection.serverVersion].filter(Boolean).join(" ");
|
|
262
|
+
checks.push(pass("mcp-initialize", "MCP initialize", identity ? `Connected to ${identity}.` : "The server completed the MCP handshake."));
|
|
263
|
+
if (inspection.tools.length === 0) {
|
|
264
|
+
checks.push(fail("tools-list", "Tool discovery", "The server returned zero tools, so wrapping cannot be verified.", "Register at least one tool and run the doctor again."));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
checks.push(pass("tools-list", "Tool discovery", `The server returned ${inspection.tools.length} tool${inspection.tools.length === 1 ? "" : "s"}.`));
|
|
268
|
+
const coverage = inspectToolCoverage(inspection.tools);
|
|
269
|
+
if (!options.expectCapture) {
|
|
270
|
+
const exposed = coverage.current.length + coverage.legacy.length;
|
|
271
|
+
checks.push(exposed === 0
|
|
272
|
+
? pass("tool-wrapping", "Telemetry capture", "No Armature telemetry fields are advertised, as requested.")
|
|
273
|
+
: warn("tool-wrapping", "Telemetry capture", `${exposed}/${coverage.total} tools still advertise Armature telemetry fields.`, "Confirm captureTelemetry=false is applied before tools are registered."));
|
|
274
|
+
}
|
|
275
|
+
else if (coverage.missing.length > 0) {
|
|
276
|
+
const sample = coverage.missing.slice(0, 5).join(", ");
|
|
277
|
+
checks.push(fail("tool-wrapping", "Tool wrapping", `${coverage.missing.length}/${coverage.total} tools do not expose the Armature telemetry contract${sample ? `: ${sample}` : ""}.`, "Wrap the same server instance that is started, and register tools inside withMcpAnalytics or through an Armature recorder."));
|
|
278
|
+
}
|
|
279
|
+
else if (coverage.legacy.length > 0) {
|
|
280
|
+
checks.push(warn("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools are wrapped, but ${coverage.legacy.length} use the legacy telemetry contract.`, "Upgrade the Armature SDK and restart the MCP server."));
|
|
281
|
+
}
|
|
282
|
+
else if (coverage.owned.length > 0) {
|
|
283
|
+
const sample = coverage.owned.slice(0, 5).join(", ");
|
|
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."));
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
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
|
+
: "")));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
checks.push(fail("mcp-initialize", "MCP initialize", errorMessage(error), options.target.kind === "http"
|
|
296
|
+
? "Start the MCP server, verify the URL/auth headers, and run the doctor again."
|
|
297
|
+
: "Run the server command directly once, fix startup errors, then run the doctor again."));
|
|
298
|
+
}
|
|
299
|
+
if (options.skipIngest) {
|
|
300
|
+
checks.push(warn("ingest-auth", "Armature ingest", "Skipped by --skip-ingest; no network request was made."));
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const apiKey = environment.ANALYTICS_INGEST_API_KEY;
|
|
304
|
+
const endpoint = environment.ANALYTICS_INGEST_URL || DEFAULT_INGEST_URL;
|
|
305
|
+
if (!apiKey) {
|
|
306
|
+
checks.push(fail("ingest-auth", "Armature ingest", "ANALYTICS_INGEST_API_KEY is not set in the doctor environment.", "Export the same ingest key used by the MCP server, then run the doctor again."));
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
try {
|
|
310
|
+
await dependencies.verifyIngest(endpoint, apiKey, options.timeoutMs);
|
|
311
|
+
checks.push(pass("ingest-auth", "Armature ingest", "The endpoint accepted an empty authenticated health probe; no session or customer content was sent."));
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
checks.push(fail("ingest-auth", "Armature ingest", errorMessage(error), "Check ANALYTICS_INGEST_API_KEY and ANALYTICS_INGEST_URL, then run the doctor again."));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
healthy: !checks.some((check) => check.status === "fail"),
|
|
320
|
+
target: options.target.kind,
|
|
321
|
+
checks,
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
export const defaultDoctorOptions = (target) => ({
|
|
325
|
+
target,
|
|
326
|
+
cwd: process.cwd(),
|
|
327
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
328
|
+
expectCapture: true,
|
|
329
|
+
skipIngest: false,
|
|
330
|
+
json: false,
|
|
331
|
+
});
|
package/dist/esm/emit.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare const defaultMcpAnalyticsConfig: {
|
|
|
9
9
|
export declare const resolveEndpointUrl: (config: McpAnalyticsConfig) => string;
|
|
10
10
|
export declare const resolveApiKey: (config: McpAnalyticsConfig) => string | undefined;
|
|
11
11
|
export declare const resolveActorSeed: (config: McpAnalyticsConfig, input: ActorIdResolverInput) => Promise<string>;
|
|
12
|
+
/** Resolve the optional caller-provided identifier without interpreting it. */
|
|
13
|
+
export declare const resolveActorIdentifier: (config: McpAnalyticsConfig, input: ActorIdResolverInput) => Promise<string | undefined>;
|
|
12
14
|
export declare const postTelemetryEvent: (batch: AnalyticsIngestBatch, config?: McpAnalyticsConfig) => Promise<{
|
|
13
15
|
skipped: boolean;
|
|
14
16
|
reason: string;
|
|
@@ -20,6 +22,7 @@ export declare const postTelemetryEvent: (batch: AnalyticsIngestBatch, config?:
|
|
|
20
22
|
status: number;
|
|
21
23
|
reason?: undefined;
|
|
22
24
|
}>;
|
|
25
|
+
export declare const reportEmitError: (error: unknown, batch: AnalyticsIngestBatch, config: McpAnalyticsConfig) => void;
|
|
23
26
|
export declare const emitTelemetryEvent: (batch: AnalyticsIngestBatch, config?: McpAnalyticsConfig) => Promise<void>;
|
|
24
27
|
export declare const createFlushableEmitter: (config: McpAnalyticsConfig) => {
|
|
25
28
|
emitBatch: (batch: AnalyticsIngestBatch) => Promise<void>;
|
package/dist/esm/emit.js
CHANGED
|
@@ -34,6 +34,19 @@ export const resolveActorSeed = async (config, input) => {
|
|
|
34
34
|
return authorization;
|
|
35
35
|
return "anonymous";
|
|
36
36
|
};
|
|
37
|
+
const MAX_ACTOR_IDENTIFIER_BYTES = 8 * 1024;
|
|
38
|
+
/** Resolve the optional caller-provided identifier without interpreting it. */
|
|
39
|
+
export const resolveActorIdentifier = async (config, input) => {
|
|
40
|
+
const configured = config.armature?.actorIdentifier;
|
|
41
|
+
if (configured === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
const value = typeof configured === "function" ? await configured(input) : configured;
|
|
44
|
+
if (typeof value !== "string" || value.length === 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
return new TextEncoder().encode(value).byteLength <= MAX_ACTOR_IDENTIFIER_BYTES
|
|
47
|
+
? value
|
|
48
|
+
: undefined;
|
|
49
|
+
};
|
|
37
50
|
export const postTelemetryEvent = async (batch, config = defaultMcpAnalyticsConfig) => {
|
|
38
51
|
const endpointUrl = resolveEndpointUrl(config);
|
|
39
52
|
const apiKey = resolveApiKey(config);
|
|
@@ -62,7 +75,7 @@ export const postTelemetryEvent = async (batch, config = defaultMcpAnalyticsConf
|
|
|
62
75
|
clearTimeout(timeout);
|
|
63
76
|
}
|
|
64
77
|
};
|
|
65
|
-
const reportEmitError = (error, batch, config) => {
|
|
78
|
+
export const reportEmitError = (error, batch, config) => {
|
|
66
79
|
const onError = config.armature?.onError;
|
|
67
80
|
if (onError) {
|
|
68
81
|
onError(error, batch);
|
package/dist/esm/events.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, McpClientInfo, RedactFunction, RequestExtra, TelemetryArgs } from "./types.js";
|
|
1
|
+
import type { AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, McpClientInfo, RedactEventHook, RedactFunction, RequestExtra, TelemetryArgs } from "./types.js";
|
|
2
2
|
import { type BoundedKeySet } from "./utils.js";
|
|
3
3
|
export declare const buildActorId: ({ actorSeed, }: {
|
|
4
4
|
actorSeed: string;
|
|
@@ -8,7 +8,12 @@ export declare const buildEventId: ({ actorId, requestId, kind, }: {
|
|
|
8
8
|
requestId: string;
|
|
9
9
|
kind: AnalyticsEventKind;
|
|
10
10
|
}) => string;
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const buildActorIdentityEvent: ({ actorId, identifier, startedAt, }: {
|
|
12
|
+
actorId: string;
|
|
13
|
+
identifier: string;
|
|
14
|
+
startedAt: string;
|
|
15
|
+
}) => AnalyticsIngestEvent;
|
|
16
|
+
export type BuildToolCallEventInput = {
|
|
12
17
|
toolName: string;
|
|
13
18
|
telemetry?: TelemetryArgs;
|
|
14
19
|
input: unknown;
|
|
@@ -22,8 +27,14 @@ export declare const buildToolCallEvent: ({ toolName, telemetry, input, output,
|
|
|
22
27
|
startedAt: string;
|
|
23
28
|
finishedAt: string;
|
|
24
29
|
workflowRunId?: string;
|
|
30
|
+
capabilityRequest?: boolean;
|
|
25
31
|
redact?: RedactFunction;
|
|
26
|
-
|
|
32
|
+
redactSecrets?: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare const buildToolCallEvent: (input: BuildToolCallEventInput) => AnalyticsIngestEvent;
|
|
35
|
+
export declare const finalizeToolCallEvent: (input: BuildToolCallEventInput & {
|
|
36
|
+
redactEvent?: RedactEventHook;
|
|
37
|
+
}) => Promise<AnalyticsIngestEvent | null>;
|
|
27
38
|
export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, extra, clientInfo, workflowRunId, }: {
|
|
28
39
|
actorId: string;
|
|
29
40
|
sessionId: string;
|
|
@@ -32,8 +43,9 @@ export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, ex
|
|
|
32
43
|
clientInfo?: McpClientInfo;
|
|
33
44
|
workflowRunId?: string;
|
|
34
45
|
}) => AnalyticsIngestEvent;
|
|
35
|
-
export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
46
|
+
export declare const buildBatch: ({ event, identityEvent, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
36
47
|
event: AnalyticsIngestEvent;
|
|
48
|
+
identityEvent?: AnalyticsIngestEvent;
|
|
37
49
|
extra?: RequestExtra;
|
|
38
50
|
actorId: string;
|
|
39
51
|
startedAt: string;
|
|
@@ -41,7 +53,7 @@ export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionIni
|
|
|
41
53
|
clientInfo?: McpClientInfo;
|
|
42
54
|
workflowRunId?: string;
|
|
43
55
|
}) => AnalyticsIngestBatch;
|
|
44
|
-
export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
56
|
+
export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, identityEvent, }: {
|
|
45
57
|
actorId: string;
|
|
46
58
|
sessionId: string;
|
|
47
59
|
startedAt: string;
|
|
@@ -49,6 +61,7 @@ export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, ex
|
|
|
49
61
|
sessionInitKeys: BoundedKeySet;
|
|
50
62
|
clientInfo?: McpClientInfo;
|
|
51
63
|
workflowRunId?: string;
|
|
64
|
+
identityEvent?: AnalyticsIngestEvent;
|
|
52
65
|
}) => AnalyticsIngestBatch | null;
|
|
53
66
|
export declare const normalizeSessionId: (eventSessionId: string | undefined, extra: RequestExtra | undefined) => string | undefined;
|
|
54
67
|
export declare const normalizeRequestId: (eventRequestId: string | undefined) => string;
|