@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/README.md
CHANGED
|
@@ -28,6 +28,27 @@ Create a server in the [Armature dashboard](https://app.armature.tech), copy its
|
|
|
28
28
|
export ANALYTICS_INGEST_API_KEY="..."
|
|
29
29
|
~~~
|
|
30
30
|
|
|
31
|
+
### Verify the installation locally
|
|
32
|
+
|
|
33
|
+
Run the doctor against the same environment and MCP server you plan to deploy:
|
|
34
|
+
|
|
35
|
+
~~~bash
|
|
36
|
+
npx @armature-tech/mcp-analytics doctor --url http://localhost:3000/mcp
|
|
37
|
+
~~~
|
|
38
|
+
|
|
39
|
+
For a stdio server:
|
|
40
|
+
|
|
41
|
+
~~~bash
|
|
42
|
+
npx @armature-tech/mcp-analytics doctor --command node --arg dist/server.js
|
|
43
|
+
~~~
|
|
44
|
+
|
|
45
|
+
The doctor performs an MCP handshake, lists the server's tools, verifies that
|
|
46
|
+
every tool exposes Armature's telemetry contract, and checks the existing
|
|
47
|
+
`ANALYTICS_INGEST_API_KEY` with an empty authenticated batch. The probe creates
|
|
48
|
+
no session and sends no tool arguments, responses, or user content. Add
|
|
49
|
+
`--skip-ingest` for a fully offline check, or `--json` for a support-ready
|
|
50
|
+
machine-readable report.
|
|
51
|
+
|
|
31
52
|
### 3. Instrument your MCP server
|
|
32
53
|
|
|
33
54
|
Wrap the factory that creates your existing **McpServer**:
|
|
@@ -195,14 +216,19 @@ type McpAnalyticsConfig = {
|
|
|
195
216
|
endpointUrl?: string;
|
|
196
217
|
apiKey?: string;
|
|
197
218
|
actorId?: string | ((input) => string | Promise<string>);
|
|
219
|
+
actorIdentifier?: string | ((input) => string | Promise<string>);
|
|
198
220
|
enabled?: boolean;
|
|
199
221
|
delivery?: "background" | "await";
|
|
200
222
|
timeoutMs?: number;
|
|
201
223
|
emit?: (batch) => void | Promise<void>;
|
|
202
224
|
onError?: (error, batch) => void;
|
|
203
225
|
captureTelemetry?: boolean;
|
|
226
|
+
redactSecrets?: boolean;
|
|
204
227
|
redact?: (value: unknown) => unknown;
|
|
228
|
+
redactEvent?: (event) => typeof event | null | Promise<typeof event | null>;
|
|
229
|
+
schedule?: (work: Promise<void>) => void;
|
|
205
230
|
telemetryFieldMap?: { user_intent?: string; agent_thinking?: string; user_frustration?: string };
|
|
231
|
+
requestCapability?: boolean;
|
|
206
232
|
};
|
|
207
233
|
};
|
|
208
234
|
~~~
|
|
@@ -212,31 +238,84 @@ type McpAnalyticsConfig = {
|
|
|
212
238
|
| **endpointUrl** | Armature cloud | Override the ingestion endpoint |
|
|
213
239
|
| **apiKey** | **ANALYTICS_INGEST_API_KEY** | Authenticate events and identify the MCP server |
|
|
214
240
|
| **actorId** | Derived from request auth | Supply a stable user or tenant seed |
|
|
241
|
+
| **actorIdentifier** | None | Store a caller-provided identifier verbatim |
|
|
215
242
|
| **enabled** | **true** | Enable or disable instrumentation |
|
|
216
243
|
| **delivery** | **"background"** | Use **"await"** for serverless or short-lived processes |
|
|
217
244
|
| **timeoutMs** | **500** | Set the delivery timeout |
|
|
218
245
|
| **emit** | Network emitter | Replace delivery for tests or custom pipelines |
|
|
219
246
|
| **onError** | None | Observe delivery failures |
|
|
220
247
|
| **captureTelemetry** | **true** | Disable conversation-derived telemetry entirely (see below) |
|
|
248
|
+
| **redactSecrets** | **true** | Disable only built-in high-confidence secret matching |
|
|
221
249
|
| **redact** | None | Redact sensitive data from previews before delivery (see below) |
|
|
250
|
+
| **redactEvent** | None | Mutate or drop the prepared whole tool-call event |
|
|
251
|
+
| **schedule** | None | Register background work with a serverless lifecycle primitive |
|
|
222
252
|
| **telemetryFieldMap** | None | Export existing argument fields as telemetry (see below) |
|
|
253
|
+
| **requestCapability** | **false** | Inject `request_capability` so agents can report an unmet tool need |
|
|
254
|
+
|
|
255
|
+
### Capability requests
|
|
256
|
+
|
|
257
|
+
Set **requestCapability: true** to add an SDK-owned `request_capability` tool
|
|
258
|
+
to the advertised tool list. The tool accepts one required `capability` string
|
|
259
|
+
and uses this description exactly:
|
|
260
|
+
|
|
261
|
+
> Request a capability that is not provided by the currently available tools. Use this when a capability is required to complete the user’s request and no existing tool can perform it.
|
|
262
|
+
|
|
263
|
+
Calls are recorded through the normal analytics pipeline and feed Armature's
|
|
264
|
+
unmet-demand signals. The option is off by default and is also suppressed when
|
|
265
|
+
**enabled: false** or no API key/custom **emit** delivery is configured. While
|
|
266
|
+
active, `request_capability` is reserved; rename a
|
|
267
|
+
customer-defined tool with the same name before enabling it.
|
|
268
|
+
|
|
269
|
+
```mermaid
|
|
270
|
+
sequenceDiagram
|
|
271
|
+
participant App
|
|
272
|
+
participant SDK as Armature SDK
|
|
273
|
+
participant MCP as MCP server
|
|
274
|
+
participant Agent
|
|
275
|
+
participant Ingest as Armature ingest
|
|
276
|
+
participant Demand as Demand pipeline
|
|
277
|
+
|
|
278
|
+
App->>SDK: Construct server with requestCapability enabled
|
|
279
|
+
SDK->>SDK: Check analytics enabled and delivery configured
|
|
280
|
+
alt Injection is disabled or cannot deliver
|
|
281
|
+
SDK-->>App: Return server without request_capability
|
|
282
|
+
else Injection is active
|
|
283
|
+
SDK->>MCP: Check reserved tool name
|
|
284
|
+
alt Name collision
|
|
285
|
+
SDK-->>App: Raise explicit configuration error
|
|
286
|
+
else Name is available
|
|
287
|
+
SDK->>MCP: Register request_capability schema and handler
|
|
288
|
+
Agent->>MCP: List tools
|
|
289
|
+
MCP-->>Agent: Advertise request_capability
|
|
290
|
+
Agent->>MCP: Call request_capability(capability)
|
|
291
|
+
MCP->>SDK: Record provenance-marked tool_call
|
|
292
|
+
MCP-->>Agent: Capability request acknowledged
|
|
293
|
+
SDK->>Ingest: Deliver analytics event
|
|
294
|
+
Ingest->>Demand: Add non-workflow request as failed_intent
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
```
|
|
223
298
|
|
|
224
299
|
### Telemetry capture and privacy
|
|
225
300
|
|
|
226
301
|
The SDK injects an optional `telemetry` object (`user_intent`, `agent_thinking`, `user_frustration`) into each wrapped tool's input schema. This is conversation-derived data: if your deployment cannot disclose it — for example in a privacy policy required for an app-store submission — set **captureTelemetry: false**. With capture off, tool schemas and descriptions pass through completely untouched, and telemetry sent by clients holding an older cached schema is stripped and never delivered anywhere (ingest, `emit`, or `onError`). Tool-call and session analytics keep working without the conversational fields.
|
|
227
302
|
|
|
228
|
-
Disclosure summary for privacy policies: with capture **on**, the SDK collects tool names, tool call inputs/outputs (size-capped previews), error messages, timing, a one-way hash of the actor seed, client name/version, and the agent-supplied `telemetry` fields above; recipients are your Armature workspace. With capture **off**, the `telemetry` fields are not collected.
|
|
303
|
+
Disclosure summary for privacy policies: with capture **on**, the SDK collects tool names, tool call inputs/outputs (size-capped previews), error messages, timing, a one-way hash of the actor seed, the verbatim `actorIdentifier` when configured, client name/version, and the agent-supplied `telemetry` fields above; recipients are your Armature workspace. With capture **off**, the `telemetry` fields are not collected.
|
|
229
304
|
|
|
230
305
|
If a tool's own input schema already declares a top-level `telemetry` property, the SDK treats that field as **yours**: the schema, description, and arguments pass through untouched, nothing is interpreted as Armature telemetry, and a warning is logged once at registration. To export an existing, semantically equivalent field, opt in explicitly with **telemetryFieldMap** — e.g. `{ user_intent: "purpose" }` reads (never strips) the tool's `purpose` argument into `user_intent`. Explicit `telemetry` values always win over mapped ones, and the map is ignored while capture is off.
|
|
231
306
|
|
|
232
307
|
### Redaction and binary payloads
|
|
233
308
|
|
|
234
|
-
Before any preview is serialized, the SDK
|
|
309
|
+
Before any preview is serialized, the SDK bounds sanitizer work to 65,536 units, removes binary/base64 payloads, and applies default-on high-confidence secret rules to inputs, outputs, errors, and telemetry text. Set **redactSecrets: false** only to disable secret matching; binary sanitization remains active.
|
|
310
|
+
|
|
311
|
+
The legacy synchronous **redact** hook runs next. Prefer async-capable **redactEvent** for new integrations: it receives the whole prepared tool-call candidate and may mutate it or return `null` to drop the tool event. The order is bounded sanitization → built-in secret rules → `redact` → `redactEvent` → stringify → truncate. Hook failures fail closed with `"[redaction failed]"` placeholders.
|
|
235
312
|
|
|
236
313
|
### Delivery
|
|
237
314
|
|
|
238
|
-
- **"background"**
|
|
239
|
-
- **"await"**
|
|
315
|
+
- **"background"** queues privacy work and returns immediately. It is intended for long-lived processes; call **await recorder.flush()** during shutdown.
|
|
316
|
+
- **"await"** drains sanitization, hooks, and delivery before returning. Use it for serverless functions and short-lived processes.
|
|
317
|
+
|
|
318
|
+
The FIFO queue batches up to 20 candidates, holds at most 1,000, and drops the oldest candidate on overflow. On platforms with `waitUntil`, pass **schedule: work => waitUntil(work)** to keep background delivery alive after the response.
|
|
240
319
|
|
|
241
320
|
If the API key is missing, delivery quietly no-ops for local development.
|
|
242
321
|
|
|
@@ -246,6 +325,22 @@ By default, the SDK derives an actor seed from request authentication informatio
|
|
|
246
325
|
|
|
247
326
|
The seed is hashed before transmission. Armature scopes the resulting actor identifier to your server.
|
|
248
327
|
|
|
328
|
+
Optional **actorIdentifier** attaches one caller-provided string without
|
|
329
|
+
changing the hashed actor id. The SDK does not interpret its contents: it may
|
|
330
|
+
be an internal ID, email, name, or any other non-empty string. It is sent
|
|
331
|
+
verbatim in a separate identity event only when its value changes:
|
|
332
|
+
|
|
333
|
+
~~~ts
|
|
334
|
+
armature: {
|
|
335
|
+
actorIdentifier: ({ ctx }) => (ctx as RequestContext).user.externalIdentifier,
|
|
336
|
+
}
|
|
337
|
+
~~~
|
|
338
|
+
|
|
339
|
+
The SDK hashes **actorIdentifier** into `actor_id` and also sends the original
|
|
340
|
+
value verbatim as `metadata.identifier`. The SDK validates only that it is a
|
|
341
|
+
non-empty string no larger than 8 KiB. When **actorIdentifier** is absent,
|
|
342
|
+
**actorId** retains its existing hashed-only behavior.
|
|
343
|
+
|
|
249
344
|
## Environment variables
|
|
250
345
|
|
|
251
346
|
| Variable | Purpose |
|
package/SKILL.md
CHANGED
|
@@ -71,19 +71,25 @@ for local dev — say so once, don't add guards.
|
|
|
71
71
|
|
|
72
72
|
## Step 4: Pick a delivery mode
|
|
73
73
|
|
|
74
|
-
The default is `delivery: "background"
|
|
75
|
-
|
|
74
|
+
The default is `delivery: "background"`, which queues sanitization, redaction,
|
|
75
|
+
and delivery off the response path. A serverless function may freeze before
|
|
76
|
+
that work completes.
|
|
76
77
|
|
|
77
78
|
Use this decision table:
|
|
78
79
|
|
|
79
80
|
| Runtime | `delivery` |
|
|
80
81
|
| --- | --- |
|
|
81
|
-
| Vercel / Lambda / Cloudflare Workers / any per-request serverless | `"await"` |
|
|
82
|
+
| Vercel / Lambda / Cloudflare Workers / any per-request serverless | `"await"`, or `"background"` with `schedule: work => waitUntil(work)` |
|
|
82
83
|
| Long-lived Node process, container, fly machine, persistent server | `"background"` + call `recorder.flush()` on `SIGTERM` |
|
|
83
84
|
|
|
84
85
|
Detect the runtime from the repo (look for `vercel.json`, `wrangler.toml`, `Dockerfile`,
|
|
85
86
|
`fly.toml`, `package.json` scripts). If you're not sure, default to `"await"` — it's the
|
|
86
|
-
safe choice
|
|
87
|
+
safe choice. `flush()` drains the entire privacy queue, not only active POSTs.
|
|
88
|
+
|
|
89
|
+
Built-in high-confidence secret redaction is default-on. Prefer the async
|
|
90
|
+
whole-event `redactEvent` hook for custom policy; it may mutate or drop a tool
|
|
91
|
+
event. The legacy `redact` hook remains supported and runs first. Set
|
|
92
|
+
`redactSecrets: false` only when explicitly replacing the built-ins.
|
|
87
93
|
|
|
88
94
|
## Step 5: Make the edits
|
|
89
95
|
|
|
@@ -314,6 +320,11 @@ expose auth under those names don't need a custom `actorId` resolver.
|
|
|
314
320
|
`actorId` is configured the normal way on `config.armature.actorId` — the resolver
|
|
315
321
|
receives `ctx` set to Mastra's second-arg context.
|
|
316
322
|
|
|
323
|
+
Optional verbatim identification uses `actorIdentifier`. It accepts any
|
|
324
|
+
non-empty string up to 8 KiB and emits an identity event only when the value
|
|
325
|
+
changes. The same value is hashed into `actor_id` and sent verbatim as the
|
|
326
|
+
identifier; `actorId` remains the hashed-only fallback when this is absent.
|
|
327
|
+
|
|
317
328
|
The SDK does not import `@mastra/*` at runtime (structural typing), so the adapter
|
|
318
329
|
works with whatever Mastra version the customer is on. Do not add `@mastra/*` to
|
|
319
330
|
their dependencies — it's already there if Shape D applies.
|
|
@@ -335,6 +346,20 @@ already has a custom `initialize` handler — otherwise skip it.
|
|
|
335
346
|
|
|
336
347
|
Two checks. Don't skip them.
|
|
337
348
|
|
|
349
|
+
Start with the packaged local doctor whenever the server can be launched over
|
|
350
|
+
Streamable HTTP or stdio:
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
npx @armature-tech/mcp-analytics doctor --url http://localhost:3000/mcp
|
|
354
|
+
# or: npx @armature-tech/mcp-analytics doctor --command node --arg dist/server.js
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Run it with the same `ANALYTICS_INGEST_API_KEY` and
|
|
358
|
+
`ANALYTICS_INGEST_URL` environment as the server. It verifies the MCP
|
|
359
|
+
handshake, every served tool's public wrapping contract, and ingest auth using
|
|
360
|
+
an empty content-free batch. Use `--skip-ingest` only when the user explicitly
|
|
361
|
+
wants an offline check. Include the doctor result in the handoff.
|
|
362
|
+
|
|
338
363
|
**Check 1 — Schema includes telemetry.** Spin up the server, ask it for `tools/list`, and
|
|
339
364
|
confirm one of the tools has a `telemetry` property in its `inputSchema`. If the project
|
|
340
365
|
has a dev server script, use it; otherwise write a 10-line script that imports the factory
|
package/dist/cjs/cli.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const doctor_js_1 = require("./doctor.js");
|
|
5
|
+
const doctor_args_js_1 = require("./doctor-args.js");
|
|
6
|
+
const usage = "Armature MCP analytics doctor\n"
|
|
7
|
+
+ "\n"
|
|
8
|
+
+ "Usage:\n"
|
|
9
|
+
+ " mcp-analytics doctor --url <http://localhost:3000/mcp> [options]\n"
|
|
10
|
+
+ " mcp-analytics doctor --command <executable> [--arg <value> ...] [options]\n"
|
|
11
|
+
+ "\n"
|
|
12
|
+
+ "Checks:\n"
|
|
13
|
+
+ " - the local project declares an Armature SDK dependency\n"
|
|
14
|
+
+ " - MCP initialize and tools/list succeed\n"
|
|
15
|
+
+ " - every served tool exposes the Armature telemetry contract\n"
|
|
16
|
+
+ " - the existing ingest endpoint accepts the configured key\n"
|
|
17
|
+
+ "\n"
|
|
18
|
+
+ "Options:\n"
|
|
19
|
+
+ " --url <url> Inspect a running Streamable HTTP MCP server\n"
|
|
20
|
+
+ " --command <executable> Spawn and inspect a stdio MCP server\n"
|
|
21
|
+
+ " --arg <value> Add one argument to the stdio command (repeatable)\n"
|
|
22
|
+
+ " --header <name:value> Add an HTTP MCP header (repeatable; values are never printed)\n"
|
|
23
|
+
+ " --bearer-env <name> Read an HTTP bearer token from an environment variable\n"
|
|
24
|
+
+ " --cwd <path> Project directory for dependency detection and stdio spawn\n"
|
|
25
|
+
+ " --timeout <ms> Per-check timeout (default: 10000)\n"
|
|
26
|
+
+ " --capture <on|off> Expected telemetry capture state (default: on)\n"
|
|
27
|
+
+ " --skip-ingest Do not send the empty authenticated ingest health probe\n"
|
|
28
|
+
+ " --json Print a machine-readable report\n"
|
|
29
|
+
+ " --help Show this help\n"
|
|
30
|
+
+ "\n"
|
|
31
|
+
+ "The ingest key is read only from ANALYTICS_INGEST_API_KEY. The health probe\n"
|
|
32
|
+
+ "sends {\"schema_version\":1,\"events\":[]} and never sends tool or user content.";
|
|
33
|
+
const printReport = (report) => {
|
|
34
|
+
console.log("Armature MCP doctor\n");
|
|
35
|
+
for (const check of report.checks) {
|
|
36
|
+
console.log(check.status.toUpperCase().padEnd(4) + " " + check.label + ": " + check.detail);
|
|
37
|
+
if (check.remediation)
|
|
38
|
+
console.log(" Fix: " + check.remediation);
|
|
39
|
+
}
|
|
40
|
+
console.log("\nResult: " + (report.healthy ? "healthy" : "needs attention"));
|
|
41
|
+
};
|
|
42
|
+
const main = async () => {
|
|
43
|
+
let options;
|
|
44
|
+
try {
|
|
45
|
+
options = (0, doctor_args_js_1.parseDoctorArguments)(process.argv.slice(2));
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof Error && error.message !== "help") {
|
|
49
|
+
console.error("mcp-analytics doctor: " + error.message + "\n");
|
|
50
|
+
}
|
|
51
|
+
console.error(usage);
|
|
52
|
+
process.exitCode = error instanceof Error && error.message === "help" ? 0 : 2;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const report = await (0, doctor_js_1.runDoctor)(options);
|
|
56
|
+
if (options.json)
|
|
57
|
+
console.log(JSON.stringify(report, null, 2));
|
|
58
|
+
else
|
|
59
|
+
printReport(report);
|
|
60
|
+
process.exitCode = report.healthy ? 0 : 1;
|
|
61
|
+
};
|
|
62
|
+
void main();
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDoctorArguments = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const doctor_js_1 = require("./doctor.js");
|
|
6
|
+
const valueAfter = (argv, index, flag, allowOptionLikeValue = false) => {
|
|
7
|
+
const value = argv[index + 1];
|
|
8
|
+
if (!value || (!allowOptionLikeValue && value.startsWith("--"))) {
|
|
9
|
+
throw new Error(flag + " requires a value");
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
const parseHeader = (raw) => {
|
|
14
|
+
const colon = raw.indexOf(":");
|
|
15
|
+
if (colon <= 0)
|
|
16
|
+
throw new Error("--header must use NAME: VALUE");
|
|
17
|
+
const name = raw.slice(0, colon).trim();
|
|
18
|
+
const value = raw.slice(colon + 1).trim();
|
|
19
|
+
if (!/^[!#$%&'*+.^_|~0-9A-Za-z-]+$/.test(name) || !value) {
|
|
20
|
+
throw new Error("--header must use a valid non-empty NAME: VALUE");
|
|
21
|
+
}
|
|
22
|
+
return [name, value];
|
|
23
|
+
};
|
|
24
|
+
const parseDoctorArguments = (argv, environment = process.env) => {
|
|
25
|
+
const args = argv[0] === "doctor" ? argv.slice(1) : argv;
|
|
26
|
+
let url;
|
|
27
|
+
let command;
|
|
28
|
+
const commandArgs = [];
|
|
29
|
+
const headers = {};
|
|
30
|
+
let cwd = process.cwd();
|
|
31
|
+
let timeoutMs = 10_000;
|
|
32
|
+
let expectCapture = true;
|
|
33
|
+
let skipIngest = false;
|
|
34
|
+
let json = false;
|
|
35
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
36
|
+
const flag = args[index];
|
|
37
|
+
if (flag === "--url")
|
|
38
|
+
url = valueAfter(args, index++, flag);
|
|
39
|
+
else if (flag === "--command")
|
|
40
|
+
command = valueAfter(args, index++, flag);
|
|
41
|
+
else if (flag === "--arg")
|
|
42
|
+
commandArgs.push(valueAfter(args, index++, flag, true));
|
|
43
|
+
else if (flag === "--header") {
|
|
44
|
+
const [name, value] = parseHeader(valueAfter(args, index++, flag));
|
|
45
|
+
headers[name] = value;
|
|
46
|
+
}
|
|
47
|
+
else if (flag === "--bearer-env") {
|
|
48
|
+
const envName = valueAfter(args, index++, flag);
|
|
49
|
+
const token = environment[envName];
|
|
50
|
+
if (!token)
|
|
51
|
+
throw new Error("--bearer-env references unset variable " + envName);
|
|
52
|
+
headers.Authorization = "Bearer " + token;
|
|
53
|
+
}
|
|
54
|
+
else if (flag === "--cwd")
|
|
55
|
+
cwd = (0, node_path_1.resolve)(valueAfter(args, index++, flag));
|
|
56
|
+
else if (flag === "--timeout") {
|
|
57
|
+
timeoutMs = Number(valueAfter(args, index++, flag));
|
|
58
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 120_000) {
|
|
59
|
+
throw new Error("--timeout must be an integer between 100 and 120000");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (flag === "--capture") {
|
|
63
|
+
const value = valueAfter(args, index++, flag);
|
|
64
|
+
if (!["on", "off"].includes(value)) {
|
|
65
|
+
throw new Error("--capture must be on or off");
|
|
66
|
+
}
|
|
67
|
+
expectCapture = value === "on";
|
|
68
|
+
}
|
|
69
|
+
else if (flag === "--skip-ingest")
|
|
70
|
+
skipIngest = true;
|
|
71
|
+
else if (flag === "--json")
|
|
72
|
+
json = true;
|
|
73
|
+
else if (flag === "--help" || flag === "-h")
|
|
74
|
+
throw new Error("help");
|
|
75
|
+
else
|
|
76
|
+
throw new Error("unknown option: " + flag);
|
|
77
|
+
}
|
|
78
|
+
if (Boolean(url) === Boolean(command)) {
|
|
79
|
+
throw new Error("provide exactly one of --url or --command");
|
|
80
|
+
}
|
|
81
|
+
let target;
|
|
82
|
+
if (url) {
|
|
83
|
+
const parsed = new URL(url);
|
|
84
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
85
|
+
throw new Error("--url must use http or https");
|
|
86
|
+
}
|
|
87
|
+
target = { kind: "http", url: parsed.toString(), headers };
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
target = { kind: "stdio", command: command, args: commandArgs, cwd };
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...(0, doctor_js_1.defaultDoctorOptions)(target),
|
|
94
|
+
cwd,
|
|
95
|
+
timeoutMs,
|
|
96
|
+
expectCapture,
|
|
97
|
+
skipIngest,
|
|
98
|
+
json,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
exports.parseDoctorArguments = parseDoctorArguments;
|
|
@@ -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;
|