@vantageos/mcp-doctor 0.9.1 → 0.10.0
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/CHANGELOG.md +33 -0
- package/README.md +10 -0
- package/dist/doctor.d.ts +47 -2
- package/dist/doctor.js +463 -92
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
All notable changes to `@vantageos/mcp-doctor` are documented here.
|
|
4
4
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 0.10.0 — 2026-10-29
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- **`--url <https url>`: judge a remote streamable-HTTP MCP server the way a customer reaches it.** Dynamic mode
|
|
10
|
+
used to spawn the server over stdio, so an HTTP-only server came back `could-not-judge` on every runtime rule
|
|
11
|
+
("timeout: server did not answer initialize+tools/list" / "exited before handshake"). `--url` implies dynamic,
|
|
12
|
+
takes no launch target (refused loudly if one is given, or `--mode` other than dynamic), and runs the seven rules
|
|
13
|
+
that read what a running server serves (D8, D16, C11, C19, C21, C25, DServer2). The source-tree rules have no tree
|
|
14
|
+
to read over HTTP and are not run; the run says so on stderr.
|
|
15
|
+
- **One probe path behind a transport.** The introspector's handshake, `tools/list` and invalid-cursor probes are
|
|
16
|
+
unchanged and shared; only the transport differs (stdio child or streamable HTTP: JSON or SSE answers, session id
|
|
17
|
+
and negotiated protocol version carried). No second copy of the rules.
|
|
18
|
+
- **Auth that never prints.** `--bearer-env VAR` reads the token from the named environment variable (never a
|
|
19
|
+
command-line argument); `--header "Name: value"` is repeatable. Header values, the token, URL userinfo and URL
|
|
20
|
+
query values are scrubbed (`[redacted]`) from everything printed, including text a server echoes back.
|
|
21
|
+
- `--source DIR` (the server's source tree: D8 eval counts, D16 package version, C19/C21 ceiling, expected commit
|
|
22
|
+
via `git rev-parse HEAD`) and `--expected-commit SHA` (C25). Without them those rules say "no source tree given"
|
|
23
|
+
(`could-not-judge`), never zero coverage or a pass.
|
|
24
|
+
- Programmatic: `introspectEndpoint`, `endpointSecrets`, `redactSecrets` are exported.
|
|
25
|
+
|
|
26
|
+
### Fail-closed, with the cause named
|
|
27
|
+
An unreachable host (`unreachable: ECONNREFUSED ...`), a TLS error, HTTP 401/403 (`authentication refused`), a
|
|
28
|
+
redirect (never followed: a credential is not sent to a redirect target), any other non-2xx, a response that is not
|
|
29
|
+
MCP (wrong content-type, a body or SSE event that is not JSON-RPC), and an `initialize` / `tools/list` the server
|
|
30
|
+
answers with a JSON-RPC error are each `could-not-judge` with that cause. The last also applies to stdio: an error
|
|
31
|
+
answer is no longer read as an empty tool list. `http://` is accepted only for a loopback host.
|
|
32
|
+
|
|
33
|
+
### Proof
|
|
34
|
+
`tests/url-mode.test.ts` (36 tests, in-process HTTP server, the built CLI spawned asynchronously) and
|
|
35
|
+
`scripts/url-mode-mutation-probe.sh`: one mutation per formulation of the transport branch (401, 403, redirect,
|
|
36
|
+
non-2xx, non-MCP body, non-JSON-RPC member, SSE event, TLS, unreachable cause, both scrub layers, query and
|
|
37
|
+
token-in-header collection), each landing grep-asserted, each turning the suite red, restoration proven.
|
|
38
|
+
|
|
6
39
|
## 0.9.1 — 2026-10-28
|
|
7
40
|
|
|
8
41
|
Two could-not-judge classes of S-36..S-41 that were false, found by running 0.9.0 on
|
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ The binary's own `--help` is the authority; this is what it prints:
|
|
|
47
47
|
|
|
48
48
|
```
|
|
49
49
|
usage: mcp-doctor <source-tree-path> [--mode=static|dynamic|both] [--backend=<convex-dir>] [--json]
|
|
50
|
+
mcp-doctor --url <https url> [--bearer-env VAR] [--header "Name: value"]... [--source DIR] [--expected-commit SHA] [--json]
|
|
50
51
|
|
|
51
52
|
--mode=static read the tree only (default)
|
|
52
53
|
--mode=dynamic launch the server and judge what it serves
|
|
@@ -56,6 +57,15 @@ usage: mcp-doctor <source-tree-path> [--mode=static|dynamic|both] [--backend=<co
|
|
|
56
57
|
fails (default 0)
|
|
57
58
|
--backend=DIR the backend source (a convex/ dir) whose door list S-28 reads;
|
|
58
59
|
default: the nearest convex/ above the tree
|
|
60
|
+
--url URL judge a REMOTE streamable-HTTP server the way a customer reaches it (implies
|
|
61
|
+
dynamic; no launch target; https, or http on loopback only). Only the rules that
|
|
62
|
+
judge what a running server serves run; source-tree rules are not run
|
|
63
|
+
--bearer-env VAR send the token held in environment variable VAR as 'Authorization: Bearer'
|
|
64
|
+
(the token never appears on a command line or in output)
|
|
65
|
+
--header "Name: value" an extra request header (repeatable); values are never printed
|
|
66
|
+
--source DIR with --url: the server's source tree, for D8 eval counts and the C-25 expected
|
|
67
|
+
commit (git rev-parse HEAD there)
|
|
68
|
+
--expected-commit SHA with --url: the full commit id the server must serve (C-25)
|
|
59
69
|
--json print the report as JSON (results, owedHumanVerdicts, exitCode)
|
|
60
70
|
--version print the version and exit
|
|
61
71
|
--help print this and exit
|
package/dist/doctor.d.ts
CHANGED
|
@@ -199,6 +199,14 @@ interface RuntimeContext {
|
|
|
199
199
|
* second argument — the decided `runDynamic(runtime)` signature stays single.
|
|
200
200
|
*/
|
|
201
201
|
root: string;
|
|
202
|
+
/**
|
|
203
|
+
* True when the server was reached over a URL (`--url`): `root` is then the DISPLAYED endpoint, not a
|
|
204
|
+
* path, and no detector may treat it as a directory. The source tree of the same server, when the
|
|
205
|
+
* caller supplied one, is `sourceRoot`; a detector that reads a static co-artifact reads it through
|
|
206
|
+
* `runtimeSourceRoot` and says so (could-not-judge) when there is none.
|
|
207
|
+
*/
|
|
208
|
+
remote?: boolean;
|
|
209
|
+
sourceRoot?: string;
|
|
202
210
|
tools: RuntimeTool[];
|
|
203
211
|
launchError?: string;
|
|
204
212
|
/**
|
|
@@ -329,11 +337,48 @@ interface LiveDetector {
|
|
|
329
337
|
*/
|
|
330
338
|
declare function isLiveDetector(d: Detector | LiveDetector): d is LiveDetector;
|
|
331
339
|
|
|
340
|
+
/** A remote streamable-HTTP MCP server judged the way a customer reaches it (`--url`). */
|
|
341
|
+
interface HttpEndpoint {
|
|
342
|
+
/** The MCP endpoint. https, or http on a loopback host only (a credential never travels in clear). */
|
|
343
|
+
url: string;
|
|
344
|
+
/** Request headers (credentials included). Values are NEVER printed; see `redactSecrets`. */
|
|
345
|
+
headers: Record<string, string>;
|
|
346
|
+
/**
|
|
347
|
+
* Optional source tree of the same server. A remote URL carries no `evals/` and no git history:
|
|
348
|
+
* with a tree, D8 reads its eval counts and C-25 derives the expected commit from `git rev-parse HEAD`;
|
|
349
|
+
* without one, D8 and C-25 say so (could-not-judge) instead of judging an absent file as zero coverage.
|
|
350
|
+
*/
|
|
351
|
+
source?: string;
|
|
352
|
+
/** The full 40-hex commit the server is expected to serve; wins over one derived from `source`. */
|
|
353
|
+
expectedCommit?: string;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Every secret value an `HttpEndpoint` carries: header values (and the token of an `Authorization:
|
|
357
|
+
* Bearer|Basic|Token <token>` value), the URL's userinfo, and every URL query value. Used to scrub
|
|
358
|
+
* anything printed. Values shorter than 6 characters are not scrubbed (replacing a 1-character value
|
|
359
|
+
* would garble every report); they are not credentials worth the name.
|
|
360
|
+
*/
|
|
361
|
+
declare function endpointSecrets(ep: HttpEndpoint): string[];
|
|
362
|
+
/** Replace every secret in `text` with `[redacted]`. Longest first, so a token inside a header value goes whole. */
|
|
363
|
+
declare function redactSecrets(text: string, secrets: string[]): string;
|
|
364
|
+
/**
|
|
365
|
+
* Introspect a remote streamable-HTTP MCP server (`--url`): the same probes, the same judges, over
|
|
366
|
+
* the transport a customer uses. NEVER throws; a transport failure (unreachable, TLS, 401/403,
|
|
367
|
+
* redirect, a non-MCP response) is an in-band `launchError` naming the cause, never a pass.
|
|
368
|
+
*/
|
|
369
|
+
declare function introspectEndpoint(ep: HttpEndpoint): RuntimeContext;
|
|
370
|
+
|
|
332
371
|
type RunMode = "static" | "dynamic" | "both";
|
|
333
372
|
interface RunDoctorOptions {
|
|
334
373
|
mode?: RunMode;
|
|
335
374
|
/** The backend source root (`convex/`) a detector reads the backend's door list from (S-28). */
|
|
336
375
|
backend?: string;
|
|
376
|
+
/**
|
|
377
|
+
* A remote streamable-HTTP server to judge instead of a launched one (`--url`). Only the rules that
|
|
378
|
+
* judge what a RUNNING server serves can run (the source-tree rules have no tree to read): the run
|
|
379
|
+
* is dynamic by construction, and `target` is ignored.
|
|
380
|
+
*/
|
|
381
|
+
endpoint?: HttpEndpoint;
|
|
337
382
|
}
|
|
338
383
|
/**
|
|
339
384
|
* Run every detector against the target.
|
|
@@ -419,5 +464,5 @@ declare function renderJson(surface: string, results: DetectorResult[], skipped:
|
|
|
419
464
|
*/
|
|
420
465
|
declare function computeExitCode(results: DetectorResult[]): number;
|
|
421
466
|
|
|
422
|
-
export { SubjectUnreadableError, computeExitCode, countOwedHumanVerdicts, isLiveDetector, renderJson, renderOwedVerdicts, renderSkipped, renderTable, runDoctor, runDoctorAsync, runDoctorReport };
|
|
423
|
-
export type { LiveDetector, RunDoctorOptions, RunMode, Session };
|
|
467
|
+
export { SubjectUnreadableError, computeExitCode, countOwedHumanVerdicts, endpointSecrets, introspectEndpoint, isLiveDetector, redactSecrets, renderJson, renderOwedVerdicts, renderSkipped, renderTable, runDoctor, runDoctorAsync, runDoctorReport };
|
|
468
|
+
export type { HttpEndpoint, LiveDetector, RunDoctorOptions, RunMode, Session };
|
package/dist/doctor.js
CHANGED
|
@@ -7733,6 +7733,11 @@ var c18StructureManifest = guardUnreadablePackageJson(
|
|
|
7733
7733
|
{ authoritative: false }
|
|
7734
7734
|
);
|
|
7735
7735
|
|
|
7736
|
+
// src/runtime/sourceRoot.ts
|
|
7737
|
+
function runtimeSourceRoot(runtime) {
|
|
7738
|
+
return runtime.remote ? runtime.sourceRoot : runtime.root;
|
|
7739
|
+
}
|
|
7740
|
+
|
|
7736
7741
|
// src/detectors/c19-served-descriptions.ts
|
|
7737
7742
|
var PIN6 = STANDARD_PIN;
|
|
7738
7743
|
var TOOL_DESC_INLINE_RE = /\b(?:s\.tool|\.tool|registerTool)\s*\(\s*(?:["'`][^"'`]+["'`]|[A-Za-z_$][\w$]*)\s*,\s*["'`]([^"'`]+)["'`]/;
|
|
@@ -7888,7 +7893,8 @@ var c19ServedDescriptions = {
|
|
|
7888
7893
|
verdict: "server serves no tools over tools/list; served-descriptions check n/a (C-19)"
|
|
7889
7894
|
};
|
|
7890
7895
|
}
|
|
7891
|
-
const
|
|
7896
|
+
const sourceRoot = runtimeSourceRoot(runtime);
|
|
7897
|
+
const ceiling = sourceRoot ? findCeiling(loadTree(sourceRoot)) : void 0;
|
|
7892
7898
|
for (const t of runtime.tools) {
|
|
7893
7899
|
if (!t.description) {
|
|
7894
7900
|
return {
|
|
@@ -7926,6 +7932,16 @@ var c19ServedDescriptions = {
|
|
|
7926
7932
|
};
|
|
7927
7933
|
}
|
|
7928
7934
|
}
|
|
7935
|
+
if (!sourceRoot) {
|
|
7936
|
+
const reason = `the ${runtime.tools.length} served description(s) are bilingual and carry their trigger phrase, but the declared per-tool ceiling lives in the source tree and none was given (--source DIR) \u2014 the budget half of C-19 is unmeasured, so the rule is not judged present`;
|
|
7937
|
+
return {
|
|
7938
|
+
id: this.id,
|
|
7939
|
+
anchor: runtime.root,
|
|
7940
|
+
state: "could-not-judge",
|
|
7941
|
+
reason,
|
|
7942
|
+
verdict: `could not judge: ${reason}`
|
|
7943
|
+
};
|
|
7944
|
+
}
|
|
7929
7945
|
return {
|
|
7930
7946
|
id: this.id,
|
|
7931
7947
|
anchor: runtime.tools[0].name,
|
|
@@ -8071,7 +8087,18 @@ var c21ProgressiveDisclosure = {
|
|
|
8071
8087
|
verdict: `could not judge: ${reason}`
|
|
8072
8088
|
};
|
|
8073
8089
|
}
|
|
8074
|
-
const
|
|
8090
|
+
const sourceRoot = runtimeSourceRoot(runtime);
|
|
8091
|
+
if (!sourceRoot) {
|
|
8092
|
+
const reason = "the C-13 context ceiling is declared in the server's source tree and none was given (--source DIR) \u2014 C-21 has nothing to measure the served payload against";
|
|
8093
|
+
return {
|
|
8094
|
+
id: this.id,
|
|
8095
|
+
anchor: runtime.root,
|
|
8096
|
+
state: "could-not-judge",
|
|
8097
|
+
reason,
|
|
8098
|
+
verdict: `could not judge: ${reason}`
|
|
8099
|
+
};
|
|
8100
|
+
}
|
|
8101
|
+
const ceiling = findCeiling(loadTree(sourceRoot));
|
|
8075
8102
|
if (!ceiling) {
|
|
8076
8103
|
const reason = "no (global, perTool) context ceiling declared anywhere in the tree (C-13) \u2014 C-21 has nothing to measure against";
|
|
8077
8104
|
return {
|
|
@@ -11649,9 +11676,10 @@ var d16 = {
|
|
|
11649
11676
|
verdict: "[dynamic] the running server serves NO version on the pre-auth initialize handshake -> expose a version sourced from package.json (Server Rule 16)"
|
|
11650
11677
|
};
|
|
11651
11678
|
}
|
|
11652
|
-
const
|
|
11679
|
+
const sourceRoot = runtimeSourceRoot(runtime);
|
|
11680
|
+
const pkgVersion = sourceRoot ? readPackageVersion(sourceRoot) : null;
|
|
11653
11681
|
if (!pkgVersion) {
|
|
11654
|
-
const reason = `[dynamic] the server serves version "${served}" but its package.json version could not be read to compare against \u2014 canonical version unestablished (Server Rule 16)`;
|
|
11682
|
+
const reason = `[dynamic] the server serves version "${served}" but its package.json version could not be read to compare against \u2014 canonical version unestablished${sourceRoot ? "" : " (no source tree was given: --source DIR)"} (Server Rule 16)`;
|
|
11655
11683
|
return {
|
|
11656
11684
|
id: this.id,
|
|
11657
11685
|
anchor,
|
|
@@ -20779,12 +20807,6 @@ import { spawn } from "node:child_process";
|
|
|
20779
20807
|
const plan = JSON.parse(process.env.MCP_DOCTOR_PLAN);
|
|
20780
20808
|
const INVALID_CURSOR = "mcp-doctor:invalid-cursor:%%%";
|
|
20781
20809
|
const done = (o) => { process.stdout.write(JSON.stringify(o)); process.exit(0); };
|
|
20782
|
-
let child;
|
|
20783
|
-
try {
|
|
20784
|
-
child = spawn(plan.command, plan.args, { cwd: plan.cwd, stdio: ["pipe", "pipe", "pipe"] });
|
|
20785
|
-
} catch (e) {
|
|
20786
|
-
done({ launchError: "spawn failed: " + (e && e.message ? e.message : String(e)) });
|
|
20787
|
-
}
|
|
20788
20810
|
let settled = false;
|
|
20789
20811
|
let serverInfo;
|
|
20790
20812
|
let capabilities = {};
|
|
@@ -20793,90 +20815,203 @@ const probes = [];
|
|
|
20793
20815
|
const pending = new Map();
|
|
20794
20816
|
let nextId = 10;
|
|
20795
20817
|
let probeTimer;
|
|
20796
|
-
|
|
20818
|
+
let transport;
|
|
20819
|
+
const fail = (msg) => { if (settled) return; settled = true; Promise.resolve(transport && transport.close()).finally(() => done({ launchError: msg })); };
|
|
20797
20820
|
const finish = (why) => {
|
|
20798
20821
|
if (settled) return; settled = true; clearTimeout(to); clearTimeout(probeTimer);
|
|
20799
20822
|
for (const idx of pending.values()) probes[idx].outcome = { kind: "no-answer", reason: why };
|
|
20800
|
-
|
|
20801
|
-
done({ tools, serverInfo, cursorProbes: probes });
|
|
20823
|
+
Promise.resolve(transport && transport.close()).finally(() => done({ tools, serverInfo, cursorProbes: probes }));
|
|
20802
20824
|
};
|
|
20803
20825
|
const to = setTimeout(() => {
|
|
20804
20826
|
if (tools) finish("no answer before the introspection deadline");
|
|
20805
20827
|
else fail("timeout: server did not answer initialize+tools/list within the deadline");
|
|
20806
20828
|
}, 12000);
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
20810
|
-
|
|
20811
|
-
|
|
20812
|
-
|
|
20829
|
+
// A transport failure with a NAMED cause: before tools/list answered it is a launch failure; after,
|
|
20830
|
+
// the pending probes are recorded as no-answer naming it. Never a silent pass.
|
|
20831
|
+
const onFailure = (cause) => { if (tools) finish(cause); else fail(cause); };
|
|
20832
|
+
// The transport is the ONLY thing that differs between a local launch and a remote URL. It delivers
|
|
20833
|
+
// every JSON-RPC message the server sends to onMessage; the probe sequence below is ONE code path.
|
|
20834
|
+
// stdio: newline-delimited JSON-RPC on the child's stdin/stdout. http: streamable HTTP (a POST per
|
|
20835
|
+
// message; the answer is a JSON body or an SSE stream), failures named through onFailure.
|
|
20836
|
+
const makeStdioTransport = () => {
|
|
20837
|
+
let child;
|
|
20838
|
+
try {
|
|
20839
|
+
child = spawn(plan.command, plan.args, { cwd: plan.cwd, stdio: ["pipe", "pipe", "pipe"] });
|
|
20840
|
+
} catch (e) {
|
|
20841
|
+
done({ launchError: "spawn failed: " + (e && e.message ? e.message : String(e)) });
|
|
20842
|
+
}
|
|
20843
|
+
child.on("error", (e) => fail("spawn error: " + (e && e.message ? e.message : String(e))));
|
|
20844
|
+
child.on("exit", (code) => {
|
|
20845
|
+
if (tools) finish("the server exited (code " + code + ") before answering");
|
|
20846
|
+
else fail("server exited (code " + code + ") before completing the MCP handshake");
|
|
20847
|
+
});
|
|
20848
|
+
const send = (o) => { try { child.stdin.write(JSON.stringify(o) + "\n"); } catch (e) { fail("write failed: " + e.message); } };
|
|
20849
|
+
let buf = "";
|
|
20850
|
+
child.stdout.on("data", (d) => {
|
|
20851
|
+
buf += d.toString();
|
|
20852
|
+
let i;
|
|
20853
|
+
while ((i = buf.indexOf("\n")) >= 0) {
|
|
20854
|
+
const line = buf.slice(0, i); buf = buf.slice(i + 1);
|
|
20855
|
+
if (!line.trim()) continue;
|
|
20856
|
+
// (a) Not a filesystem read: an in-memory parse of one stdout line. A non-JSON line is legitimately not a JSON-RPC answer (a server may log to stdout); the answers it never gave surface as no-answer outcomes / the 5 s probe deadline, never as a silent pass.
|
|
20857
|
+
let msg; try { msg = JSON.parse(line); } catch { continue; }
|
|
20858
|
+
onMessage(msg);
|
|
20859
|
+
}
|
|
20860
|
+
});
|
|
20861
|
+
return { send, close: () => { try { child.kill(); } catch {} } };
|
|
20862
|
+
};
|
|
20863
|
+
const makeHttpTransport = () => {
|
|
20864
|
+
let sessionId;
|
|
20865
|
+
let protocolVersion;
|
|
20866
|
+
const ctl = new AbortController();
|
|
20867
|
+
const TLS = /CERT|TLS|SSL|EPROTO|SELF_SIGNED|UNABLE_TO_VERIFY|HOSTNAME_MISMATCH/i;
|
|
20868
|
+
const classify = (e) => {
|
|
20869
|
+
const c = e && e.cause ? e.cause : e;
|
|
20870
|
+
const code = c && c.code ? String(c.code) : "";
|
|
20871
|
+
const msg = c && c.message ? String(c.message) : String(e);
|
|
20872
|
+
if (TLS.test(code) || TLS.test(msg)) return "TLS error (" + (code || msg) + ")";
|
|
20873
|
+
return "unreachable: " + (code ? code + " " : "") + msg;
|
|
20874
|
+
};
|
|
20875
|
+
const nonMcp = (what) => onFailure("non-MCP response: " + what);
|
|
20876
|
+
// A JSON-RPC message is an object carrying jsonrpc "2.0"; anything else is not an MCP answer.
|
|
20877
|
+
const isRpc = (m) => Boolean(m) && typeof m === "object" && !Array.isArray(m) && m.jsonrpc === "2.0";
|
|
20878
|
+
const deliver = (m) => {
|
|
20879
|
+
if (m.id === 1 && m.result && typeof m.result.protocolVersion === "string") protocolVersion = m.result.protocolVersion;
|
|
20880
|
+
onMessage(m);
|
|
20881
|
+
};
|
|
20882
|
+
const readSse = async (res, wantId) => {
|
|
20883
|
+
const reader = res.body.getReader();
|
|
20884
|
+
const dec = new TextDecoder();
|
|
20885
|
+
let buf = "";
|
|
20886
|
+
let answered = false;
|
|
20887
|
+
for (;;) {
|
|
20888
|
+
const { value, done: end } = await reader.read();
|
|
20889
|
+
if (value) buf += dec.decode(value, { stream: true });
|
|
20890
|
+
if (end) buf += "\n\n";
|
|
20891
|
+
let i;
|
|
20892
|
+
while ((i = buf.search(/\r?\n\r?\n/)) >= 0) {
|
|
20893
|
+
const ev = buf.slice(0, i); buf = buf.slice(i).replace(/^\r?\n\r?\n/, "");
|
|
20894
|
+
const data = ev.split(/\r?\n/).filter((l) => l.startsWith("data:")).map((l) => l.slice(5).replace(/^ /, "")).join("\n");
|
|
20895
|
+
if (!data) continue;
|
|
20896
|
+
let m; try { m = JSON.parse(data); } catch { nonMcp("an SSE event whose data is not JSON"); try { await reader.cancel(); } catch {} return; }
|
|
20897
|
+
if (!isRpc(m)) { nonMcp("an SSE event that is not a JSON-RPC message"); try { await reader.cancel(); } catch {} return; }
|
|
20898
|
+
deliver(m);
|
|
20899
|
+
if (m.id === wantId) answered = true;
|
|
20900
|
+
}
|
|
20901
|
+
if (answered) { try { await reader.cancel(); } catch {} return; }
|
|
20902
|
+
if (end) break;
|
|
20903
|
+
}
|
|
20904
|
+
onFailure("the SSE stream ended without answering request " + wantId);
|
|
20905
|
+
};
|
|
20906
|
+
const send = (o) => {
|
|
20907
|
+
const headers = Object.assign({}, plan.headers, { "content-type": "application/json", accept: "application/json, text/event-stream" });
|
|
20908
|
+
if (sessionId) headers["mcp-session-id"] = sessionId;
|
|
20909
|
+
if (protocolVersion) headers["mcp-protocol-version"] = protocolVersion;
|
|
20910
|
+
(async () => {
|
|
20911
|
+
let res;
|
|
20912
|
+
try {
|
|
20913
|
+
res = await fetch(plan.url, { method: "POST", headers, body: JSON.stringify(o), signal: ctl.signal, redirect: "manual" });
|
|
20914
|
+
} catch (e) { onFailure(classify(e)); return; }
|
|
20915
|
+
try {
|
|
20916
|
+
const st = res.status;
|
|
20917
|
+
const sid = res.headers.get("mcp-session-id");
|
|
20918
|
+
if (sid && !sessionId) sessionId = sid;
|
|
20919
|
+
if (st === 401 || st === 403) { onFailure("authentication refused: HTTP " + st + " (the server did not accept the credential supplied)"); return; }
|
|
20920
|
+
if (st >= 300 && st < 400) { onFailure("redirect not followed: HTTP " + st + " (a credential is never sent to a redirect target)"); return; }
|
|
20921
|
+
const ct = (res.headers.get("content-type") || "").toLowerCase();
|
|
20922
|
+
if (o.id === undefined) {
|
|
20923
|
+
if (st >= 200 && st < 300) { try { await res.body.cancel(); } catch {} return; }
|
|
20924
|
+
onFailure("HTTP " + st + " answering " + o.method); return;
|
|
20925
|
+
}
|
|
20926
|
+
if (ct.includes("text/event-stream") && st >= 200 && st < 300) { await readSse(res, o.id); return; }
|
|
20927
|
+
const text = await res.text();
|
|
20928
|
+
let list = [];
|
|
20929
|
+
if (ct.includes("json")) {
|
|
20930
|
+
try { const p = JSON.parse(text); list = Array.isArray(p) ? p : [p]; } catch { list = []; }
|
|
20931
|
+
}
|
|
20932
|
+
if (list.length > 0 && list.every(isRpc)) { for (const m of list) deliver(m); return; }
|
|
20933
|
+
if (st < 200 || st >= 300) { onFailure("HTTP " + st + " answering " + o.method); return; }
|
|
20934
|
+
nonMcp(ct ? "content-type " + ct.split(";")[0] + " that is not a JSON-RPC answer" : "no content-type and no JSON-RPC answer");
|
|
20935
|
+
} catch (e) { onFailure(classify(e)); }
|
|
20936
|
+
})();
|
|
20937
|
+
};
|
|
20938
|
+
const close = async () => {
|
|
20939
|
+
ctl.abort();
|
|
20940
|
+
if (!sessionId) return;
|
|
20941
|
+
try {
|
|
20942
|
+
const headers = Object.assign({}, plan.headers, { "mcp-session-id": sessionId });
|
|
20943
|
+
if (protocolVersion) headers["mcp-protocol-version"] = protocolVersion;
|
|
20944
|
+
await fetch(plan.url, { method: "DELETE", headers, redirect: "manual", signal: AbortSignal.timeout(1500) });
|
|
20945
|
+
} catch {}
|
|
20946
|
+
};
|
|
20947
|
+
return { send, close };
|
|
20948
|
+
};
|
|
20949
|
+
const send = (o) => transport.send(o);
|
|
20813
20950
|
const probe = (target, surface, method, params) => {
|
|
20814
20951
|
const id = nextId++;
|
|
20815
20952
|
pending.set(id, probes.length);
|
|
20816
20953
|
probes.push({ target, surface });
|
|
20817
20954
|
send({ jsonrpc: "2.0", id, method, params });
|
|
20818
20955
|
};
|
|
20819
|
-
|
|
20820
|
-
|
|
20821
|
-
|
|
20822
|
-
|
|
20823
|
-
|
|
20824
|
-
|
|
20825
|
-
|
|
20826
|
-
|
|
20827
|
-
|
|
20828
|
-
|
|
20829
|
-
|
|
20830
|
-
|
|
20831
|
-
|
|
20832
|
-
|
|
20833
|
-
|
|
20834
|
-
|
|
20835
|
-
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
|
|
20843
|
-
const
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
20850
|
-
|
|
20851
|
-
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
|
|
20855
|
-
|
|
20856
|
-
|
|
20857
|
-
|
|
20858
|
-
probes.push({ target: name, surface: "tool-argument", outcome: { kind: "not-sent", reason: "the tool requires " + required.join(", ") + " beside the cursor; the probe never invents a value for them" } });
|
|
20859
|
-
continue;
|
|
20860
|
-
}
|
|
20861
|
-
probe(name, "tool-argument", "tools/call", { name, arguments: { cursor: INVALID_CURSOR } });
|
|
20862
|
-
}
|
|
20863
|
-
if (pending.size === 0) { finish("no probe pending"); return; }
|
|
20864
|
-
probeTimer = setTimeout(() => finish("no answer within the 5 s probe deadline"), 5000);
|
|
20865
|
-
} else if (pending.has(msg.id)) {
|
|
20866
|
-
const idx = pending.get(msg.id); pending.delete(msg.id);
|
|
20867
|
-
if (msg.error && typeof msg.error === "object") {
|
|
20868
|
-
probes[idx].outcome = { kind: "error", code: msg.error.code, message: typeof msg.error.message === "string" ? msg.error.message : undefined };
|
|
20869
|
-
} else if (msg.result && typeof msg.result === "object") {
|
|
20870
|
-
const sc = msg.result.structuredContent;
|
|
20871
|
-
const err = sc && typeof sc === "object" ? sc.error : undefined;
|
|
20872
|
-
probes[idx].outcome = { kind: "result", isError: msg.result.isError === true, errorCode: err && typeof err === "object" ? err.code : undefined };
|
|
20873
|
-
} else {
|
|
20874
|
-
probes[idx].outcome = { kind: "no-answer", reason: "an answer with neither result nor error" };
|
|
20956
|
+
const onMessage = (msg) => {
|
|
20957
|
+
// A request or notification FROM the server carries a method: it is not an answer.
|
|
20958
|
+
if (msg.method !== undefined) return;
|
|
20959
|
+
// An initialize or tools/list that the server ANSWERED WITH AN ERROR is a refusal, named: it is never read
|
|
20960
|
+
// as an empty tool list (which would judge "no tools" over a server that refused to say).
|
|
20961
|
+
if ((msg.id === 1 || msg.id === 2) && msg.error && typeof msg.error === "object") {
|
|
20962
|
+
fail((msg.id === 1 ? "initialize" : "tools/list") + " refused by the server: JSON-RPC error " + msg.error.code + (typeof msg.error.message === "string" ? " " + msg.error.message : ""));
|
|
20963
|
+
return;
|
|
20964
|
+
}
|
|
20965
|
+
if (msg.id === 1) {
|
|
20966
|
+
// The initialize response's serverInfo is the SAME non-authenticated
|
|
20967
|
+
// discovery surface a client reads version from (S-7); captured here
|
|
20968
|
+
// so C-25's dynamic half can read a served build-identity field
|
|
20969
|
+
// alongside it, additively -- every existing consumer of the
|
|
20970
|
+
// tools-only introspector output is unaffected.
|
|
20971
|
+
serverInfo = msg.result && msg.result.serverInfo;
|
|
20972
|
+
capabilities = (msg.result && msg.result.capabilities) || {};
|
|
20973
|
+
send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
20974
|
+
send({ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} });
|
|
20975
|
+
} else if (msg.id === 2) {
|
|
20976
|
+
if (settled) return;
|
|
20977
|
+
const served = msg.result && Array.isArray(msg.result.tools) ? msg.result.tools : [];
|
|
20978
|
+
const schemaOf = (t) => (t && t.inputSchema && typeof t.inputSchema === "object" ? t.inputSchema : {});
|
|
20979
|
+
const takesCursor = (t) => {
|
|
20980
|
+
const props = schemaOf(t).properties;
|
|
20981
|
+
return Boolean(props && typeof props === "object" && Object.prototype.hasOwnProperty.call(props, "cursor"));
|
|
20982
|
+
};
|
|
20983
|
+
tools = served.map((t) => ({ name: String(t && t.name), description: t && typeof t.description === "string" ? t.description : undefined, cursorArgument: takesCursor(t) }));
|
|
20984
|
+
const lists = ["tools/list"];
|
|
20985
|
+
if (capabilities.resources) lists.push("resources/list", "resources/templates/list");
|
|
20986
|
+
if (capabilities.prompts) lists.push("prompts/list");
|
|
20987
|
+
for (const m of lists) probe(m, "list-method", m, { cursor: INVALID_CURSOR });
|
|
20988
|
+
for (const t of served) {
|
|
20989
|
+
if (!takesCursor(t)) continue;
|
|
20990
|
+
const name = String(t && t.name);
|
|
20991
|
+
const required = Array.isArray(schemaOf(t).required) ? schemaOf(t).required.filter((r) => r !== "cursor") : [];
|
|
20992
|
+
if (required.length > 0) {
|
|
20993
|
+
probes.push({ target: name, surface: "tool-argument", outcome: { kind: "not-sent", reason: "the tool requires " + required.join(", ") + " beside the cursor; the probe never invents a value for them" } });
|
|
20994
|
+
continue;
|
|
20875
20995
|
}
|
|
20876
|
-
|
|
20996
|
+
probe(name, "tool-argument", "tools/call", { name, arguments: { cursor: INVALID_CURSOR } });
|
|
20997
|
+
}
|
|
20998
|
+
if (pending.size === 0) { finish("no probe pending"); return; }
|
|
20999
|
+
probeTimer = setTimeout(() => finish("no answer within the 5 s probe deadline"), 5000);
|
|
21000
|
+
} else if (pending.has(msg.id)) {
|
|
21001
|
+
const idx = pending.get(msg.id); pending.delete(msg.id);
|
|
21002
|
+
if (msg.error && typeof msg.error === "object") {
|
|
21003
|
+
probes[idx].outcome = { kind: "error", code: msg.error.code, message: typeof msg.error.message === "string" ? msg.error.message : undefined };
|
|
21004
|
+
} else if (msg.result && typeof msg.result === "object") {
|
|
21005
|
+
const sc = msg.result.structuredContent;
|
|
21006
|
+
const err = sc && typeof sc === "object" ? sc.error : undefined;
|
|
21007
|
+
probes[idx].outcome = { kind: "result", isError: msg.result.isError === true, errorCode: err && typeof err === "object" ? err.code : undefined };
|
|
21008
|
+
} else {
|
|
21009
|
+
probes[idx].outcome = { kind: "no-answer", reason: "an answer with neither result nor error" };
|
|
20877
21010
|
}
|
|
21011
|
+
if (pending.size === 0) finish("no probe pending");
|
|
20878
21012
|
}
|
|
20879
|
-
}
|
|
21013
|
+
};
|
|
21014
|
+
transport = plan.kind === "http" ? makeHttpTransport() : makeStdioTransport();
|
|
20880
21015
|
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "mcp-doctor", version: "0" } } });
|
|
20881
21016
|
`;
|
|
20882
21017
|
function readEvalCounts(target) {
|
|
@@ -20984,31 +21119,62 @@ function readCursorProbe(raw) {
|
|
|
20984
21119
|
return unreadable(`outcome kind ${JSON.stringify(o.kind)}`);
|
|
20985
21120
|
}
|
|
20986
21121
|
}
|
|
20987
|
-
function
|
|
20988
|
-
const
|
|
20989
|
-
|
|
20990
|
-
|
|
21122
|
+
function endpointSecrets(ep) {
|
|
21123
|
+
const out = /* @__PURE__ */ new Set();
|
|
21124
|
+
const add = (v) => {
|
|
21125
|
+
if (v && v.length >= 6) out.add(v);
|
|
21126
|
+
};
|
|
21127
|
+
for (const v of Object.values(ep.headers)) {
|
|
21128
|
+
add(v);
|
|
21129
|
+
const m = /^\s*\S+\s+(\S.*)$/.exec(v);
|
|
21130
|
+
if (m) add(m[1]);
|
|
21131
|
+
}
|
|
21132
|
+
try {
|
|
21133
|
+
const u = new URL(ep.url);
|
|
21134
|
+
add(decodeURIComponent(u.username));
|
|
21135
|
+
add(decodeURIComponent(u.password));
|
|
21136
|
+
for (const [, v] of u.searchParams) add(v);
|
|
21137
|
+
} catch {
|
|
21138
|
+
}
|
|
21139
|
+
return [...out].sort((a, b) => b.length - a.length);
|
|
21140
|
+
}
|
|
21141
|
+
function redactSecrets(text, secrets) {
|
|
21142
|
+
let out = text;
|
|
21143
|
+
for (const s of secrets) out = out.split(s).join("[redacted]");
|
|
21144
|
+
return out;
|
|
21145
|
+
}
|
|
21146
|
+
function displayUrl(url) {
|
|
21147
|
+
try {
|
|
21148
|
+
const u = new URL(url);
|
|
21149
|
+
return `${u.protocol}//${u.host}${u.pathname}`;
|
|
21150
|
+
} catch {
|
|
21151
|
+
return "<unparsable url>";
|
|
20991
21152
|
}
|
|
21153
|
+
}
|
|
21154
|
+
function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets) {
|
|
20992
21155
|
const proc = spawnSync2(process.execPath, ["--input-type=module", "-e", INTROSPECTOR], {
|
|
20993
21156
|
env: { ...process.env, MCP_DOCTOR_PLAN: JSON.stringify(plan) },
|
|
20994
21157
|
encoding: "utf8",
|
|
20995
21158
|
timeout: 2e4,
|
|
20996
21159
|
maxBuffer: 8 * 1024 * 1024
|
|
20997
21160
|
});
|
|
21161
|
+
const scrub = (t) => redactSecrets(t, secrets);
|
|
20998
21162
|
if (proc.error) {
|
|
20999
21163
|
return {
|
|
21000
|
-
root
|
|
21164
|
+
root,
|
|
21001
21165
|
tools: [],
|
|
21002
|
-
launchError: `introspector failed to run: ${proc.error.message}`
|
|
21166
|
+
launchError: scrub(`introspector failed to run: ${proc.error.message}`)
|
|
21003
21167
|
};
|
|
21004
21168
|
}
|
|
21005
21169
|
const out = (proc.stdout ?? "").trim();
|
|
21006
21170
|
if (!out) {
|
|
21007
21171
|
const stderr = (proc.stderr ?? "").trim();
|
|
21008
21172
|
return {
|
|
21009
|
-
root
|
|
21173
|
+
root,
|
|
21010
21174
|
tools: [],
|
|
21011
|
-
launchError:
|
|
21175
|
+
launchError: scrub(
|
|
21176
|
+
`introspector produced no result${stderr ? ` (stderr: ${stderr.slice(0, 300)})` : ""}`
|
|
21177
|
+
)
|
|
21012
21178
|
};
|
|
21013
21179
|
}
|
|
21014
21180
|
let parsed;
|
|
@@ -21016,25 +21182,25 @@ function launchAndIntrospect(target) {
|
|
|
21016
21182
|
parsed = JSON.parse(out);
|
|
21017
21183
|
} catch {
|
|
21018
21184
|
return {
|
|
21019
|
-
root
|
|
21185
|
+
root,
|
|
21020
21186
|
tools: [],
|
|
21021
|
-
launchError: `introspector emitted non-JSON output: ${out.slice(0, 300)}`
|
|
21187
|
+
launchError: scrub(`introspector emitted non-JSON output: ${out.slice(0, 300)}`)
|
|
21022
21188
|
};
|
|
21023
21189
|
}
|
|
21024
21190
|
if (parsed.launchError) {
|
|
21025
|
-
return { root
|
|
21191
|
+
return { root, tools: [], launchError: scrub(parsed.launchError) };
|
|
21026
21192
|
}
|
|
21027
|
-
const { counts:
|
|
21193
|
+
const evals = evalSource ? readEvalCounts(evalSource) : { counts: /* @__PURE__ */ new Map() };
|
|
21194
|
+
const evalsUnreadable = evalsNote ?? evals.unreadable;
|
|
21028
21195
|
const tools = (parsed.tools ?? []).map((t) => {
|
|
21029
21196
|
const name = t.name;
|
|
21030
|
-
const count =
|
|
21197
|
+
const count = evals.counts.get(name);
|
|
21031
21198
|
const base = t.description ? { name, description: t.description } : { name };
|
|
21032
21199
|
const withCursor = t.cursorArgument === true ? { ...base, cursorArgument: true } : base;
|
|
21033
21200
|
return count === void 0 ? withCursor : { ...withCursor, evalCaseCount: count };
|
|
21034
21201
|
});
|
|
21035
|
-
const expectedCommit = deriveExpectedCommit(plan.cwd);
|
|
21036
21202
|
return {
|
|
21037
|
-
root
|
|
21203
|
+
root,
|
|
21038
21204
|
tools,
|
|
21039
21205
|
...parsed.serverInfo ? { serverInfo: parsed.serverInfo } : {},
|
|
21040
21206
|
...expectedCommit ? { expectedCommit } : {},
|
|
@@ -21042,12 +21208,158 @@ function launchAndIntrospect(target) {
|
|
|
21042
21208
|
...Array.isArray(parsed.cursorProbes) ? { cursorProbes: parsed.cursorProbes.map(readCursorProbe) } : {}
|
|
21043
21209
|
};
|
|
21044
21210
|
}
|
|
21211
|
+
function launchAndIntrospect(target) {
|
|
21212
|
+
const plan = deriveLaunchPlan(target);
|
|
21213
|
+
if ("error" in plan) {
|
|
21214
|
+
return { root: target, tools: [], launchError: plan.error };
|
|
21215
|
+
}
|
|
21216
|
+
return introspect(
|
|
21217
|
+
{ kind: "stdio", ...plan },
|
|
21218
|
+
target,
|
|
21219
|
+
target,
|
|
21220
|
+
deriveExpectedCommit(plan.cwd),
|
|
21221
|
+
void 0,
|
|
21222
|
+
[]
|
|
21223
|
+
);
|
|
21224
|
+
}
|
|
21225
|
+
function introspectEndpoint(ep) {
|
|
21226
|
+
const expected = ep.expectedCommit ?? (ep.source ? deriveExpectedCommit(ep.source) : void 0);
|
|
21227
|
+
const rt = introspect(
|
|
21228
|
+
{ kind: "http", url: ep.url, headers: ep.headers },
|
|
21229
|
+
displayUrl(ep.url),
|
|
21230
|
+
ep.source,
|
|
21231
|
+
expected,
|
|
21232
|
+
ep.source ? void 0 : "no --source tree was given: the server's evals/evals.json is not reachable over HTTP, so per-tool eval coverage is unknown, never zero",
|
|
21233
|
+
endpointSecrets(ep)
|
|
21234
|
+
);
|
|
21235
|
+
return { ...rt, remote: true, ...ep.source ? { sourceRoot: ep.source } : {} };
|
|
21236
|
+
}
|
|
21045
21237
|
|
|
21046
21238
|
// src/types.ts
|
|
21047
21239
|
function isLiveDetector(d) {
|
|
21048
21240
|
return typeof d.runLive === "function";
|
|
21049
21241
|
}
|
|
21050
21242
|
|
|
21243
|
+
// src/urlArgs.ts
|
|
21244
|
+
import { statSync as statSync21 } from "fs";
|
|
21245
|
+
var VALUE_OPTIONS = [
|
|
21246
|
+
"--url",
|
|
21247
|
+
"--header",
|
|
21248
|
+
"--bearer-env",
|
|
21249
|
+
"--source",
|
|
21250
|
+
"--expected-commit"
|
|
21251
|
+
];
|
|
21252
|
+
var MANAGED_HEADERS = /* @__PURE__ */ new Set([
|
|
21253
|
+
"content-type",
|
|
21254
|
+
"accept",
|
|
21255
|
+
"mcp-session-id",
|
|
21256
|
+
"mcp-protocol-version"
|
|
21257
|
+
]);
|
|
21258
|
+
var LOOPBACK2 = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
21259
|
+
function parseUrlArgs(args, env) {
|
|
21260
|
+
const values = {
|
|
21261
|
+
"--url": [],
|
|
21262
|
+
"--header": [],
|
|
21263
|
+
"--bearer-env": [],
|
|
21264
|
+
"--source": [],
|
|
21265
|
+
"--expected-commit": []
|
|
21266
|
+
};
|
|
21267
|
+
const remaining = [];
|
|
21268
|
+
for (let i = 0; i < args.length; i++) {
|
|
21269
|
+
const a = args[i];
|
|
21270
|
+
const opt = VALUE_OPTIONS.find((o) => a === o || a.startsWith(`${o}=`));
|
|
21271
|
+
if (!opt) {
|
|
21272
|
+
remaining.push(a);
|
|
21273
|
+
continue;
|
|
21274
|
+
}
|
|
21275
|
+
if (a.startsWith(`${opt}=`)) {
|
|
21276
|
+
values[opt].push(a.slice(opt.length + 1));
|
|
21277
|
+
} else {
|
|
21278
|
+
const next = args[i + 1];
|
|
21279
|
+
if (next === void 0) return { kind: "error", message: `${opt} needs a value` };
|
|
21280
|
+
values[opt].push(next);
|
|
21281
|
+
i++;
|
|
21282
|
+
}
|
|
21283
|
+
}
|
|
21284
|
+
const used = VALUE_OPTIONS.filter((o) => values[o].length > 0);
|
|
21285
|
+
if (values["--url"].length === 0) {
|
|
21286
|
+
if (used.length === 0) return { kind: "none", remaining };
|
|
21287
|
+
return { kind: "error", message: `${used[0]} is only meaningful with --url <https url>` };
|
|
21288
|
+
}
|
|
21289
|
+
if (values["--url"].length > 1) return { kind: "error", message: "--url may be given once" };
|
|
21290
|
+
const raw = values["--url"][0];
|
|
21291
|
+
let url;
|
|
21292
|
+
try {
|
|
21293
|
+
url = new URL(raw);
|
|
21294
|
+
} catch {
|
|
21295
|
+
return { kind: "error", message: "--url is not a valid URL" };
|
|
21296
|
+
}
|
|
21297
|
+
const loopback = LOOPBACK2.has(url.hostname);
|
|
21298
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
|
|
21299
|
+
return {
|
|
21300
|
+
kind: "error",
|
|
21301
|
+
message: "--url must be an https URL (cleartext http is accepted for a loopback host only: a credential never travels in clear)"
|
|
21302
|
+
};
|
|
21303
|
+
}
|
|
21304
|
+
url.hash = "";
|
|
21305
|
+
const headers = {};
|
|
21306
|
+
const setHeader = (name, value) => {
|
|
21307
|
+
const key = name.toLowerCase();
|
|
21308
|
+
if (MANAGED_HEADERS.has(key)) {
|
|
21309
|
+
return `header "${name}" is set by the doctor itself and cannot be supplied`;
|
|
21310
|
+
}
|
|
21311
|
+
if (key in headers) return `header "${name}" is given twice`;
|
|
21312
|
+
headers[key] = value;
|
|
21313
|
+
return null;
|
|
21314
|
+
};
|
|
21315
|
+
for (const h of values["--header"]) {
|
|
21316
|
+
const m = /^([A-Za-z0-9!#$%&'*+.^_`|~-]+)\s*:\s*(.*)$/.exec(h);
|
|
21317
|
+
if (!m) return { kind: "error", message: '--header must be "Name: value"' };
|
|
21318
|
+
const err = setHeader(m[1], m[2]);
|
|
21319
|
+
if (err) return { kind: "error", message: `--header: ${err}` };
|
|
21320
|
+
}
|
|
21321
|
+
if (values["--bearer-env"].length > 1) {
|
|
21322
|
+
return { kind: "error", message: "--bearer-env may be given once" };
|
|
21323
|
+
}
|
|
21324
|
+
if (values["--bearer-env"].length === 1) {
|
|
21325
|
+
const name = values["--bearer-env"][0];
|
|
21326
|
+
const token = env[name];
|
|
21327
|
+
if (token === void 0 || token === "") {
|
|
21328
|
+
return {
|
|
21329
|
+
kind: "error",
|
|
21330
|
+
message: `--bearer-env ${name}: that environment variable is unset or empty`
|
|
21331
|
+
};
|
|
21332
|
+
}
|
|
21333
|
+
const err = setHeader("Authorization", `Bearer ${token}`);
|
|
21334
|
+
if (err) return { kind: "error", message: `--bearer-env: ${err}` };
|
|
21335
|
+
}
|
|
21336
|
+
const endpoint = { url: url.toString(), headers };
|
|
21337
|
+
if (values["--source"].length > 1)
|
|
21338
|
+
return { kind: "error", message: "--source may be given once" };
|
|
21339
|
+
if (values["--source"].length === 1) {
|
|
21340
|
+
const src = values["--source"][0];
|
|
21341
|
+
let isDir2 = false;
|
|
21342
|
+
try {
|
|
21343
|
+
isDir2 = statSync21(src).isDirectory();
|
|
21344
|
+
} catch {
|
|
21345
|
+
isDir2 = false;
|
|
21346
|
+
}
|
|
21347
|
+
if (!isDir2) return { kind: "error", message: `--source ${src}: not a readable directory` };
|
|
21348
|
+
endpoint.source = src;
|
|
21349
|
+
}
|
|
21350
|
+
if (values["--expected-commit"].length > 1) {
|
|
21351
|
+
return { kind: "error", message: "--expected-commit may be given once" };
|
|
21352
|
+
}
|
|
21353
|
+
if (values["--expected-commit"].length === 1) {
|
|
21354
|
+
const sha = values["--expected-commit"][0].trim().toLowerCase();
|
|
21355
|
+
if (!/^[0-9a-f]{40}$/.test(sha)) {
|
|
21356
|
+
return { kind: "error", message: "--expected-commit must be a full 40-hex commit id" };
|
|
21357
|
+
}
|
|
21358
|
+
endpoint.expectedCommit = sha;
|
|
21359
|
+
}
|
|
21360
|
+
return { kind: "endpoint", endpoint, remaining };
|
|
21361
|
+
}
|
|
21362
|
+
|
|
21051
21363
|
// src/doctor.ts
|
|
21052
21364
|
function pad(s, w) {
|
|
21053
21365
|
return s.length >= w ? s : s + " ".repeat(w - s.length);
|
|
@@ -21113,6 +21425,17 @@ function runDoctor(target, detectorList = detectors, opts = {}) {
|
|
|
21113
21425
|
return runDoctorReport(target, detectorList, opts).results;
|
|
21114
21426
|
}
|
|
21115
21427
|
function runDoctorReport(target, detectorList = detectors, opts = {}) {
|
|
21428
|
+
if (opts.endpoint) {
|
|
21429
|
+
const rt = introspectEndpoint(opts.endpoint);
|
|
21430
|
+
const results2 = detectorList.filter((d) => typeof d.runDynamic === "function").map(
|
|
21431
|
+
(d) => invokeChecked(
|
|
21432
|
+
d.id,
|
|
21433
|
+
"dynamic",
|
|
21434
|
+
() => d.runDynamic(rt)
|
|
21435
|
+
)
|
|
21436
|
+
);
|
|
21437
|
+
return { results: results2, skipped: [] };
|
|
21438
|
+
}
|
|
21116
21439
|
const mode = opts.mode ?? "static";
|
|
21117
21440
|
const tree = loadTree(target, opts.backend);
|
|
21118
21441
|
const needsRuntime = mode !== "static" && detectorList.some((d) => typeof d.runDynamic === "function");
|
|
@@ -21278,6 +21601,7 @@ function computeExitCode(results) {
|
|
|
21278
21601
|
}
|
|
21279
21602
|
var USAGE = [
|
|
21280
21603
|
"usage: mcp-doctor <source-tree-path> [--mode=static|dynamic|both] [--backend=<convex-dir>] [--json]",
|
|
21604
|
+
' mcp-doctor --url <https url> [--bearer-env VAR] [--header "Name: value"]... [--source DIR] [--expected-commit SHA] [--json]',
|
|
21281
21605
|
"",
|
|
21282
21606
|
" --mode=static read the tree only (default)",
|
|
21283
21607
|
" --mode=dynamic launch the server and judge what it serves",
|
|
@@ -21287,6 +21611,15 @@ var USAGE = [
|
|
|
21287
21611
|
" fails (default 0)",
|
|
21288
21612
|
" --backend=DIR the backend source (a convex/ dir) whose door list S-28 reads;",
|
|
21289
21613
|
" default: the nearest convex/ above the tree",
|
|
21614
|
+
" --url URL judge a REMOTE streamable-HTTP server the way a customer reaches it (implies",
|
|
21615
|
+
" dynamic; no launch target; https, or http on loopback only). Only the rules that",
|
|
21616
|
+
" judge what a running server serves run; source-tree rules are not run",
|
|
21617
|
+
" --bearer-env VAR send the token held in environment variable VAR as 'Authorization: Bearer'",
|
|
21618
|
+
" (the token never appears on a command line or in output)",
|
|
21619
|
+
' --header "Name: value" an extra request header (repeatable); values are never printed',
|
|
21620
|
+
" --source DIR with --url: the server's source tree, for D8 eval counts and the C-25 expected",
|
|
21621
|
+
" commit (git rev-parse HEAD there)",
|
|
21622
|
+
" --expected-commit SHA with --url: the full commit id the server must serve (C-25)",
|
|
21290
21623
|
" --json print the report as JSON (results, owedHumanVerdicts, exitCode)",
|
|
21291
21624
|
" --version print the version and exit",
|
|
21292
21625
|
" --help print this and exit",
|
|
@@ -21303,6 +21636,32 @@ function readVersion() {
|
|
|
21303
21636
|
return null;
|
|
21304
21637
|
}
|
|
21305
21638
|
}
|
|
21639
|
+
function runUrlMode(endpoint, rest) {
|
|
21640
|
+
const target = rest.find((a) => !a.startsWith("--"));
|
|
21641
|
+
if (target) {
|
|
21642
|
+
console.error(
|
|
21643
|
+
"mcp-doctor: --url is incompatible with a launch target (the server is already running: nothing is launched or read from a path). Use --source DIR to give its source tree for the eval counts and the expected commit."
|
|
21644
|
+
);
|
|
21645
|
+
process.exit(1);
|
|
21646
|
+
}
|
|
21647
|
+
const modeArg = rest.find((a) => a.startsWith("--mode="));
|
|
21648
|
+
if (modeArg && modeArg !== "--mode=dynamic") {
|
|
21649
|
+
console.error(
|
|
21650
|
+
`mcp-doctor: --url implies --mode=dynamic; ${modeArg} contradicts it (a remote server has no source tree to scan statically).`
|
|
21651
|
+
);
|
|
21652
|
+
process.exit(1);
|
|
21653
|
+
}
|
|
21654
|
+
const secrets = endpointSecrets(endpoint);
|
|
21655
|
+
const surface = displayUrl(endpoint.url);
|
|
21656
|
+
const { results, skipped } = runDoctorReport(surface, detectors, { endpoint });
|
|
21657
|
+
const out = rest.includes("--json") ? renderJson(surface, results, skipped) : renderTable(surface, results, skipped);
|
|
21658
|
+
console.log(redactSecrets(out, secrets));
|
|
21659
|
+
const notRun = detectors.filter((d) => typeof d.runDynamic !== "function").length;
|
|
21660
|
+
console.error(
|
|
21661
|
+
`mcp-doctor: --url judged the ${results.length} rules that read what a running server serves; ${notRun} source-tree rules were NOT run (no tree over HTTP) \u2014 this report says nothing about them.`
|
|
21662
|
+
);
|
|
21663
|
+
process.exitCode = computeExitCode(results);
|
|
21664
|
+
}
|
|
21306
21665
|
function main() {
|
|
21307
21666
|
const args = process.argv.slice(2);
|
|
21308
21667
|
if (args.includes("--version") || args.includes("-V")) {
|
|
@@ -21318,6 +21677,15 @@ function main() {
|
|
|
21318
21677
|
console.log(USAGE);
|
|
21319
21678
|
return;
|
|
21320
21679
|
}
|
|
21680
|
+
const urlArgs = parseUrlArgs(args, process.env);
|
|
21681
|
+
if (urlArgs.kind === "error") {
|
|
21682
|
+
console.error(`mcp-doctor: ${urlArgs.message}`);
|
|
21683
|
+
process.exit(1);
|
|
21684
|
+
}
|
|
21685
|
+
if (urlArgs.kind === "endpoint") {
|
|
21686
|
+
runUrlMode(urlArgs.endpoint, urlArgs.remaining);
|
|
21687
|
+
return;
|
|
21688
|
+
}
|
|
21321
21689
|
const modeArg = args.find((a) => a.startsWith("--mode="));
|
|
21322
21690
|
const backendArg = args.find((a) => a.startsWith("--backend="));
|
|
21323
21691
|
const target = args.find((a) => !a.startsWith("--"));
|
|
@@ -21390,7 +21758,10 @@ export {
|
|
|
21390
21758
|
SubjectUnreadableError,
|
|
21391
21759
|
computeExitCode,
|
|
21392
21760
|
countOwedHumanVerdicts,
|
|
21761
|
+
endpointSecrets,
|
|
21762
|
+
introspectEndpoint,
|
|
21393
21763
|
isLiveDetector,
|
|
21764
|
+
redactSecrets,
|
|
21394
21765
|
renderJson,
|
|
21395
21766
|
renderOwedVerdicts,
|
|
21396
21767
|
renderSkipped,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vantageos/mcp-doctor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Static MCP conformance checker: audits an MCP server source tree against the MCP 2026-07-28 standard and emits a conformance-diff table (file:line | present | absent | non-conforming | verdict).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/doctor.js",
|