@armature-tech/mcp-analytics 0.6.17 → 0.6.19

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 (59) hide show
  1. package/README.md +116 -4
  2. package/SKILL.md +30 -5
  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 +63 -0
  8. package/dist/cjs/doctor.js +325 -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 +19 -5
  12. package/dist/cjs/events.js +141 -22
  13. package/dist/cjs/index.d.ts +7 -4
  14. package/dist/cjs/index.js +25 -1
  15. package/dist/cjs/mastra.js +50 -4
  16. package/dist/cjs/queue.d.ts +9 -0
  17. package/dist/cjs/queue.js +116 -0
  18. package/dist/cjs/recorder.js +194 -81
  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 +10 -0
  24. package/dist/cjs/sanitize.js +102 -0
  25. package/dist/cjs/schema.d.ts +18 -66
  26. package/dist/cjs/schema.js +129 -106
  27. package/dist/cjs/server.js +36 -8
  28. package/dist/cjs/stateless-http.d.ts +1 -1
  29. package/dist/cjs/stateless-http.js +8 -2
  30. package/dist/cjs/types.d.ts +42 -3
  31. package/dist/esm/cli.d.ts +2 -0
  32. package/dist/esm/cli.js +60 -0
  33. package/dist/esm/doctor-args.d.ts +2 -0
  34. package/dist/esm/doctor-args.js +97 -0
  35. package/dist/esm/doctor.d.ts +63 -0
  36. package/dist/esm/doctor.js +315 -0
  37. package/dist/esm/emit.d.ts +3 -0
  38. package/dist/esm/emit.js +14 -1
  39. package/dist/esm/events.d.ts +19 -5
  40. package/dist/esm/events.js +138 -21
  41. package/dist/esm/index.d.ts +7 -4
  42. package/dist/esm/index.js +6 -3
  43. package/dist/esm/mastra.js +51 -5
  44. package/dist/esm/queue.d.ts +9 -0
  45. package/dist/esm/queue.js +112 -0
  46. package/dist/esm/recorder.js +197 -84
  47. package/dist/esm/redact-secrets.d.ts +10 -0
  48. package/dist/esm/redact-secrets.js +115 -0
  49. package/dist/esm/request-capability.d.ts +12 -0
  50. package/dist/esm/request-capability.js +45 -0
  51. package/dist/esm/sanitize.d.ts +10 -0
  52. package/dist/esm/sanitize.js +97 -0
  53. package/dist/esm/schema.d.ts +18 -66
  54. package/dist/esm/schema.js +124 -105
  55. package/dist/esm/server.js +37 -9
  56. package/dist/esm/stateless-http.d.ts +1 -1
  57. package/dist/esm/stateless-http.js +8 -2
  58. package/dist/esm/types.d.ts +42 -3
  59. package/package.json +8 -1
@@ -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
@@ -55,18 +56,23 @@ const parseDeprecatedToolArgs = (rest) => {
55
56
  const callback = args[0];
56
57
  return { description, inputSchema, annotations, callback };
57
58
  };
