@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/cjs/sanitize.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareForPreview = exports.sanitizeValue = exports.REDACTION_FAILED_PLACEHOLDER = exports.BASE64_REMOVED_PLACEHOLDER = exports.BINARY_REMOVED_PLACEHOLDER = void 0;
|
|
3
|
+
exports.prepareForPreview = exports.sanitizeValue = exports.SANITIZATION_BUDGET = exports.REDACTION_FAILED_PLACEHOLDER = exports.BASE64_REMOVED_PLACEHOLDER = exports.BINARY_REMOVED_PLACEHOLDER = void 0;
|
|
4
|
+
const redact_secrets_js_1 = require("./redact-secrets.js");
|
|
4
5
|
const utils_js_1 = require("./utils.js");
|
|
5
|
-
// Placeholder strings are part of the cross-SDK contract
|
|
6
|
-
// (packages/TELEMETRY-CONTRACT.md) — golden tests in all three SDKs assert
|
|
7
|
-
// them byte-for-byte.
|
|
8
6
|
exports.BINARY_REMOVED_PLACEHOLDER = "[binary removed]";
|
|
9
7
|
exports.BASE64_REMOVED_PLACEHOLDER = "[base64 removed]";
|
|
10
8
|
exports.REDACTION_FAILED_PLACEHOLDER = "[redaction failed]";
|
|
11
|
-
|
|
12
|
-
// strings need the higher bar (length + strict charset) so prose, ids, and
|
|
13
|
-
// hashes below half a KB pass through untouched. Both thresholds are contract
|
|
14
|
-
// values — keep in sync with the Python and Go SDKs.
|
|
9
|
+
exports.SANITIZATION_BUDGET = 65_536;
|
|
15
10
|
const DATA_URI_MIN_CHARS = 64;
|
|
16
11
|
const BASE64_MIN_CHARS = 512;
|
|
17
|
-
// Strict charset on purpose: no whitespace, so long prose (letters + spaces)
|
|
18
|
-
// never matches. Covers standard base64 and base64url, with optional padding.
|
|
19
12
|
const BASE64_RE = /^[A-Za-z0-9+/_-]+={0,2}$/;
|
|
20
13
|
const isBase64Payload = (value) => {
|
|
21
14
|
if (value.length >= DATA_URI_MIN_CHARS && value.startsWith("data:") && value.includes(";base64,")) {
|
|
@@ -26,60 +19,81 @@ const isBase64Payload = (value) => {
|
|
|
26
19
|
const sanitizeString = (value) => {
|
|
27
20
|
return isBase64Payload(value) ? exports.BASE64_REMOVED_PLACEHOLDER : value;
|
|
28
21
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
if (typeof value === "string")
|
|
39
|
-
|
|
22
|
+
const charge = (budget, units) => {
|
|
23
|
+
if (budget.remaining < units) {
|
|
24
|
+
budget.remaining = 0;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
budget.remaining -= units;
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
const sanitizeValueBounded = (value, seen, budget) => {
|
|
31
|
+
if (typeof value === "string") {
|
|
32
|
+
const sanitized = sanitizeString(value);
|
|
33
|
+
if (sanitized.length <= budget.remaining) {
|
|
34
|
+
budget.remaining -= sanitized.length;
|
|
35
|
+
return sanitized;
|
|
36
|
+
}
|
|
37
|
+
const sliced = sanitized.slice(0, budget.remaining);
|
|
38
|
+
budget.remaining = 0;
|
|
39
|
+
return sliced;
|
|
40
|
+
}
|
|
40
41
|
if (typeof value !== "object" || value === null)
|
|
41
42
|
return value;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
tracked.add(value);
|
|
43
|
+
if (seen.has(value))
|
|
44
|
+
return sanitizeValueBounded("[circular]", seen, budget);
|
|
45
|
+
seen.add(value);
|
|
46
46
|
try {
|
|
47
47
|
if (Array.isArray(value)) {
|
|
48
|
-
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const item of value) {
|
|
50
|
+
if (!charge(budget, 2))
|
|
51
|
+
break;
|
|
52
|
+
out.push(sanitizeValueBounded(item, seen, budget));
|
|
53
|
+
if (budget.remaining === 0)
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
49
57
|
}
|
|
50
58
|
if (!(0, utils_js_1.isRecord)(value))
|
|
51
59
|
return value;
|
|
52
60
|
const out = {};
|
|
53
61
|
for (const [key, entry] of Object.entries(value)) {
|
|
62
|
+
if (!charge(budget, key.length + 2))
|
|
63
|
+
break;
|
|
54
64
|
if (key === "data"
|
|
55
65
|
&& typeof entry === "string"
|
|
56
66
|
&& (value.type === "image" || value.type === "audio")) {
|
|
57
|
-
out[key] = exports.BINARY_REMOVED_PLACEHOLDER;
|
|
67
|
+
out[key] = sanitizeValueBounded(exports.BINARY_REMOVED_PLACEHOLDER, seen, budget);
|
|
58
68
|
}
|
|
59
69
|
else if (key === "blob" && typeof entry === "string") {
|
|
60
|
-
out[key] = exports.BINARY_REMOVED_PLACEHOLDER;
|
|
70
|
+
out[key] = sanitizeValueBounded(exports.BINARY_REMOVED_PLACEHOLDER, seen, budget);
|
|
61
71
|
}
|
|
62
72
|
else {
|
|
63
|
-
out[key] = (
|
|
73
|
+
out[key] = sanitizeValueBounded(entry, seen, budget);
|
|
64
74
|
}
|
|
75
|
+
if (budget.remaining === 0)
|
|
76
|
+
break;
|
|
65
77
|
}
|
|
66
78
|
return out;
|
|
67
79
|
}
|
|
68
80
|
finally {
|
|
69
|
-
|
|
81
|
+
seen.delete(value);
|
|
70
82
|
}
|
|
71
83
|
};
|
|
84
|
+
const sanitizeValue = (value, seen) => {
|
|
85
|
+
return sanitizeValueBounded(value, seen ?? new WeakSet(), { remaining: exports.SANITIZATION_BUDGET });
|
|
86
|
+
};
|
|
72
87
|
exports.sanitizeValue = sanitizeValue;
|
|
73
|
-
|
|
74
|
-
// whole payload with the placeholder rather than shipping unredacted data.
|
|
75
|
-
// The event itself still ships — losing a preview is recoverable, silently
|
|
76
|
-
// dropping calls from analytics is not.
|
|
77
|
-
const prepareForPreview = (value, redact) => {
|
|
88
|
+
const prepareForPreview = (value, redact, options = {}) => {
|
|
78
89
|
const sanitized = (0, exports.sanitizeValue)(value);
|
|
90
|
+
const protectedValue = options.redactSecrets === false
|
|
91
|
+
? sanitized
|
|
92
|
+
: (0, redact_secrets_js_1.redactSecretsInValue)(sanitized);
|
|
79
93
|
if (!redact)
|
|
80
|
-
return
|
|
94
|
+
return protectedValue;
|
|
81
95
|
try {
|
|
82
|
-
return redact(
|
|
96
|
+
return redact(protectedValue);
|
|
83
97
|
}
|
|
84
98
|
catch {
|
|
85
99
|
return exports.REDACTION_FAILED_PLACEHOLDER;
|
package/dist/cjs/server.js
CHANGED
|
@@ -8,6 +8,7 @@ const recorder_js_1 = require("./recorder.js");
|
|
|
8
8
|
const schema_js_1 = require("./schema.js");
|
|
9
9
|
const emit_js_1 = require("./emit.js");
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
11
|
+
const request_capability_js_1 = require("./request-capability.js");
|
|
11
12
|
const withAnalyticsStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
12
13
|
let prototypePatchInstalled = false;
|
|
13
14
|
// Mirrors the SDK's `isZodTypeLike`/`isZodRawShapeCompat` checks closely enough
|
|
@@ -154,6 +155,25 @@ const withMcpAnalytics = (config, createServer) => {
|
|
|
154
155
|
const recorder = (0, recorder_js_1.createAnalyticsRecorder)(config);
|
|
155
156
|
installPrototypePatchOnce();
|
|
156
157
|
const result = withAnalyticsStorage.run({ config, recorder }, createServer);
|
|
158
|
+
// Customer tools registered inside the factory are handled by the
|
|
159
|
+
// prototype patch above. The opt-in SDK-owned tool lives in the recorder's
|
|
160
|
+
// private registry, so attach only after leaving AsyncLocalStorage: this
|
|
161
|
+
// registers it once without adding telemetry fields or mutating its exact
|
|
162
|
+
// description.
|
|
163
|
+
if ((0, request_capability_js_1.isRequestCapabilityEnabled)(config) && !(result instanceof mcp_js_1.McpServer)) {
|
|
164
|
+
throw new Error("armature.requestCapability requires the server factory to return an McpServer instance.");
|
|
165
|
+
}
|
|
166
|
+
if ((0, request_capability_js_1.isRequestCapabilityEnabled)(config) && result instanceof mcp_js_1.McpServer) {
|
|
167
|
+
try {
|
|
168
|
+
recorder.attachToMcpServer(result);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (error instanceof Error && /already registered/i.test(error.message)) {
|
|
172
|
+
throw new Error('Tool name "request_capability" is reserved while armature.requestCapability is enabled.', { cause: error });
|
|
173
|
+
}
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
157
177
|
return { result, recorder };
|
|
158
178
|
};
|
|
159
179
|
exports.withMcpAnalytics = withMcpAnalytics;
|
package/dist/cjs/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/dist/esm/cli.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runDoctor, } from "./doctor.js";
|
|
3
|
+
import { parseDoctorArguments } from "./doctor-args.js";
|
|
4
|
+
const usage = "Armature MCP analytics doctor\n"
|
|
5
|
+
+ "\n"
|
|
6
|
+
+ "Usage:\n"
|
|
7
|
+
+ " mcp-analytics doctor --url <http://localhost:3000/mcp> [options]\n"
|
|
8
|
+
+ " mcp-analytics doctor --command <executable> [--arg <value> ...] [options]\n"
|
|
9
|
+
+ "\n"
|
|
10
|
+
+ "Checks:\n"
|
|
11
|
+
+ " - the local project declares an Armature SDK dependency\n"
|
|
12
|
+
+ " - MCP initialize and tools/list succeed\n"
|
|
13
|
+
+ " - every served tool exposes the Armature telemetry contract\n"
|
|
14
|
+
+ " - the existing ingest endpoint accepts the configured key\n"
|
|
15
|
+
+ "\n"
|
|
16
|
+
+ "Options:\n"
|
|
17
|
+
+ " --url <url> Inspect a running Streamable HTTP MCP server\n"
|
|
18
|
+
+ " --command <executable> Spawn and inspect a stdio MCP server\n"
|
|
19
|
+
+ " --arg <value> Add one argument to the stdio command (repeatable)\n"
|
|
20
|
+
+ " --header <name:value> Add an HTTP MCP header (repeatable; values are never printed)\n"
|
|
21
|
+
+ " --bearer-env <name> Read an HTTP bearer token from an environment variable\n"
|
|
22
|
+
+ " --cwd <path> Project directory for dependency detection and stdio spawn\n"
|
|
23
|
+
+ " --timeout <ms> Per-check timeout (default: 10000)\n"
|
|
24
|
+
+ " --capture <on|off> Expected telemetry capture state (default: on)\n"
|
|
25
|
+
+ " --skip-ingest Do not send the empty authenticated ingest health probe\n"
|
|
26
|
+
+ " --json Print a machine-readable report\n"
|
|
27
|
+
+ " --help Show this help\n"
|
|
28
|
+
+ "\n"
|
|
29
|
+
+ "The ingest key is read only from ANALYTICS_INGEST_API_KEY. The health probe\n"
|
|
30
|
+
+ "sends {\"schema_version\":1,\"events\":[]} and never sends tool or user content.";
|
|
31
|
+
const printReport = (report) => {
|
|
32
|
+
console.log("Armature MCP doctor\n");
|
|
33
|
+
for (const check of report.checks) {
|
|
34
|
+
console.log(check.status.toUpperCase().padEnd(4) + " " + check.label + ": " + check.detail);
|
|
35
|
+
if (check.remediation)
|
|
36
|
+
console.log(" Fix: " + check.remediation);
|
|
37
|
+
}
|
|
38
|
+
console.log("\nResult: " + (report.healthy ? "healthy" : "needs attention"));
|
|
39
|
+
};
|
|
40
|
+
const main = async () => {
|
|
41
|
+
let options;
|
|
42
|
+
try {
|
|
43
|
+
options = parseDoctorArguments(process.argv.slice(2));
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof Error && error.message !== "help") {
|
|
47
|
+
console.error("mcp-analytics doctor: " + error.message + "\n");
|
|
48
|
+
}
|
|
49
|
+
console.error(usage);
|
|
50
|
+
process.exitCode = error instanceof Error && error.message === "help" ? 0 : 2;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const report = await runDoctor(options);
|
|
54
|
+
if (options.json)
|
|
55
|
+
console.log(JSON.stringify(report, null, 2));
|
|
56
|
+
else
|
|
57
|
+
printReport(report);
|
|
58
|
+
process.exitCode = report.healthy ? 0 : 1;
|
|
59
|
+
};
|
|
60
|
+
void main();
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { defaultDoctorOptions } from "./doctor.js";
|
|
3
|
+
const valueAfter = (argv, index, flag, allowOptionLikeValue = false) => {
|
|
4
|
+
const value = argv[index + 1];
|
|
5
|
+
if (!value || (!allowOptionLikeValue && value.startsWith("--"))) {
|
|
6
|
+
throw new Error(flag + " requires a value");
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
const parseHeader = (raw) => {
|
|
11
|
+
const colon = raw.indexOf(":");
|
|
12
|
+
if (colon <= 0)
|
|
13
|
+
throw new Error("--header must use NAME: VALUE");
|
|
14
|
+
const name = raw.slice(0, colon).trim();
|
|
15
|
+
const value = raw.slice(colon + 1).trim();
|
|
16
|
+
if (!/^[!#$%&'*+.^_|~0-9A-Za-z-]+$/.test(name) || !value) {
|
|
17
|
+
throw new Error("--header must use a valid non-empty NAME: VALUE");
|
|
18
|
+
}
|
|
19
|
+
return [name, value];
|
|
20
|
+
};
|
|
21
|
+
export const parseDoctorArguments = (argv, environment = process.env) => {
|
|
22
|
+
const args = argv[0] === "doctor" ? argv.slice(1) : argv;
|
|
23
|
+
let url;
|
|
24
|
+
let command;
|
|
25
|
+
const commandArgs = [];
|
|
26
|
+
const headers = {};
|
|
27
|
+
let cwd = process.cwd();
|
|
28
|
+
let timeoutMs = 10_000;
|
|
29
|
+
let expectCapture = true;
|
|
30
|
+
let skipIngest = false;
|
|
31
|
+
let json = false;
|
|
32
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
33
|
+
const flag = args[index];
|
|
34
|
+
if (flag === "--url")
|
|
35
|
+
url = valueAfter(args, index++, flag);
|
|
36
|
+
else if (flag === "--command")
|
|
37
|
+
command = valueAfter(args, index++, flag);
|
|
38
|
+
else if (flag === "--arg")
|
|
39
|
+
commandArgs.push(valueAfter(args, index++, flag, true));
|
|
40
|
+
else if (flag === "--header") {
|
|
41
|
+
const [name, value] = parseHeader(valueAfter(args, index++, flag));
|
|
42
|
+
headers[name] = value;
|
|
43
|
+
}
|
|
44
|
+
else if (flag === "--bearer-env") {
|
|
45
|
+
const envName = valueAfter(args, index++, flag);
|
|
46
|
+
const token = environment[envName];
|
|
47
|
+
if (!token)
|
|
48
|
+
throw new Error("--bearer-env references unset variable " + envName);
|
|
49
|
+
headers.Authorization = "Bearer " + token;
|
|
50
|
+
}
|
|
51
|
+
else if (flag === "--cwd")
|
|
52
|
+
cwd = resolve(valueAfter(args, index++, flag));
|
|
53
|
+
else if (flag === "--timeout") {
|
|
54
|
+
timeoutMs = Number(valueAfter(args, index++, flag));
|
|
55
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 120_000) {
|
|
56
|
+
throw new Error("--timeout must be an integer between 100 and 120000");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (flag === "--capture") {
|
|
60
|
+
const value = valueAfter(args, index++, flag);
|
|
61
|
+
if (!["on", "off"].includes(value)) {
|
|
62
|
+
throw new Error("--capture must be on or off");
|
|
63
|
+
}
|
|
64
|
+
expectCapture = value === "on";
|
|
65
|
+
}
|
|
66
|
+
else if (flag === "--skip-ingest")
|
|
67
|
+
skipIngest = true;
|
|
68
|
+
else if (flag === "--json")
|
|
69
|
+
json = true;
|
|
70
|
+
else if (flag === "--help" || flag === "-h")
|
|
71
|
+
throw new Error("help");
|
|
72
|
+
else
|
|
73
|
+
throw new Error("unknown option: " + flag);
|
|
74
|
+
}
|
|
75
|
+
if (Boolean(url) === Boolean(command)) {
|
|
76
|
+
throw new Error("provide exactly one of --url or --command");
|
|
77
|
+
}
|
|
78
|
+
let target;
|
|
79
|
+
if (url) {
|
|
80
|
+
const parsed = new URL(url);
|
|
81
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
82
|
+
throw new Error("--url must use http or https");
|
|
83
|
+
}
|
|
84
|
+
target = { kind: "http", url: parsed.toString(), headers };
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
target = { kind: "stdio", command: command, args: commandArgs, cwd };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...defaultDoctorOptions(target),
|
|
91
|
+
cwd,
|
|
92
|
+
timeoutMs,
|
|
93
|
+
expectCapture,
|
|
94
|
+
skipIngest,
|
|
95
|
+
json,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type DoctorStatus = "pass" | "warn" | "fail";
|
|
2
|
+
export type DoctorCheck = {
|
|
3
|
+
id: string;
|
|
4
|
+
status: DoctorStatus;
|
|
5
|
+
label: string;
|
|
6
|
+
detail: string;
|
|
7
|
+
remediation?: string;
|
|
8
|
+
};
|
|
9
|
+
export type DoctorTarget = {
|
|
10
|
+
kind: "http";
|
|
11
|
+
url: string;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "stdio";
|
|
15
|
+
command: string;
|
|
16
|
+
args: string[];
|
|
17
|
+
cwd: string;
|
|
18
|
+
};
|
|
19
|
+
export type DoctorOptions = {
|
|
20
|
+
target: DoctorTarget;
|
|
21
|
+
cwd: string;
|
|
22
|
+
timeoutMs: number;
|
|
23
|
+
expectCapture: boolean;
|
|
24
|
+
skipIngest: boolean;
|
|
25
|
+
json: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type DoctorReport = {
|
|
28
|
+
healthy: boolean;
|
|
29
|
+
target: "http" | "stdio";
|
|
30
|
+
checks: DoctorCheck[];
|
|
31
|
+
};
|
|
32
|
+
export type DoctorTool = {
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
inputSchema?: unknown;
|
|
36
|
+
};
|
|
37
|
+
export type McpInspection = {
|
|
38
|
+
serverName?: string;
|
|
39
|
+
serverVersion?: string;
|
|
40
|
+
tools: DoctorTool[];
|
|
41
|
+
};
|
|
42
|
+
export type LocalSdk = {
|
|
43
|
+
language: "typescript" | "python" | "go";
|
|
44
|
+
declaration: string;
|
|
45
|
+
};
|
|
46
|
+
export type DoctorDependencies = {
|
|
47
|
+
inspectMcp: (options: DoctorOptions) => Promise<McpInspection>;
|
|
48
|
+
detectLocalSdks: (cwd: string) => Promise<LocalSdk[]>;
|
|
49
|
+
verifyIngest: (endpoint: string, apiKey: string, timeoutMs: number) => Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
export declare const inspectMcp: (options: DoctorOptions) => Promise<McpInspection>;
|
|
52
|
+
export declare const classifyToolInstrumentation: (tool: DoctorTool) => "current" | "legacy" | "owned" | "missing";
|
|
53
|
+
export declare const isSdkOwnedCapabilityTool: (tool: DoctorTool) => boolean;
|
|
54
|
+
export declare const inspectToolCoverage: (tools: DoctorTool[]) => {
|
|
55
|
+
current: string[];
|
|
56
|
+
legacy: string[];
|
|
57
|
+
owned: string[];
|
|
58
|
+
missing: string[];
|
|
59
|
+
sdkOwned: string[];
|
|
60
|
+
total: number;
|
|
61
|
+
};
|
|
62
|
+
export declare const detectLocalSdks: (cwd: string) => Promise<LocalSdk[]>;
|
|
63
|
+
export declare const verifyIngest: (endpoint: string, apiKey: string, timeoutMs: number) => Promise<void>;
|
|
64
|
+
export declare const runDoctor: (options: DoctorOptions, dependencies?: DoctorDependencies, environment?: NodeJS.ProcessEnv) => Promise<DoctorReport>;
|
|
65
|
+
export declare const defaultDoctorOptions: (target: DoctorTarget) => DoctorOptions;
|