@vantageos/mcp-doctor 0.9.0 → 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 +63 -0
- package/README.md +10 -0
- package/dist/doctor.d.ts +47 -2
- package/dist/doctor.js +769 -95
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,69 @@
|
|
|
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
|
+
|
|
39
|
+
## 0.9.1 — 2026-10-28
|
|
40
|
+
|
|
41
|
+
Two could-not-judge classes of S-36..S-41 that were false, found by running 0.9.0 on
|
|
42
|
+
`@vantageos/mcp-boilerplate` 0.4.0 (main `d34e9f05`). Both vocabularies are derived, and each keeps a
|
|
43
|
+
fail-closed remainder.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
- **A Node core `createServer` is not an outbound call.** `createServer` of `node:http`, `node:https` and
|
|
47
|
+
`node:http2` builds an inbound server; it makes no request, yet S-36..S-41 named it as "an outbound HTTP call
|
|
48
|
+
through a form the scan does not follow". What a call through a Node core networking binding does is now read
|
|
49
|
+
from the module's export: `src/detectors/nodeCoreExports.ts` classifies every export of `http`, `https`,
|
|
50
|
+
`http2`, `net`, `tls` and `dgram` as `outbound` or `not-a-request`. A test derives the export list from the
|
|
51
|
+
running Node (`Object.keys(require("node:<module>"))`) and fails, naming each, when one is unclassified. An
|
|
52
|
+
unclassified member, `request`, `get`, `connect` and every ambiguous one (`Socket`, `WebSocket`,
|
|
53
|
+
`ClientRequest`) stay named.
|
|
54
|
+
- **A forwarding rebind of a registration method is transparent.** `const register = server.registerTool.bind(server);
|
|
55
|
+
server.registerTool = (name, config, cb) => register(name, config, cb)` (the boilerplate's `trackToolRecords`)
|
|
56
|
+
no longer makes every S-36..S-41 could-not-judge "by a route the scan does not read". It is transparent only
|
|
57
|
+
when all of this is proven: one `.bind(server)` original, one assignment of a function literal, that function
|
|
58
|
+
forwards exactly its own parameters, in order, to the original, the original is referenced nowhere else
|
|
59
|
+
in the file, and the tree registers tools by direct calls the scan reads. A `typeof server.registerTool`
|
|
60
|
+
type query is no route. Anything else (a wrapper that does not forward, that alters an argument, whose original
|
|
61
|
+
escapes, the method passed or returned as a value, a computed member) stays named, with the reason it is not
|
|
62
|
+
proven.
|
|
63
|
+
Forwarding the parameters' NAMES is not enough: the wrapper must also leave every parameter untouched. A
|
|
64
|
+
parameter that is re-assigned or re-declared (`callback = ...`, `name += ...`, a destructuring target), mutated
|
|
65
|
+
(`config.x = ...`, `delete config.x`, `Object.assign(config, ...)`), passed to any other call, stored, or
|
|
66
|
+
indexed, or a body that reads `arguments`, keeps the route named, with the touching statement. A member read
|
|
67
|
+
that only copies or tests (`{ ...config.annotations }`, `if (config.annotations)`) is kept.
|
|
68
|
+
|
|
6
69
|
## 0.9.0 — 2026-10-25
|
|
7
70
|
|
|
8
71
|
Standard re-pinned to ElPi-Corp `015053b7268125cf441d7555fecfe41f318a06ed` (mcp-standard v2.7, ElPi-Corp
|
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
|
@@ -4723,6 +4723,110 @@ var c9VerbDeclared = {
|
|
|
4723
4723
|
}
|
|
4724
4724
|
};
|
|
4725
4725
|
|
|
4726
|
+
// src/detectors/nodeCoreExports.ts
|
|
4727
|
+
var TABLE = {
|
|
4728
|
+
http: {
|
|
4729
|
+
outbound: ["get", "request", "ClientRequest", "WebSocket"],
|
|
4730
|
+
notRequest: [
|
|
4731
|
+
"_connectionListener",
|
|
4732
|
+
"METHODS",
|
|
4733
|
+
"STATUS_CODES",
|
|
4734
|
+
"Agent",
|
|
4735
|
+
"IncomingMessage",
|
|
4736
|
+
"OutgoingMessage",
|
|
4737
|
+
"Server",
|
|
4738
|
+
"ServerResponse",
|
|
4739
|
+
"createServer",
|
|
4740
|
+
"isValidHeaderName",
|
|
4741
|
+
"isValidHeaderValue",
|
|
4742
|
+
"validateHeaderName",
|
|
4743
|
+
"validateHeaderValue",
|
|
4744
|
+
"setMaxIdleHTTPParsers",
|
|
4745
|
+
"setGlobalProxyFromEnv",
|
|
4746
|
+
"websocketMask",
|
|
4747
|
+
"websocketUnmask",
|
|
4748
|
+
"maxHeaderSize",
|
|
4749
|
+
"globalAgent",
|
|
4750
|
+
"CloseEvent",
|
|
4751
|
+
"MessageEvent"
|
|
4752
|
+
]
|
|
4753
|
+
},
|
|
4754
|
+
https: {
|
|
4755
|
+
outbound: ["get", "request"],
|
|
4756
|
+
notRequest: ["Agent", "globalAgent", "Server", "createServer"]
|
|
4757
|
+
},
|
|
4758
|
+
http2: {
|
|
4759
|
+
outbound: ["connect"],
|
|
4760
|
+
notRequest: [
|
|
4761
|
+
"constants",
|
|
4762
|
+
"createServer",
|
|
4763
|
+
"createSecureServer",
|
|
4764
|
+
"getDefaultSettings",
|
|
4765
|
+
"getPackedSettings",
|
|
4766
|
+
"getUnpackedSettings",
|
|
4767
|
+
"performServerHandshake",
|
|
4768
|
+
"sensitiveHeaders",
|
|
4769
|
+
"Http2ServerRequest",
|
|
4770
|
+
"Http2ServerResponse"
|
|
4771
|
+
]
|
|
4772
|
+
},
|
|
4773
|
+
net: {
|
|
4774
|
+
outbound: [
|
|
4775
|
+
"connect",
|
|
4776
|
+
"createConnection",
|
|
4777
|
+
"Socket",
|
|
4778
|
+
"Stream",
|
|
4779
|
+
"_TransferredBoundSocket",
|
|
4780
|
+
"BoundSocket"
|
|
4781
|
+
],
|
|
4782
|
+
notRequest: [
|
|
4783
|
+
"_createServerHandle",
|
|
4784
|
+
"_normalizeArgs",
|
|
4785
|
+
"BlockList",
|
|
4786
|
+
"SocketAddress",
|
|
4787
|
+
"createServer",
|
|
4788
|
+
"isIP",
|
|
4789
|
+
"isIPv4",
|
|
4790
|
+
"isIPv6",
|
|
4791
|
+
"Server",
|
|
4792
|
+
"getDefaultAutoSelectFamily",
|
|
4793
|
+
"setDefaultAutoSelectFamily",
|
|
4794
|
+
"getDefaultAutoSelectFamilyAttemptTimeout",
|
|
4795
|
+
"setDefaultAutoSelectFamilyAttemptTimeout"
|
|
4796
|
+
]
|
|
4797
|
+
},
|
|
4798
|
+
tls: {
|
|
4799
|
+
outbound: ["connect", "TLSSocket"],
|
|
4800
|
+
notRequest: [
|
|
4801
|
+
"CLIENT_RENEG_LIMIT",
|
|
4802
|
+
"CLIENT_RENEG_WINDOW",
|
|
4803
|
+
"DEFAULT_CIPHERS",
|
|
4804
|
+
"DEFAULT_ECDH_CURVE",
|
|
4805
|
+
"DEFAULT_MIN_VERSION",
|
|
4806
|
+
"DEFAULT_MAX_VERSION",
|
|
4807
|
+
"getCiphers",
|
|
4808
|
+
"getCertificateCompressionAlgorithms",
|
|
4809
|
+
"rootCertificates",
|
|
4810
|
+
"getCACertificates",
|
|
4811
|
+
"setDefaultCACertificates",
|
|
4812
|
+
"convertALPNProtocols",
|
|
4813
|
+
"checkServerIdentity",
|
|
4814
|
+
"createSecureContext",
|
|
4815
|
+
"SecureContext",
|
|
4816
|
+
"Server",
|
|
4817
|
+
"createServer"
|
|
4818
|
+
]
|
|
4819
|
+
},
|
|
4820
|
+
dgram: { outbound: ["createSocket", "Socket"], notRequest: [] }
|
|
4821
|
+
};
|
|
4822
|
+
function classifyNodeExport(module, exportName) {
|
|
4823
|
+
const t = TABLE[module.replace(/^node:/, "")];
|
|
4824
|
+
if (!t) return void 0;
|
|
4825
|
+
if (t.outbound.includes(exportName)) return "outbound";
|
|
4826
|
+
if (t.notRequest.includes(exportName)) return "not-a-request";
|
|
4827
|
+
return void 0;
|
|
4828
|
+
}
|
|
4829
|
+
|
|
4726
4830
|
// src/detectors/upstreamKit.ts
|
|
4727
4831
|
var cache = /* @__PURE__ */ new WeakMap();
|
|
4728
4832
|
function srcs(tree) {
|
|
@@ -5041,7 +5145,20 @@ function unresolvedOutbound(tree) {
|
|
|
5041
5145
|
if (via && !bindings.has(h[1])) bindings.set(h[1], `\`${h[1]}\` (an instance of ${via})`);
|
|
5042
5146
|
}
|
|
5043
5147
|
}
|
|
5148
|
+
const core = /* @__PURE__ */ new Map();
|
|
5149
|
+
for (const b of importBindings(s)) {
|
|
5150
|
+
if (/^node:(?:https?|http2)$|^(?:https?|http2)$/.test(b.module))
|
|
5151
|
+
core.set(b.local, { module: b.module, imported: b.imported });
|
|
5152
|
+
}
|
|
5044
5153
|
for (const c of byFile.get(s) ?? []) {
|
|
5154
|
+
const parts = c.callee.split(".");
|
|
5155
|
+
const cb = core.get(parts[0]);
|
|
5156
|
+
if (cb !== void 0) {
|
|
5157
|
+
const member = cb.imported === "default" || cb.imported === "*" ? parts[1] : cb.imported;
|
|
5158
|
+
const direct = cb.imported === "default" || cb.imported === "*" ? parts.length === 2 : parts.length === 1;
|
|
5159
|
+
if (direct && member !== void 0 && classifyNodeExport(cb.module, member) === "not-a-request")
|
|
5160
|
+
continue;
|
|
5161
|
+
}
|
|
5045
5162
|
if (GLOBAL_FETCH.test(c.callee)) {
|
|
5046
5163
|
add(c, "the global fetch read off its holder");
|
|
5047
5164
|
continue;
|
|
@@ -5055,6 +5172,177 @@ function unresolvedOutbound(tree) {
|
|
|
5055
5172
|
}
|
|
5056
5173
|
return out;
|
|
5057
5174
|
}
|
|
5175
|
+
function splitList(m, from, to) {
|
|
5176
|
+
const out = [];
|
|
5177
|
+
let depth = 0;
|
|
5178
|
+
let start = from;
|
|
5179
|
+
for (let i = from; i < to; i++) {
|
|
5180
|
+
const ch = m[i];
|
|
5181
|
+
if (ch === "=" && m[i + 1] === ">") i++;
|
|
5182
|
+
else if ("([{<".includes(ch)) depth++;
|
|
5183
|
+
else if (")]}>".includes(ch)) depth--;
|
|
5184
|
+
else if (ch === "," && depth === 0) {
|
|
5185
|
+
out.push(m.slice(start, i).trim());
|
|
5186
|
+
start = i + 1;
|
|
5187
|
+
}
|
|
5188
|
+
}
|
|
5189
|
+
if (m.slice(start, to).trim() !== "") out.push(m.slice(start, to).trim());
|
|
5190
|
+
return out;
|
|
5191
|
+
}
|
|
5192
|
+
function wrapperProof(s, server, mine) {
|
|
5193
|
+
if (mine.some((h) => h.computed)) return "a computed member access";
|
|
5194
|
+
const m = s.shape;
|
|
5195
|
+
let alias;
|
|
5196
|
+
let nBind = 0;
|
|
5197
|
+
let assign;
|
|
5198
|
+
let nAssign = 0;
|
|
5199
|
+
for (const h of mine) {
|
|
5200
|
+
const after = m.slice(h.at + h.len);
|
|
5201
|
+
const before = m.slice(0, h.at);
|
|
5202
|
+
const bind = new RegExp(String.raw`^\s*\.\s*bind\s*\(\s*${esc(server)}\s*\)`).exec(after);
|
|
5203
|
+
const decl = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=;]+)?=\s*$/.exec(before);
|
|
5204
|
+
if (bind && decl) {
|
|
5205
|
+
nBind++;
|
|
5206
|
+
alias = decl[1];
|
|
5207
|
+
} else if (/^\s*=(?![=>])/.test(after)) {
|
|
5208
|
+
nAssign++;
|
|
5209
|
+
assign = h;
|
|
5210
|
+
} else
|
|
5211
|
+
return "the method is read in a form other than its rebind (passed, stored or returned as a value)";
|
|
5212
|
+
}
|
|
5213
|
+
if (nBind !== 1 || alias === void 0)
|
|
5214
|
+
return "no single `const X = server.M.bind(server)` original";
|
|
5215
|
+
if (nAssign !== 1 || assign === void 0)
|
|
5216
|
+
return "no single assignment `server.M = <function>` of the rebind";
|
|
5217
|
+
const rhsAt = assign.at + assign.len + (/^\s*=/.exec(m.slice(assign.at + assign.len))?.[0].length ?? 0);
|
|
5218
|
+
const head = /^[\s(]*(?:async\s+)?(?:function\b\s*[\w$]*\s*)?\(/.exec(m.slice(rhsAt));
|
|
5219
|
+
if (!head) return "the assigned value is not a function literal";
|
|
5220
|
+
const pOpen = rhsAt + head[0].length - 1;
|
|
5221
|
+
const pClose = matchClose(m, pOpen);
|
|
5222
|
+
if (pClose < 0) return "the parameter list is unbalanced";
|
|
5223
|
+
const params = splitList(m, pOpen + 1, pClose);
|
|
5224
|
+
const names = [];
|
|
5225
|
+
for (const p of params) {
|
|
5226
|
+
const id = /^(\.\.\.)?\s*([A-Za-z_$][\w$]*)/.exec(p);
|
|
5227
|
+
if (!id) return "a destructured parameter";
|
|
5228
|
+
if (/=>/.test(p)) return "a function type in the parameter list";
|
|
5229
|
+
names.push(`${id[1] ?? ""}${id[2]}`);
|
|
5230
|
+
}
|
|
5231
|
+
const tail = m.slice(pClose + 1);
|
|
5232
|
+
const arrow = /^\s*(?::[^=>{]*)?=>\s*/.exec(tail);
|
|
5233
|
+
const fnBody = arrow ? void 0 : /^\s*(?::[^{]*)?\{/.exec(tail);
|
|
5234
|
+
let bStart;
|
|
5235
|
+
let bEnd;
|
|
5236
|
+
if (arrow) {
|
|
5237
|
+
bStart = pClose + 1 + arrow[0].length;
|
|
5238
|
+
if (m[bStart] === "{") {
|
|
5239
|
+
bEnd = matchClose(m, bStart);
|
|
5240
|
+
} else {
|
|
5241
|
+
bEnd = bStart;
|
|
5242
|
+
let d = 0;
|
|
5243
|
+
while (bEnd < m.length) {
|
|
5244
|
+
const ch = m[bEnd];
|
|
5245
|
+
if ("([{".includes(ch)) d++;
|
|
5246
|
+
else if (")]}".includes(ch)) {
|
|
5247
|
+
if (d === 0) break;
|
|
5248
|
+
d--;
|
|
5249
|
+
} else if (d === 0 && (ch === ";" || ch === "\n")) break;
|
|
5250
|
+
bEnd++;
|
|
5251
|
+
}
|
|
5252
|
+
}
|
|
5253
|
+
} else if (fnBody) {
|
|
5254
|
+
bStart = pClose + 1 + fnBody[0].length - 1;
|
|
5255
|
+
bEnd = matchClose(m, bStart);
|
|
5256
|
+
} else return "the function literal has no readable body";
|
|
5257
|
+
if (bEnd < 0) return "the function body is unbalanced";
|
|
5258
|
+
const idRe = new RegExp(String.raw`(?<![\w$.])${esc(alias)}(?![\w$])`, "g");
|
|
5259
|
+
const all = [...m.matchAll(idRe)].map((x) => x.index ?? 0);
|
|
5260
|
+
const inBody = all.filter((i) => i > bStart && i < bEnd);
|
|
5261
|
+
if (inBody.length !== 1 || all.length !== 2)
|
|
5262
|
+
return `the original \`${alias}\` is referenced ${all.length - 1} time(s) after its binding (once, in the wrapper, is the proof)`;
|
|
5263
|
+
const at = inBody[0];
|
|
5264
|
+
let argsOpen = -1;
|
|
5265
|
+
if (/^\s*\(/.test(m.slice(at + alias.length, at + alias.length + 4))) {
|
|
5266
|
+
argsOpen = at + alias.length + m.slice(at + alias.length).indexOf("(");
|
|
5267
|
+
} else {
|
|
5268
|
+
const o = m.lastIndexOf("(", at);
|
|
5269
|
+
if (o >= 0 && m.slice(o + 1, at).trim() === "") {
|
|
5270
|
+
const c = matchClose(m, o);
|
|
5271
|
+
if (c > 0 && /^\s+as\b/.test(m.slice(at + alias.length, c))) {
|
|
5272
|
+
const nx = /^\s*\(/.exec(m.slice(c + 1));
|
|
5273
|
+
if (nx) argsOpen = c + nx[0].length;
|
|
5274
|
+
}
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
if (argsOpen < 0) return `the original \`${alias}\` is not called in the wrapper`;
|
|
5278
|
+
const argsClose = matchClose(m, argsOpen);
|
|
5279
|
+
if (argsClose < 0) return "the forwarding call is unbalanced";
|
|
5280
|
+
const args = splitList(m, argsOpen + 1, argsClose);
|
|
5281
|
+
if (args.length !== names.length || args.some((a, i) => a !== names[i]))
|
|
5282
|
+
return `the wrapper does not forward exactly its own parameters (${names.join(", ")}) to \`${alias}\``;
|
|
5283
|
+
return untouchedParams(s, params, names, bStart, bEnd, argsOpen, argsClose);
|
|
5284
|
+
}
|
|
5285
|
+
var PRIMITIVE_TYPE = /^(?:(?:string|number|boolean|bigint|symbol|null|undefined|"[^"]*"|'[^']*'|\d+)\s*\|?\s*)+$/;
|
|
5286
|
+
function enclosingOpens(m, at, lo) {
|
|
5287
|
+
const out = [];
|
|
5288
|
+
let depth = 0;
|
|
5289
|
+
for (let i = at - 1; i >= lo; i--) {
|
|
5290
|
+
const ch = m[i];
|
|
5291
|
+
if (")]}".includes(ch)) depth++;
|
|
5292
|
+
else if ("([{".includes(ch)) {
|
|
5293
|
+
if (depth === 0) out.push(i);
|
|
5294
|
+
else depth--;
|
|
5295
|
+
}
|
|
5296
|
+
}
|
|
5297
|
+
return out;
|
|
5298
|
+
}
|
|
5299
|
+
function untouchedParams(s, params, names, bStart, bEnd, fwdOpen, fwdClose) {
|
|
5300
|
+
const m = s.shape;
|
|
5301
|
+
const stmt = (i) => {
|
|
5302
|
+
let a = i;
|
|
5303
|
+
while (a > bStart && !";{}\n".includes(m[a - 1])) a--;
|
|
5304
|
+
let b = i;
|
|
5305
|
+
while (b < bEnd && !";\n".includes(m[b])) b++;
|
|
5306
|
+
return `${anchorAt(s, i)} \`${m.slice(a, b).trim().replace(/\s+/g, " ").slice(0, 80)}\``;
|
|
5307
|
+
};
|
|
5308
|
+
const argsUse = /(?<![\w$.])arguments(?![\w$])/g.exec(m.slice(bStart, bEnd));
|
|
5309
|
+
if (argsUse)
|
|
5310
|
+
return `the wrapper reads \`arguments\`, which aliases its parameters: ${stmt(bStart + argsUse.index)}`;
|
|
5311
|
+
for (let k = 0; k < names.length; k++) {
|
|
5312
|
+
const id = names[k].replace(/^\.\.\./, "");
|
|
5313
|
+
const decl = params[k].replace(/^\.\.\.\s*/, "");
|
|
5314
|
+
const typed = /^[A-Za-z_$][\w$]*\s*\??\s*:\s*([^=]*?)\s*(?:=(?![=>]).*)?$/s.exec(decl);
|
|
5315
|
+
const primitive = typed !== void 0 && typed !== null && PRIMITIVE_TYPE.test(typed[1]);
|
|
5316
|
+
const re = new RegExp(String.raw`(?<![\w$.])${esc(id)}(?![\w$])`, "g");
|
|
5317
|
+
for (const o of m.slice(bStart, bEnd).matchAll(re)) {
|
|
5318
|
+
const i = bStart + (o.index ?? 0);
|
|
5319
|
+
if (i >= fwdOpen && i <= fwdClose) continue;
|
|
5320
|
+
const e = i + id.length;
|
|
5321
|
+
const before = m.slice(bStart, i);
|
|
5322
|
+
const after = m.slice(e, bEnd);
|
|
5323
|
+
const touch = `the wrapper's parameter \`${id}\` is not proven untouched before it is forwarded: ${stmt(i)}`;
|
|
5324
|
+
if (/^\s*(?:=(?![=>])|[-+*/%&|^]=|\*\*=|<<=|>>>?=|&&=|\|\|=|\?\?=|\+\+|--)/.test(after) || /(?:\+\+|--)\s*$/.test(before) || /\b(?:const|let|var|function|class)\s*$/.test(before))
|
|
5325
|
+
return touch;
|
|
5326
|
+
for (const open of enclosingOpens(m, i, bStart)) {
|
|
5327
|
+
const pre = m.slice(bStart, open).trimEnd();
|
|
5328
|
+
if (open > bStart && /[\w$)\]]$/.test(pre) && m[open] !== "{") continue;
|
|
5329
|
+
const close = matchClose(m, open);
|
|
5330
|
+
if (close > 0 && /^\s*=(?![=>])/.test(m.slice(close + 1, bEnd))) return touch;
|
|
5331
|
+
}
|
|
5332
|
+
if (primitive) continue;
|
|
5333
|
+
const chain = /^(?:\s*!?\s*\??\.\s*[A-Za-z_$][\w$]*)+/.exec(after);
|
|
5334
|
+
if (!chain) return touch;
|
|
5335
|
+
const rest = after.slice(chain[0].length);
|
|
5336
|
+
if (/^\s*(?:\(|\?\.\(|\[|\?\.\[|=(?![=>])|[-+*/%&|^]=|\*\*=|<<=|>>>?=|&&=|\|\|=|\?\?=|\+\+|--)/.test(
|
|
5337
|
+
rest
|
|
5338
|
+
))
|
|
5339
|
+
return touch;
|
|
5340
|
+
const ok = /(?:\.\.\.\s*\(*|\btypeof\s+\(*|!\s*\(*|[!=]==?\s*\(*|\b(?:if|while)\s*\(\s*)$/;
|
|
5341
|
+
if (!ok.test(before.trimEnd())) return touch;
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
return void 0;
|
|
5345
|
+
}
|
|
5058
5346
|
function toolRegistrations(tree) {
|
|
5059
5347
|
const regs = [];
|
|
5060
5348
|
const unread = [];
|
|
@@ -5110,6 +5398,7 @@ function toolRegistrations(tree) {
|
|
|
5110
5398
|
))
|
|
5111
5399
|
servers.add(h[1]);
|
|
5112
5400
|
for (const name of servers) {
|
|
5401
|
+
const hits = [];
|
|
5113
5402
|
for (const h of s.shape.matchAll(
|
|
5114
5403
|
new RegExp(
|
|
5115
5404
|
String.raw`(?<![\w$])${esc(name)}\s*(?:\.\s*(tool|registerTool|registerToolTask)\b(?!\s*(?:<[^<>()]*>)?\s*\()|\[)`,
|
|
@@ -5123,13 +5412,27 @@ function toolRegistrations(tree) {
|
|
|
5123
5412
|
const called = close >= 0 && /^\s*\(/.test(s.shape.slice(close + 1, close + 4));
|
|
5124
5413
|
if (!called && !/tool/i.test(key)) continue;
|
|
5125
5414
|
}
|
|
5126
|
-
|
|
5415
|
+
hits.push({ at, len: h[0].length, method: h[1], computed: h[0].endsWith("[") });
|
|
5416
|
+
}
|
|
5417
|
+
const live = hits.filter((h) => h.computed || !/\btypeof\s*$/.test(s.shape.slice(0, h.at)));
|
|
5418
|
+
const transparent = /* @__PURE__ */ new Set();
|
|
5419
|
+
const why = /* @__PURE__ */ new Map();
|
|
5420
|
+
for (const method of new Set(live.map((h) => h.method).filter((m) => !!m))) {
|
|
5421
|
+
const mine = live.filter((h) => h.method === method);
|
|
5422
|
+
const proof = regs.length === 0 ? "no tool is registered by a direct call anywhere in the tree" : wrapperProof(s, name, mine);
|
|
5423
|
+
if (proof === void 0) transparent.add(method);
|
|
5424
|
+
else why.set(method, proof);
|
|
5425
|
+
}
|
|
5426
|
+
for (const h of live) {
|
|
5427
|
+
if (h.method !== void 0 && transparent.has(h.method)) continue;
|
|
5428
|
+
const anchor = anchorAt(s, h.at);
|
|
5429
|
+
const reason = h.method === void 0 ? "" : why.get(h.method);
|
|
5127
5430
|
unread.push({
|
|
5128
5431
|
anchor,
|
|
5129
|
-
reason: `${anchor} \`${s.code.slice(at, at + h
|
|
5432
|
+
reason: `${anchor} \`${s.code.slice(h.at, h.at + h.len + 12).replace(/\s+/g, "").slice(
|
|
5130
5433
|
0,
|
|
5131
5434
|
40
|
|
5132
|
-
)}\` reaches a tool-registration method of \`${name}\` by a route the scan does not read (not a direct call): the tools it registers are unread`
|
|
5435
|
+
)}\` reaches a tool-registration method of \`${name}\` by a route the scan does not read (not a direct call): the tools it registers are unread${reason ? ` (a rebind of it is transparent only when it forwards every argument to the original and registrations are made by direct calls; here: ${reason})` : ""}`
|
|
5133
5436
|
});
|
|
5134
5437
|
}
|
|
5135
5438
|
}
|
|
@@ -7430,6 +7733,11 @@ var c18StructureManifest = guardUnreadablePackageJson(
|
|
|
7430
7733
|
{ authoritative: false }
|
|
7431
7734
|
);
|
|
7432
7735
|
|
|
7736
|
+
// src/runtime/sourceRoot.ts
|
|
7737
|
+
function runtimeSourceRoot(runtime) {
|
|
7738
|
+
return runtime.remote ? runtime.sourceRoot : runtime.root;
|
|
7739
|
+
}
|
|
7740
|
+
|
|
7433
7741
|
// src/detectors/c19-served-descriptions.ts
|
|
7434
7742
|
var PIN6 = STANDARD_PIN;
|
|
7435
7743
|
var TOOL_DESC_INLINE_RE = /\b(?:s\.tool|\.tool|registerTool)\s*\(\s*(?:["'`][^"'`]+["'`]|[A-Za-z_$][\w$]*)\s*,\s*["'`]([^"'`]+)["'`]/;
|
|
@@ -7585,7 +7893,8 @@ var c19ServedDescriptions = {
|
|
|
7585
7893
|
verdict: "server serves no tools over tools/list; served-descriptions check n/a (C-19)"
|
|
7586
7894
|
};
|
|
7587
7895
|
}
|
|
7588
|
-
const
|
|
7896
|
+
const sourceRoot = runtimeSourceRoot(runtime);
|
|
7897
|
+
const ceiling = sourceRoot ? findCeiling(loadTree(sourceRoot)) : void 0;
|
|
7589
7898
|
for (const t of runtime.tools) {
|
|
7590
7899
|
if (!t.description) {
|
|
7591
7900
|
return {
|
|
@@ -7623,6 +7932,16 @@ var c19ServedDescriptions = {
|
|
|
7623
7932
|
};
|
|
7624
7933
|
}
|
|
7625
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
|
+
}
|
|
7626
7945
|
return {
|
|
7627
7946
|
id: this.id,
|
|
7628
7947
|
anchor: runtime.tools[0].name,
|
|
@@ -7768,7 +8087,18 @@ var c21ProgressiveDisclosure = {
|
|
|
7768
8087
|
verdict: `could not judge: ${reason}`
|
|
7769
8088
|
};
|
|
7770
8089
|
}
|
|
7771
|
-
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));
|
|
7772
8102
|
if (!ceiling) {
|
|
7773
8103
|
const reason = "no (global, perTool) context ceiling declared anywhere in the tree (C-13) \u2014 C-21 has nothing to measure against";
|
|
7774
8104
|
return {
|
|
@@ -11346,9 +11676,10 @@ var d16 = {
|
|
|
11346
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)"
|
|
11347
11677
|
};
|
|
11348
11678
|
}
|
|
11349
|
-
const
|
|
11679
|
+
const sourceRoot = runtimeSourceRoot(runtime);
|
|
11680
|
+
const pkgVersion = sourceRoot ? readPackageVersion(sourceRoot) : null;
|
|
11350
11681
|
if (!pkgVersion) {
|
|
11351
|
-
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)`;
|
|
11352
11683
|
return {
|
|
11353
11684
|
id: this.id,
|
|
11354
11685
|
anchor,
|
|
@@ -20476,12 +20807,6 @@ import { spawn } from "node:child_process";
|
|
|
20476
20807
|
const plan = JSON.parse(process.env.MCP_DOCTOR_PLAN);
|
|
20477
20808
|
const INVALID_CURSOR = "mcp-doctor:invalid-cursor:%%%";
|
|
20478
20809
|
const done = (o) => { process.stdout.write(JSON.stringify(o)); process.exit(0); };
|
|
20479
|
-
let child;
|
|
20480
|
-
try {
|
|
20481
|
-
child = spawn(plan.command, plan.args, { cwd: plan.cwd, stdio: ["pipe", "pipe", "pipe"] });
|
|
20482
|
-
} catch (e) {
|
|
20483
|
-
done({ launchError: "spawn failed: " + (e && e.message ? e.message : String(e)) });
|
|
20484
|
-
}
|
|
20485
20810
|
let settled = false;
|
|
20486
20811
|
let serverInfo;
|
|
20487
20812
|
let capabilities = {};
|
|
@@ -20490,90 +20815,203 @@ const probes = [];
|
|
|
20490
20815
|
const pending = new Map();
|
|
20491
20816
|
let nextId = 10;
|
|
20492
20817
|
let probeTimer;
|
|
20493
|
-
|
|
20818
|
+
let transport;
|
|
20819
|
+
const fail = (msg) => { if (settled) return; settled = true; Promise.resolve(transport && transport.close()).finally(() => done({ launchError: msg })); };
|
|
20494
20820
|
const finish = (why) => {
|
|
20495
20821
|
if (settled) return; settled = true; clearTimeout(to); clearTimeout(probeTimer);
|
|
20496
20822
|
for (const idx of pending.values()) probes[idx].outcome = { kind: "no-answer", reason: why };
|
|
20497
|
-
|
|
20498
|
-
done({ tools, serverInfo, cursorProbes: probes });
|
|
20823
|
+
Promise.resolve(transport && transport.close()).finally(() => done({ tools, serverInfo, cursorProbes: probes }));
|
|
20499
20824
|
};
|
|
20500
20825
|
const to = setTimeout(() => {
|
|
20501
20826
|
if (tools) finish("no answer before the introspection deadline");
|
|
20502
20827
|
else fail("timeout: server did not answer initialize+tools/list within the deadline");
|
|
20503
20828
|
}, 12000);
|
|
20504
|
-
|
|
20505
|
-
|
|
20506
|
-
|
|
20507
|
-
|
|
20508
|
-
|
|
20509
|
-
|
|
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);
|
|
20510
20950
|
const probe = (target, surface, method, params) => {
|
|
20511
20951
|
const id = nextId++;
|
|
20512
20952
|
pending.set(id, probes.length);
|
|
20513
20953
|
probes.push({ target, surface });
|
|
20514
20954
|
send({ jsonrpc: "2.0", id, method, params });
|
|
20515
20955
|
};
|
|
20516
|
-
|
|
20517
|
-
|
|
20518
|
-
|
|
20519
|
-
|
|
20520
|
-
|
|
20521
|
-
|
|
20522
|
-
|
|
20523
|
-
|
|
20524
|
-
|
|
20525
|
-
|
|
20526
|
-
|
|
20527
|
-
|
|
20528
|
-
|
|
20529
|
-
|
|
20530
|
-
|
|
20531
|
-
|
|
20532
|
-
|
|
20533
|
-
|
|
20534
|
-
|
|
20535
|
-
|
|
20536
|
-
|
|
20537
|
-
|
|
20538
|
-
|
|
20539
|
-
|
|
20540
|
-
const
|
|
20541
|
-
|
|
20542
|
-
|
|
20543
|
-
|
|
20544
|
-
|
|
20545
|
-
|
|
20546
|
-
|
|
20547
|
-
|
|
20548
|
-
|
|
20549
|
-
|
|
20550
|
-
|
|
20551
|
-
|
|
20552
|
-
|
|
20553
|
-
|
|
20554
|
-
|
|
20555
|
-
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" } });
|
|
20556
|
-
continue;
|
|
20557
|
-
}
|
|
20558
|
-
probe(name, "tool-argument", "tools/call", { name, arguments: { cursor: INVALID_CURSOR } });
|
|
20559
|
-
}
|
|
20560
|
-
if (pending.size === 0) { finish("no probe pending"); return; }
|
|
20561
|
-
probeTimer = setTimeout(() => finish("no answer within the 5 s probe deadline"), 5000);
|
|
20562
|
-
} else if (pending.has(msg.id)) {
|
|
20563
|
-
const idx = pending.get(msg.id); pending.delete(msg.id);
|
|
20564
|
-
if (msg.error && typeof msg.error === "object") {
|
|
20565
|
-
probes[idx].outcome = { kind: "error", code: msg.error.code, message: typeof msg.error.message === "string" ? msg.error.message : undefined };
|
|
20566
|
-
} else if (msg.result && typeof msg.result === "object") {
|
|
20567
|
-
const sc = msg.result.structuredContent;
|
|
20568
|
-
const err = sc && typeof sc === "object" ? sc.error : undefined;
|
|
20569
|
-
probes[idx].outcome = { kind: "result", isError: msg.result.isError === true, errorCode: err && typeof err === "object" ? err.code : undefined };
|
|
20570
|
-
} else {
|
|
20571
|
-
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;
|
|
20572
20995
|
}
|
|
20573
|
-
|
|
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" };
|
|
20574
21010
|
}
|
|
21011
|
+
if (pending.size === 0) finish("no probe pending");
|
|
20575
21012
|
}
|
|
20576
|
-
}
|
|
21013
|
+
};
|
|
21014
|
+
transport = plan.kind === "http" ? makeHttpTransport() : makeStdioTransport();
|
|
20577
21015
|
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "mcp-doctor", version: "0" } } });
|
|
20578
21016
|
`;
|
|
20579
21017
|
function readEvalCounts(target) {
|
|
@@ -20681,31 +21119,62 @@ function readCursorProbe(raw) {
|
|
|
20681
21119
|
return unreadable(`outcome kind ${JSON.stringify(o.kind)}`);
|
|
20682
21120
|
}
|
|
20683
21121
|
}
|
|
20684
|
-
function
|
|
20685
|
-
const
|
|
20686
|
-
|
|
20687
|
-
|
|
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>";
|
|
20688
21152
|
}
|
|
21153
|
+
}
|
|
21154
|
+
function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets) {
|
|
20689
21155
|
const proc = spawnSync2(process.execPath, ["--input-type=module", "-e", INTROSPECTOR], {
|
|
20690
21156
|
env: { ...process.env, MCP_DOCTOR_PLAN: JSON.stringify(plan) },
|
|
20691
21157
|
encoding: "utf8",
|
|
20692
21158
|
timeout: 2e4,
|
|
20693
21159
|
maxBuffer: 8 * 1024 * 1024
|
|
20694
21160
|
});
|
|
21161
|
+
const scrub = (t) => redactSecrets(t, secrets);
|
|
20695
21162
|
if (proc.error) {
|
|
20696
21163
|
return {
|
|
20697
|
-
root
|
|
21164
|
+
root,
|
|
20698
21165
|
tools: [],
|
|
20699
|
-
launchError: `introspector failed to run: ${proc.error.message}`
|
|
21166
|
+
launchError: scrub(`introspector failed to run: ${proc.error.message}`)
|
|
20700
21167
|
};
|
|
20701
21168
|
}
|
|
20702
21169
|
const out = (proc.stdout ?? "").trim();
|
|
20703
21170
|
if (!out) {
|
|
20704
21171
|
const stderr = (proc.stderr ?? "").trim();
|
|
20705
21172
|
return {
|
|
20706
|
-
root
|
|
21173
|
+
root,
|
|
20707
21174
|
tools: [],
|
|
20708
|
-
launchError:
|
|
21175
|
+
launchError: scrub(
|
|
21176
|
+
`introspector produced no result${stderr ? ` (stderr: ${stderr.slice(0, 300)})` : ""}`
|
|
21177
|
+
)
|
|
20709
21178
|
};
|
|
20710
21179
|
}
|
|
20711
21180
|
let parsed;
|
|
@@ -20713,25 +21182,25 @@ function launchAndIntrospect(target) {
|
|
|
20713
21182
|
parsed = JSON.parse(out);
|
|
20714
21183
|
} catch {
|
|
20715
21184
|
return {
|
|
20716
|
-
root
|
|
21185
|
+
root,
|
|
20717
21186
|
tools: [],
|
|
20718
|
-
launchError: `introspector emitted non-JSON output: ${out.slice(0, 300)}`
|
|
21187
|
+
launchError: scrub(`introspector emitted non-JSON output: ${out.slice(0, 300)}`)
|
|
20719
21188
|
};
|
|
20720
21189
|
}
|
|
20721
21190
|
if (parsed.launchError) {
|
|
20722
|
-
return { root
|
|
21191
|
+
return { root, tools: [], launchError: scrub(parsed.launchError) };
|
|
20723
21192
|
}
|
|
20724
|
-
const { counts:
|
|
21193
|
+
const evals = evalSource ? readEvalCounts(evalSource) : { counts: /* @__PURE__ */ new Map() };
|
|
21194
|
+
const evalsUnreadable = evalsNote ?? evals.unreadable;
|
|
20725
21195
|
const tools = (parsed.tools ?? []).map((t) => {
|
|
20726
21196
|
const name = t.name;
|
|
20727
|
-
const count =
|
|
21197
|
+
const count = evals.counts.get(name);
|
|
20728
21198
|
const base = t.description ? { name, description: t.description } : { name };
|
|
20729
21199
|
const withCursor = t.cursorArgument === true ? { ...base, cursorArgument: true } : base;
|
|
20730
21200
|
return count === void 0 ? withCursor : { ...withCursor, evalCaseCount: count };
|
|
20731
21201
|
});
|
|
20732
|
-
const expectedCommit = deriveExpectedCommit(plan.cwd);
|
|
20733
21202
|
return {
|
|
20734
|
-
root
|
|
21203
|
+
root,
|
|
20735
21204
|
tools,
|
|
20736
21205
|
...parsed.serverInfo ? { serverInfo: parsed.serverInfo } : {},
|
|
20737
21206
|
...expectedCommit ? { expectedCommit } : {},
|
|
@@ -20739,12 +21208,158 @@ function launchAndIntrospect(target) {
|
|
|
20739
21208
|
...Array.isArray(parsed.cursorProbes) ? { cursorProbes: parsed.cursorProbes.map(readCursorProbe) } : {}
|
|
20740
21209
|
};
|
|
20741
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
|
+
}
|
|
20742
21237
|
|
|
20743
21238
|
// src/types.ts
|
|
20744
21239
|
function isLiveDetector(d) {
|
|
20745
21240
|
return typeof d.runLive === "function";
|
|
20746
21241
|
}
|
|
20747
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
|
+
|
|
20748
21363
|
// src/doctor.ts
|
|
20749
21364
|
function pad(s, w) {
|
|
20750
21365
|
return s.length >= w ? s : s + " ".repeat(w - s.length);
|
|
@@ -20810,6 +21425,17 @@ function runDoctor(target, detectorList = detectors, opts = {}) {
|
|
|
20810
21425
|
return runDoctorReport(target, detectorList, opts).results;
|
|
20811
21426
|
}
|
|
20812
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
|
+
}
|
|
20813
21439
|
const mode = opts.mode ?? "static";
|
|
20814
21440
|
const tree = loadTree(target, opts.backend);
|
|
20815
21441
|
const needsRuntime = mode !== "static" && detectorList.some((d) => typeof d.runDynamic === "function");
|
|
@@ -20975,6 +21601,7 @@ function computeExitCode(results) {
|
|
|
20975
21601
|
}
|
|
20976
21602
|
var USAGE = [
|
|
20977
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]',
|
|
20978
21605
|
"",
|
|
20979
21606
|
" --mode=static read the tree only (default)",
|
|
20980
21607
|
" --mode=dynamic launch the server and judge what it serves",
|
|
@@ -20984,6 +21611,15 @@ var USAGE = [
|
|
|
20984
21611
|
" fails (default 0)",
|
|
20985
21612
|
" --backend=DIR the backend source (a convex/ dir) whose door list S-28 reads;",
|
|
20986
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)",
|
|
20987
21623
|
" --json print the report as JSON (results, owedHumanVerdicts, exitCode)",
|
|
20988
21624
|
" --version print the version and exit",
|
|
20989
21625
|
" --help print this and exit",
|
|
@@ -21000,6 +21636,32 @@ function readVersion() {
|
|
|
21000
21636
|
return null;
|
|
21001
21637
|
}
|
|
21002
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
|
+
}
|
|
21003
21665
|
function main() {
|
|
21004
21666
|
const args = process.argv.slice(2);
|
|
21005
21667
|
if (args.includes("--version") || args.includes("-V")) {
|
|
@@ -21015,6 +21677,15 @@ function main() {
|
|
|
21015
21677
|
console.log(USAGE);
|
|
21016
21678
|
return;
|
|
21017
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
|
+
}
|
|
21018
21689
|
const modeArg = args.find((a) => a.startsWith("--mode="));
|
|
21019
21690
|
const backendArg = args.find((a) => a.startsWith("--backend="));
|
|
21020
21691
|
const target = args.find((a) => !a.startsWith("--"));
|
|
@@ -21087,7 +21758,10 @@ export {
|
|
|
21087
21758
|
SubjectUnreadableError,
|
|
21088
21759
|
computeExitCode,
|
|
21089
21760
|
countOwedHumanVerdicts,
|
|
21761
|
+
endpointSecrets,
|
|
21762
|
+
introspectEndpoint,
|
|
21090
21763
|
isLiveDetector,
|
|
21764
|
+
redactSecrets,
|
|
21091
21765
|
renderJson,
|
|
21092
21766
|
renderOwedVerdicts,
|
|
21093
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",
|