58
- const wrapCallbackWithAnalytics = (name, cb, originalHasInputSchema, ctx) => {
59
+ const wrapCallbackWithAnalytics = (name, cb,
60
+ // The SDK invokes the wrapped callback according to the schema we REGISTERED
61
+ // (args + extra when present, just extra when absent); the original callback
62
+ // expects arguments according to the schema the CUSTOMER declared. The two
63
+ // differ for schema-less tools in injected mode, so both flags are needed.
64
+ originalHasInputSchema, registeredHasInputSchema, telemetryMode, ctx) => {
59
65
  const { recorder } = ctx;
60
66
  return async (argsOrExtra, maybeExtra) => {
61
67
  const startedAtMs = Date.now();
62
68
  const startedAt = new Date(startedAtMs).toISOString();
63
69
  const requestId = (0, node_crypto_1.randomUUID)();
64
- const extra = (originalHasInputSchema ? maybeExtra : argsOrExtra);
65
- const { args, telemetry } = recorder.extractTelemetry(argsOrExtra);
70
+ const extra = (registeredHasInputSchema ? maybeExtra : argsOrExtra);
71
+ const { args, telemetry } = recorder.extractTelemetry(registeredHasInputSchema ? argsOrExtra : undefined, telemetryMode);
66
72
  try {
67
73
  const output = originalHasInputSchema
68
- ? await cb(args, maybeExtra)
69
- : await cb(maybeExtra ?? argsOrExtra);
74
+ ? await cb(args, extra)
75
+ : await cb(extra);
70
76
  // A returned MCP error result (`isError: true`) is a failed call even
71
77
  // though the callback resolved; record it as an error while returning the
72
78
  // original output to the caller untouched.
@@ -115,12 +121,15 @@ const installPrototypePatchOnce = () => {
115
121
  }
116
122
  const { config } = ctx;
117
123
  const originalHasInputSchema = toolConfig.inputSchema !== undefined;
124
+ const plan = (0, schema_js_1.planToolTelemetry)(name, toolConfig.inputSchema, config);
125
+ const registeredHasInputSchema = plan.inputSchema !== undefined;
126
+ const description = plan.applyDescription(toolConfig.description);
118
127
  const instrumentedConfig = {
119
128
  ...toolConfig,
120
- description: (0, schema_js_1.appendTelemetryHint)(toolConfig.description),
121
- inputSchema: (0, schema_js_1.decorateInputSchemaWithTelemetry)(toolConfig.inputSchema, config),
129
+ ...(description !== undefined ? { description } : {}),
130
+ ...(registeredHasInputSchema ? { inputSchema: plan.inputSchema } : {}),
122
131
  };
123
- const wrappedCallback = wrapCallbackWithAnalytics(name, cb, originalHasInputSchema, ctx);
132
+ const wrappedCallback = wrapCallbackWithAnalytics(name, cb, originalHasInputSchema, registeredHasInputSchema, plan.mode, ctx);
124
133
  return originalRegisterTool.call(this, name, instrumentedConfig, wrappedCallback);
125
134
  };
126
135
  // PRIA and other older codebases still use the deprecated `server.tool(...)`
@@ -146,6 +155,25 @@ const withMcpAnalytics = (config, createServer) => {
146
155
  const recorder = (0, recorder_js_1.createAnalyticsRecorder)(config);
147
156
  installPrototypePatchOnce();
148
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
+ }
149
177
  return { result, recorder };
150
178
  };
151
179
  exports.withMcpAnalytics = withMcpAnalytics;
@@ -1,6 +1,6 @@
1
1
  import type { HeaderBag, McpClientInfo } from "./types.js";
2
2
  /** Mint a session id that carries the client identity from `initialize`. */
3
- export declare const buildStatelessSessionId: (clientInfo?: McpClientInfo) => string;
3
+ export declare const buildStatelessSessionId: (clientInfo?: McpClientInfo, sessionSeed?: string) => string;
4
4
  /** Recover the client identity from an identity-bearing session id. */
5
5
  export declare const parseStatelessSessionClientInfo: (sessionId: string | undefined) => McpClientInfo | undefined;
6
6
  export type StatelessHttpSession = {
@@ -28,6 +28,7 @@ const utils_js_1 = require("./utils.js");
28
28
  // });
29
29
  // await analytics.dispatch(name, args, { ctx, ...session.dispatchContext });
30
30
  const SESSION_ID_RE = /^mcp_([A-Za-z0-9.-]+)_v_([A-Za-z0-9.-]*)_([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/;
31
+ const SESSION_SEED_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
31
32
  const ANONYMOUS_NAME = "unknown";
32
33
  const slugPart = (value, fallback) => {
33
34
  const slug = String(value ?? "")
@@ -40,7 +41,11 @@ const slugPart = (value, fallback) => {
40
41
  /** Mint a session id that carries the client identity from `initialize`. */
41
42
  // Version falls back to an empty segment (`_v__`) so a client that never
42
43
  // reported a version stays distinguishable from one reporting literal "0".
43
- const buildStatelessSessionId = (clientInfo) => `mcp_${slugPart(clientInfo?.name, ANONYMOUS_NAME)}_v_${slugPart(clientInfo?.version, "")}_${(0, node_crypto_1.randomUUID)()}`;
44
+ const buildStatelessSessionId = (clientInfo, sessionSeed) => {
45
+ const seed = String(sessionSeed ?? "").trim();
46
+ const uuid = SESSION_SEED_RE.test(seed) ? seed.toLowerCase() : (0, node_crypto_1.randomUUID)();
47
+ return `mcp_${slugPart(clientInfo?.name, ANONYMOUS_NAME)}_v_${slugPart(clientInfo?.version, "")}_${uuid}`;
48
+ };
44
49
  exports.buildStatelessSessionId = buildStatelessSessionId;
45
50
  /** Recover the client identity from an identity-bearing session id. */
46
51
  const parseStatelessSessionClientInfo = (sessionId) => {
@@ -69,7 +74,8 @@ const clientInfoFromInitialize = (message) => {
69
74
  const resolveStatelessHttpSession = (input) => {
70
75
  const initialize = findInitializeMessage(input.body);
71
76
  if (initialize) {
72
- const sessionId = (0, exports.buildStatelessSessionId)(clientInfoFromInitialize(initialize));
77
+ const clientInfo = clientInfoFromInitialize(initialize);
78
+ const sessionId = (0, exports.buildStatelessSessionId)(clientInfo, (0, utils_js_1.headerValue)(input.headers, "x-armature-session-seed") ?? undefined);
73
79
  return {
74
80
  sessionId,
75
81
  sessionIdGenerator: () => sessionId,
@@ -39,26 +39,62 @@ 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>;
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>;
56
+ export type TelemetryFieldMap = {
57
+ /** @deprecated `user_turn` is no longer collected; this mapping is ignored. */
58
+ user_turn?: string;
59
+ user_intent?: string;
60
+ agent_thinking?: string;
61
+ user_frustration?: string;
62
+ };
42
63
  export type McpAnalyticsConfig = {
43
64
  armature?: {
44
65
  endpointUrl?: string;
45
66
  apiKey?: string;
46
67
  actorId?: string | ActorIdResolver;
68
+ /** Optional caller-provided identifier stored verbatim. */
69
+ actorIdentifier?: string | ActorIdentifierResolver;
47
70
  enabled?: boolean;
48
71
  delivery?: "background" | "await";
49
72
  emit?: TelemetryEmitter;
50
73
  onError?: (error: unknown, batch: AnalyticsIngestBatch) => void;
51
74
  timeoutMs?: number;
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. */
79
+ redact?: RedactFunction;
80
+ redactEvent?: RedactEventHook;
81
+ /** Register background work with a platform lifecycle primitive (for example waitUntil). */
82
+ schedule?: (work: Promise<void>) => void;
83
+ telemetryFieldMap?: TelemetryFieldMap;
84
+ requestCapability?: boolean;
52
85
  };
53
86
  };
87
+ export type TelemetryMode = "injected" | "owned" | "scrub";
54
88
  export type InternalMcpAnalyticsConfig = McpAnalyticsConfig & {
89
+ /** @deprecated Required-per-call intent conflicts with sparse intent declarations and is ignored. */
55
90
  telemetry?: {
56
91
  user_intent?: "required" | "optional";
57
- /** @deprecated Pre-V1 spelling of `user_intent`; still honored. */
92
+ /** @deprecated Pre-V1 spelling retained for source compatibility; ignored. */
58
93
  intent?: "required" | "optional";
59
94
  };
60
95
  };
61
96
  export type TelemetryArgs = {
97
+ /** @deprecated `user_turn` is accepted from cached clients but ignored. */
62
98
  user_turn?: number;
63
99
  user_intent?: string;
64
100
  agent_thinking?: string;
@@ -113,6 +149,7 @@ export type RecordToolCallEvent = {
113
149
  error?: unknown;
114
150
  clientInfo?: McpClientInfo;
115
151
  workflowRunId?: string;
152
+ capabilityRequest?: boolean;
116
153
  };
117
154
  export type InstrumentToolCallEvent = {
118
155
  name: string;
@@ -125,6 +162,8 @@ export type InstrumentToolCallEvent = {
125
162
  requestId?: string;
126
163
  clientInfo?: McpClientInfo;
127
164
  workflowRunId?: string;
165
+ telemetryMode?: TelemetryMode;
166
+ capabilityRequest?: boolean;
128
167
  };
129
168
  export type ToolCallHandler<T> = (args: unknown) => T | Promise<T>;
130
169
  export type ToolHandlerContext = {
@@ -151,7 +190,7 @@ export type McpServerInfo = {
151
190
  };
152
191
  export type AnalyticsRecorder = {
153
192
  decorateDefinitions: (defs: ToolDefinition[]) => ToolDefinition[];
154
- extractTelemetry: (args: unknown) => ExtractedToolArguments;
193
+ extractTelemetry: (args: unknown, mode?: TelemetryMode) => ExtractedToolArguments;
155
194
  recordToolCall: (event: RecordToolCallEvent) => Promise<void>;
156
195
  recordSessionInit: (event: RecordSessionInitEvent) => Promise<void>;
157
196
  instrumentToolCall: <T>(event: InstrumentToolCallEvent, handler: ToolCallHandler<T>) => Promise<T>;
@@ -163,7 +202,7 @@ export type AnalyticsRecorder = {
163
202
  createMcpServer: (info: McpServerInfo) => McpServer;
164
203
  flush: () => Promise<void>;
165
204
  };
166
- export type AnalyticsEventKind = "tool_call" | "session_init";
205
+ export type AnalyticsEventKind = "tool_call" | "session_init" | "actor_identity";
167
206
  export type AnalyticsIngestEvent = {
168
207
  event_id: string;
169
208
  kind: AnalyticsEventKind;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -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,2 @@
1
+ import { type DoctorOptions } from "./doctor.js";
2
+ export declare const parseDoctorArguments: (argv: string[], environment?: NodeJS.ProcessEnv) => DoctorOptions;
@@ -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,63 @@
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 inspectToolCoverage: (tools: DoctorTool[]) => {
54
+ current: string[];
55
+ legacy: string[];
56
+ owned: string[];
57
+ missing: string[];
58
+ total: number;
59
+ };
60
+ export declare const detectLocalSdks: (cwd: string) => Promise<LocalSdk[]>;
61
+ export declare const verifyIngest: (endpoint: string, apiKey: string, timeoutMs: number) => Promise<void>;
62
+ export declare const runDoctor: (options: DoctorOptions, dependencies?: DoctorDependencies, environment?: NodeJS.ProcessEnv) => Promise<DoctorReport>;
63
+ export declare const defaultDoctorOptions: (target: DoctorTarget) => DoctorOptions;