@vantageos/mcp-doctor 0.11.1 → 0.11.2

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 CHANGED
@@ -3,6 +3,31 @@
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.11.2 — 2026-10-29
7
+
8
+ Patch: static readers that judged natural TypeScript by an identifier's name or missed a
9
+ TypeScript wrapper. No rule and no public type changes.
10
+
11
+ ### Fixed
12
+ - **D7 judges a hand-rolled result builder by the object it writes, never by a name.** A local variable named
13
+ `ttlMs` used in a conditional (`healthy ? ttlMs : …`) read as a hand-written `ttlMs:` field and turned D7
14
+ `non-conforming`. A protocol field (`resultType`, `ttlMs`, `cacheScope`) now counts only when it is WRITTEN:
15
+ a key, quoted key or shorthand in an object value, or an assignment `o.f =` / `o["f"] =`, and, for D7, only
16
+ into a RESULT object (one carrying `resultType` or a payload key of an MCP result: `content`,
17
+ `structuredContent`, `isError`, `tools`, `resources`, `resourceTemplates`, `prompts`, `contents`, `messages`,
18
+ `completion`, `nextCursor`). A conditional branch, a type member, a parameter annotation, a binding pattern, a
19
+ member read or a cache-library option is not a builder. A write into an object whose shape is hidden behind a
20
+ spread is `could-not-judge`, naming the spread. A quoted key, a shorthand and an assignment, which the name
21
+ matcher missed, are now read. D3, D4 and the Skills cache check read the same written forms.
22
+ - **The `_meta` readers (C-29, C-30, E-8, E-9, E-12, C-32, A-8, DExt1) see through TypeScript wrappers.**
23
+ `x as T`, `x satisfies T`, `x!`, `(x)` and `<T>x` on a `_meta` value, a const initializer or a spread no
24
+ longer hide its keys. A `_meta` that is a TYPE member (`_meta?: Record<string, unknown>` in a type literal,
25
+ `_meta: T` in an interface) is not read as a served object; it turned eight rows `could-not-judge`. A type
26
+ literal in `const x = (…) as { … }` is no longer read as the value of `x`: a `_meta: x` naming such a const
27
+ was silently resolved to the type and read `absent`; it is now `could-not-judge`, naming what `x` is bound to.
28
+ A spread of a call or a member access inside a `_meta` (`...build()`, `...x._meta`), skipped in silence, is
29
+ now named as unread.
30
+
6
31
  ## 0.11.1 — 2026-10-29
7
32
 
8
33
  Patch: a safety fix in the runtime introspector. No rule, verdict form or public type changes.
package/dist/doctor.js CHANGED
@@ -3412,12 +3412,433 @@ function helperImports(tree, re) {
3412
3412
  return [...new Set(out)];
3413
3413
  }
3414
3414
 
3415
+ // src/detectors/tsForms.ts
3416
+ function textBefore(file, line, col, max = 600) {
3417
+ const rows = uncommentedLines(file);
3418
+ let s = rows[line - 1].slice(0, col);
3419
+ for (let n = line - 1; n >= 1 && s.length < max; n--) s = `${rows[n - 1]}
3420
+ ${s}`;
3421
+ return s;
3422
+ }
3423
+ function nextCode(file, line, col, maxLines = 4) {
3424
+ const rows = uncommentedLines(file);
3425
+ for (let n = line; n <= Math.min(file.lines.length, line + maxLines); n++) {
3426
+ const raw = rows[n - 1];
3427
+ for (let c = n === line ? col : 0; c < raw.length; c++) {
3428
+ if (/\s/.test(raw[c])) continue;
3429
+ return { line: n, col: c };
3430
+ }
3431
+ }
3432
+ return null;
3433
+ }
3434
+ function charAt(file, p) {
3435
+ return uncommentedLines(file)[p.line - 1][p.col] ?? "";
3436
+ }
3437
+ function restOfLine(file, p) {
3438
+ return uncommentedLines(file)[p.line - 1].slice(p.col);
3439
+ }
3440
+ function enclosingOpener(file, line, col) {
3441
+ const rows = uncommentedLines(file);
3442
+ let depth = 0;
3443
+ for (let n = line; n >= 1; n--) {
3444
+ const raw = rows[n - 1];
3445
+ for (let c = (n === line ? col : raw.length) - 1; c >= 0; c--) {
3446
+ const ch = raw[c];
3447
+ if (!"()[]{}".includes(ch) || !isCodeAt(file, n, c)) continue;
3448
+ if (ch === ")" || ch === "]" || ch === "}") depth++;
3449
+ else if (depth === 0) return { line: n, col: c, ch };
3450
+ else depth--;
3451
+ }
3452
+ }
3453
+ return null;
3454
+ }
3455
+ function afterClose(file, p, open, close) {
3456
+ const b = balancedBlock(file, p.line, p.col, open, close);
3457
+ if (!b) return null;
3458
+ const endLine = b.endLine;
3459
+ const lastRow = b.text.split("\n").pop() ?? "";
3460
+ const endCol = endLine === p.line ? p.col + lastRow.length : lastRow.length;
3461
+ return { line: endLine, col: endCol };
3462
+ }
3463
+ function colonIsTernary(file, line, col) {
3464
+ const rows = uncommentedLines(file);
3465
+ let depth = 0;
3466
+ let colons = 0;
3467
+ for (let n = line; n >= Math.max(1, line - 12); n--) {
3468
+ const raw = rows[n - 1];
3469
+ for (let c = (n === line ? col : raw.length) - 1; c >= 0; c--) {
3470
+ const ch = raw[c];
3471
+ if (!isCodeAt(file, n, c)) continue;
3472
+ if (ch === ")" || ch === "]" || ch === "}") depth++;
3473
+ else if (ch === "(" || ch === "[" || ch === "{") {
3474
+ if (depth === 0) return false;
3475
+ depth--;
3476
+ } else if (depth === 0) {
3477
+ if (ch === ";") return false;
3478
+ if (ch === ":" && raw[c - 1] !== "?") colons++;
3479
+ if (ch === "?" && raw[c + 1] !== "." && raw[c + 1] !== "?" && raw[c - 1] !== "?") {
3480
+ if (raw.slice(c + 1).trimStart().startsWith(":"))
3481
+ continue;
3482
+ if (colons === 0) return true;
3483
+ colons--;
3484
+ }
3485
+ }
3486
+ }
3487
+ }
3488
+ return false;
3489
+ }
3490
+ var DECL_ANNOTATION = /\b(?:const|let|var|using)\s+[\w$]+\s*$/;
3491
+ function colonContext(file, brace, before, depth) {
3492
+ const colon = lastCodeChar(file, brace);
3493
+ if (!colon) return { kind: "unread", form: "a `:` whose position cannot be read" };
3494
+ if (colonIsTernary(file, colon.line, colon.col)) return { kind: "value" };
3495
+ const head = before.slice(0, -1).trimEnd();
3496
+ if (/\bcase\b[^;{}]*$/.test(head) || /\bdefault$/.test(head)) return { kind: "block" };
3497
+ if (head.endsWith(")")) return { kind: "type" };
3498
+ const enc = enclosingOpener(file, colon.line, colon.col);
3499
+ if (!enc) {
3500
+ if (DECL_ANNOTATION.test(head)) return { kind: "type" };
3501
+ return { kind: "unread", form: `the brace after \`${head.slice(-30).trim()}:\`` };
3502
+ }
3503
+ if (enc.ch === "(") {
3504
+ return /(?:\(|,)\s*(?:\.\.\.)?\s*[\w$]+\s*\??\s*$/.test(head) ? { kind: "type" } : { kind: "value" };
3505
+ }
3506
+ if (enc.ch === "[") return { kind: "value" };
3507
+ const parent = braceContext(file, enc.line, enc.col, depth + 1);
3508
+ if (parent.kind === "block") {
3509
+ return DECL_ANNOTATION.test(head) ? { kind: "type" } : { kind: "block" };
3510
+ }
3511
+ return parent;
3512
+ }
3513
+ function lastCodeChar(file, p) {
3514
+ const rows = uncommentedLines(file);
3515
+ for (let n = p.line; n >= 1; n--) {
3516
+ const raw = rows[n - 1];
3517
+ for (let c = (n === p.line ? p.col : raw.length) - 1; c >= 0; c--) {
3518
+ if (/\s/.test(raw[c])) continue;
3519
+ return { line: n, col: c };
3520
+ }
3521
+ }
3522
+ return null;
3523
+ }
3524
+ function braceContext(file, line, col, depth = 0) {
3525
+ if (depth > 12) return { kind: "unread", form: "a brace nested deeper than 12 levels" };
3526
+ const before = textBefore(file, line, col).replace(/\s+$/, "");
3527
+ if (before === "") return { kind: "block" };
3528
+ if (/\b(?:interface\s+[\w$]+[^{};=()]*|type\s+[\w$]+\s*(?:<[^=]*>)?\s*=|enum\s+[\w$]+|class(?:\s+[\w$]+)?[^{};=()]*|as|satisfies|keyof|typeof|extends|implements\s+[^{};]*)$/.test(
3529
+ before
3530
+ ) || /[<|&]$/.test(before)) {
3531
+ return { kind: "type" };
3532
+ }
3533
+ if (/\b(?:const|let|var|using)$/.test(before)) return { kind: "pattern" };
3534
+ const prevValueToken = /(?:^|[^=!<>])=$/.test(before) || /\b(?:return|yield|await|throw|default)$/.test(before) || /(?:[(,[?!+\-*]|\?\?|\|\||&&|\.\.\.)$/.test(before);
3535
+ if (prevValueToken) {
3536
+ const after = afterClose(file, { line, col }, "{", "}");
3537
+ const next = after ? nextCode(file, after.line, after.col) : null;
3538
+ const rest = next ? restOfLine(file, next) : "";
3539
+ if (/^=(?![=>])/.test(rest)) return { kind: "pattern" };
3540
+ if (/[(,]$/.test(before)) {
3541
+ if (rest.startsWith(":")) return { kind: "pattern" };
3542
+ const enc = enclosingOpener(file, line, col);
3543
+ if (enc && enc.ch === "(") {
3544
+ const close = afterClose(file, enc, "(", ")");
3545
+ const n2 = close ? nextCode(file, close.line, close.col) : null;
3546
+ const r2 = n2 ? restOfLine(file, n2) : "";
3547
+ const head = textBefore(file, enc.line, enc.col).trimEnd();
3548
+ const isCall = /[\w$\])]$/.test(head) && !/\b(?:function|async)$/.test(head);
3549
+ if (r2.startsWith("=>") || r2.startsWith("{")) return { kind: "pattern" };
3550
+ if (r2.startsWith(":") && !isCall) return { kind: "pattern" };
3551
+ }
3552
+ }
3553
+ return { kind: "value" };
3554
+ }
3555
+ if (/(?:\)|=>|[;{}])$/.test(before) || /\b(?:else|try|finally|do)$/.test(before)) {
3556
+ return { kind: "block" };
3557
+ }
3558
+ if (before.endsWith(":")) return colonContext(file, { line, col }, before, depth);
3559
+ return { kind: "unread", form: `the brace after \`${before.slice(-30).trim()}\`` };
3560
+ }
3561
+ function conditionalOfObjects(text) {
3562
+ let depth = 0;
3563
+ let q = -1;
3564
+ let colon = -1;
3565
+ for (let i = 0; i < text.length; i++) {
3566
+ const ch = text[i];
3567
+ if ("([{".includes(ch)) depth++;
3568
+ else if (")]}".includes(ch)) depth--;
3569
+ else if (depth === 0 && ch === "?" && text[i + 1] !== "." && text[i + 1] !== "?" && q < 0)
3570
+ q = i;
3571
+ else if (depth === 0 && ch === ":" && q >= 0 && colon < 0) colon = i;
3572
+ }
3573
+ if (q < 0 || colon < 0) return false;
3574
+ const branch = (b) => /^(?:\{[\s\S]*\}|undefined|null)$/.test(b.trim());
3575
+ return branch(text.slice(q + 1, colon)) && branch(text.slice(colon + 1));
3576
+ }
3577
+ function isTsx(file) {
3578
+ return /\.[jt]sx$/.test(file.path);
3579
+ }
3580
+ function skipType(file, p) {
3581
+ const rows = uncommentedLines(file);
3582
+ let depth = 0;
3583
+ for (let n = p.line; n <= Math.min(file.lines.length, p.line + 20); n++) {
3584
+ const raw = rows[n - 1];
3585
+ for (let c = n === p.line ? p.col : 0; c < raw.length; c++) {
3586
+ const ch = raw[c];
3587
+ if (!isCodeAt(file, n, c)) continue;
3588
+ if (ch === "=" && raw[c + 1] === ">") {
3589
+ c++;
3590
+ continue;
3591
+ }
3592
+ if ("<{([".includes(ch)) depth++;
3593
+ else if (">})]".includes(ch)) {
3594
+ if (depth === 0) return { line: n, col: c };
3595
+ depth--;
3596
+ } else if (depth === 0 && (ch === "," || ch === ";")) return { line: n, col: c };
3597
+ }
3598
+ if (depth === 0) return { line: n, col: raw.length };
3599
+ }
3600
+ return { line: p.line, col: rows[p.line - 1].length };
3601
+ }
3602
+ function readSuffix(file, p, parens) {
3603
+ const wrappers = [];
3604
+ let open = parens;
3605
+ let cur = p;
3606
+ for (let guard = 0; guard < 20; guard++) {
3607
+ cur = cur ? nextCode(file, cur.line, cur.col, 1) : null;
3608
+ if (!cur) return { wrappers };
3609
+ const rest = restOfLine(file, cur);
3610
+ if (rest.startsWith("!") && !rest.startsWith("!=")) {
3611
+ wrappers.push("non-null");
3612
+ cur = { line: cur.line, col: cur.col + 1 };
3613
+ continue;
3614
+ }
3615
+ const kw = rest.match(/^(as|satisfies)\b/);
3616
+ if (kw) {
3617
+ wrappers.push(kw[1]);
3618
+ const t = nextCode(file, cur.line, cur.col + kw[1].length, 1);
3619
+ cur = t ? skipType(file, t) : null;
3620
+ continue;
3621
+ }
3622
+ if (rest.startsWith(")") && open > 0) {
3623
+ open--;
3624
+ cur = { line: cur.line, col: cur.col + 1 };
3625
+ continue;
3626
+ }
3627
+ if (/^(?:[,;})\]]|$)/.test(rest) && open === 0) return { wrappers };
3628
+ if (/^\s*$/.test(rest) && open === 0) return { wrappers };
3629
+ return { foreign: rest.trim().slice(0, 40) };
3630
+ }
3631
+ return { foreign: "an expression the reader stopped following" };
3632
+ }
3633
+ function exprText(file, p) {
3634
+ const raw = restOfLine(file, p);
3635
+ let depth = 0;
3636
+ for (let c = 0; c < raw.length; c++) {
3637
+ const ch = raw[c];
3638
+ if ("([{".includes(ch)) depth++;
3639
+ else if (")]}".includes(ch)) {
3640
+ if (depth === 0) return raw.slice(0, c).trim();
3641
+ depth--;
3642
+ } else if (depth === 0 && (ch === "," || ch === ";")) return raw.slice(0, c).trim();
3643
+ }
3644
+ return raw.trim().slice(0, 60);
3645
+ }
3646
+ function unwrapValue(file, line, col) {
3647
+ const wrappers = [];
3648
+ let parens = 0;
3649
+ let p = nextCode(file, line, col);
3650
+ const firstParen = { line: p?.line ?? line, col: p?.col ?? col };
3651
+ for (let guard = 0; p && guard < 10; guard++) {
3652
+ const ch = charAt(file, p);
3653
+ if (ch === "(") {
3654
+ wrappers.push("parentheses");
3655
+ parens++;
3656
+ p = nextCode(file, p.line, p.col + 1);
3657
+ continue;
3658
+ }
3659
+ if (ch === "<" && !isTsx(file)) {
3660
+ const end = afterClose(file, p, "<", ">");
3661
+ if (!end) return { kind: "other", form: "an unterminated `<T>` type assertion" };
3662
+ wrappers.push("type-assertion");
3663
+ p = nextCode(file, end.line, end.col);
3664
+ continue;
3665
+ }
3666
+ break;
3667
+ }
3668
+ if (!p) return { kind: "other", form: "no value after the key" };
3669
+ const start = p;
3670
+ const rest = restOfLine(file, p);
3671
+ if (charAt(file, p) === "{") {
3672
+ const end = afterClose(file, p, "{", "}");
3673
+ if (!end) return { kind: "other", form: "an object that never closes before end of file" };
3674
+ const suffix2 = readSuffix(file, end, parens);
3675
+ if ("foreign" in suffix2) {
3676
+ return { kind: "other", form: `an object literal followed by \`${suffix2.foreign}\`` };
3677
+ }
3678
+ return {
3679
+ kind: "object",
3680
+ line: start.line,
3681
+ col: start.col,
3682
+ wrappers: [...wrappers, ...suffix2.wrappers]
3683
+ };
3684
+ }
3685
+ if (/^(?:true|false|null|undefined)\b/.test(rest) || /^["'`\d-]/.test(rest)) {
3686
+ return { kind: "literal" };
3687
+ }
3688
+ const id = rest.match(/^[A-Za-z_$][\w$]*/);
3689
+ if (!id) return { kind: "other", form: `\`${exprText(file, p)}\`` };
3690
+ if (/^(?:await|new|typeof|void|yield|delete)$/.test(id[0])) {
3691
+ return { kind: "other", form: `an \`${id[0]}\` expression (\`${exprText(file, start)}\`)` };
3692
+ }
3693
+ const after = { line: p.line, col: p.col + id[0].length };
3694
+ const tail = restOfLine(file, after);
3695
+ if (/^\s*(?:\?\.|\.|\(|\[)/.test(tail) || /^\s*<[^>]*>\s*\(/.test(tail)) {
3696
+ const text = exprText(file, start);
3697
+ if (parens > 0 && conditionalOfObjects(text)) return { kind: "objects-inline", ...firstParen };
3698
+ const kind = /\)\s*$/.test(text.replace(/\s+(?:as|satisfies)\s.*$/, "")) ? "a call" : "a member access";
3699
+ return { kind: "other", form: `${kind} (\`${text}\`)` };
3700
+ }
3701
+ const suffix = readSuffix(file, after, parens);
3702
+ if ("foreign" in suffix) {
3703
+ if (parens > 0 && conditionalOfObjects(exprText(file, start)))
3704
+ return { kind: "objects-inline", ...firstParen };
3705
+ return { kind: "other", form: `\`${id[0]}\` followed by \`${suffix.foreign}\`` };
3706
+ }
3707
+ return { kind: "ident", name: id[0], wrappers: [...wrappers, ...suffix.wrappers] };
3708
+ }
3709
+ function prevCodeText(file, line, col) {
3710
+ return textBefore(file, line, col, 200).trimEnd();
3711
+ }
3712
+ function keyInBrace(file, line, col, name, form, out) {
3713
+ const anchor = `${file.rel}:${line}`;
3714
+ const enc = enclosingOpener(file, line, col);
3715
+ if (!enc || enc.ch !== "{") return;
3716
+ const ctx = braceContext(file, enc.line, enc.col);
3717
+ if (ctx.kind === "value") {
3718
+ out.writes.push({ name, form, file, line, anchor, object: { line: enc.line, col: enc.col } });
3719
+ } else if (ctx.kind === "unread") {
3720
+ out.unread.push({
3721
+ anchor,
3722
+ reason: `\`${name}\` at ${anchor} is a key of a brace whose kind (object value, type, pattern, block) is unread: ${ctx.form}`
3723
+ });
3724
+ }
3725
+ }
3726
+ function fieldWrites(tree, names) {
3727
+ const out = { writes: [], unread: [] };
3728
+ const alt = names.map((n) => n.replace(/[$]/g, "\\$&")).join("|");
3729
+ const identRe = new RegExp(`(?<![\\w$])(${alt})(?![\\w$])`, "g");
3730
+ const quotedRe = new RegExp(`(["'])(${alt})\\1`, "g");
3731
+ for (const file of tree.files) {
3732
+ for (const line of file.lines) {
3733
+ if (line.comment) continue;
3734
+ for (const m of line.raw.matchAll(identRe)) {
3735
+ const col = m.index ?? 0;
3736
+ if (!isCodeAt(file, line.n, col)) continue;
3737
+ const name = m[1];
3738
+ const prev = prevCodeText(file, line.n, col);
3739
+ const nx = nextCode(file, line.n, col + name.length, 1);
3740
+ const after = nx ? restOfLine(file, nx) : "";
3741
+ if (prev.endsWith(".") && !prev.endsWith("...")) {
3742
+ if (/^=(?![=>])/.test(after)) {
3743
+ const base = prev.match(/([\w$]+)\s*\.$/);
3744
+ out.writes.push({
3745
+ name,
3746
+ form: "member-assign",
3747
+ file,
3748
+ line: line.n,
3749
+ anchor: `${file.rel}:${line.n}`,
3750
+ base: base?.[1]
3751
+ });
3752
+ }
3753
+ continue;
3754
+ }
3755
+ const keyPos = /[{,]$/.test(prev);
3756
+ if (!keyPos) continue;
3757
+ if (after.startsWith(":") && !after.startsWith("::")) {
3758
+ keyInBrace(file, line.n, col, name, "key", out);
3759
+ } else if (/^(?:[,}]|$)/.test(after)) {
3760
+ keyInBrace(file, line.n, col, name, "shorthand", out);
3761
+ }
3762
+ }
3763
+ for (const m of line.raw.matchAll(quotedRe)) {
3764
+ const col = m.index ?? 0;
3765
+ if (!isCodeAt(file, line.n, col)) continue;
3766
+ const name = m[2];
3767
+ const prev = prevCodeText(file, line.n, col);
3768
+ const nx = nextCode(file, line.n, col + m[0].length, 1);
3769
+ const after = nx ? restOfLine(file, nx) : "";
3770
+ if (prev.endsWith("[") && /^\]\s*=(?![=>])/.test(after)) {
3771
+ const base = prev.match(/([\w$]+)\s*\??\.?\s*\[$/);
3772
+ out.writes.push({
3773
+ name,
3774
+ form: "bracket-assign",
3775
+ file,
3776
+ line: line.n,
3777
+ anchor: `${file.rel}:${line.n}`,
3778
+ base: base?.[1]
3779
+ });
3780
+ continue;
3781
+ }
3782
+ if (/[{,]$/.test(prev) && after.startsWith(":")) {
3783
+ keyInBrace(file, line.n, col, name, "quoted-key", out);
3784
+ }
3785
+ }
3786
+ }
3787
+ }
3788
+ return out;
3789
+ }
3790
+ function objectMembers(file, p) {
3791
+ const keys = /* @__PURE__ */ new Set();
3792
+ const spreads = [];
3793
+ const b = balancedBlock(file, p.line, p.col, "{", "}");
3794
+ if (!b) return { keys, spreads };
3795
+ const text = b.text.slice(1, -1);
3796
+ let depth = 0;
3797
+ let quote = "";
3798
+ let seg = "";
3799
+ const flush = () => {
3800
+ const s = seg.trim();
3801
+ seg = "";
3802
+ if (!s) return;
3803
+ const spread = s.match(/^\.\.\.\s*([\s\S]+)$/);
3804
+ if (spread) {
3805
+ spreads.push(spread[1].trim());
3806
+ return;
3807
+ }
3808
+ const k = s.match(/^(?:["'`]([^"'`]+)["'`]|([A-Za-z_$][\w$]*))\s*(?:\??:|\(|$)/);
3809
+ if (k) keys.add(k[1] ?? k[2]);
3810
+ };
3811
+ for (let i = 0; i < text.length; i++) {
3812
+ const ch = text[i];
3813
+ if (quote) {
3814
+ seg += ch;
3815
+ if (ch === "\\") {
3816
+ seg += text[++i] ?? "";
3817
+ } else if (ch === quote) quote = "";
3818
+ continue;
3819
+ }
3820
+ if (ch === '"' || ch === "'" || ch === "`") {
3821
+ quote = ch;
3822
+ seg += ch;
3823
+ continue;
3824
+ }
3825
+ if ("([{".includes(ch)) depth++;
3826
+ else if (")]}".includes(ch)) depth--;
3827
+ if (depth === 0 && ch === ",") {
3828
+ flush();
3829
+ continue;
3830
+ }
3831
+ seg += ch;
3832
+ }
3833
+ flush();
3834
+ return { keys, spreads };
3835
+ }
3836
+
3415
3837
  // src/detectors/metaKeys.ts
3416
3838
  var KEY_IN_BLOCK_RE = /(["'`])([A-Za-z0-9_.-]+\/[^"'`\s]*)\1\s*:/g;
3417
3839
  var META_OPEN_RE = /\b_meta\??\s*[:=]\s*/g;
3418
3840
  var CAP_OPEN_RE = /\b(extensions|experimental)\s*:\s*/g;
3419
3841
  var META_BRACKET_RE = /\b_meta\s*\[\s*(["'`])([^"'`]+\/[^"'`]*)\1\s*\]/g;
3420
- var SPREAD_RE = /\.\.\.\s*([A-Za-z_$][\w$]*)\b(?!\s*[(.[])/g;
3421
3842
  function addKeys(block, file, obj, acc) {
3422
3843
  obj.texts.push(block.text);
3423
3844
  block.text.split("\n").forEach((text, i) => {
@@ -3432,19 +3853,33 @@ function addKeys(block, file, obj, acc) {
3432
3853
  }
3433
3854
  });
3434
3855
  }
3435
- function findConstBlock(tree, name) {
3856
+ function findConstBinding(tree, name) {
3436
3857
  const re = new RegExp(
3437
- `\\b(?:const|let|var)\\s+${name.replace(/[$]/g, "\\$&")}\\b[^=\\n]*=\\s*`,
3858
+ `\\b(?:const|let|var)\\s+${name.replace(/[$]/g, "\\$&")}\\b[^=\\n]*=(?![=>])\\s*`,
3438
3859
  "g"
3439
3860
  );
3861
+ const forms = [];
3440
3862
  for (const site of codeSites(tree, re)) {
3441
3863
  const after = site.col + site.match[0].length;
3442
- const op = nextOpener(site.file, site.line.n, after, "{", 1);
3443
- if (!op) continue;
3444
- const block = balancedBlock(site.file, op.line, op.col, "{", "}");
3445
- if (block) return { file: site.file, block };
3864
+ const core = unwrapValue(site.file, site.line.n, after);
3865
+ if (core.kind === "object") {
3866
+ const block = balancedBlock(site.file, core.line, core.col, "{", "}");
3867
+ if (block) return { found: { file: site.file, block, col: core.col }, forms };
3868
+ forms.push(`an object at ${site.anchor} that never closes`);
3869
+ } else if (core.kind === "ident") {
3870
+ forms.push(`the identifier \`${core.name}\` at ${site.anchor}`);
3871
+ } else if (core.kind === "literal") {
3872
+ forms.push(`a literal at ${site.anchor}`);
3873
+ } else if (core.kind === "objects-inline") {
3874
+ forms.push(`a conditional of object literals at ${site.anchor}`);
3875
+ } else {
3876
+ forms.push(`${core.form} at ${site.anchor}`);
3877
+ }
3446
3878
  }
3447
- return null;
3879
+ return { found: null, forms };
3880
+ }
3881
+ function findConstBlock(tree, name) {
3882
+ return findConstBinding(tree, name).found;
3448
3883
  }
3449
3884
  function followIdent(tree, name, obj, acc, hops, seen, from) {
3450
3885
  if (seen.has(name)) return;
@@ -3456,29 +3891,47 @@ function followIdent(tree, name, obj, acc, hops, seen, from) {
3456
3891
  });
3457
3892
  return;
3458
3893
  }
3459
- const found = findConstBlock(tree, name);
3894
+ const { found, forms } = findConstBinding(tree, name);
3460
3895
  if (!found) {
3896
+ const bound = forms.length > 0 ? ` (bound to ${forms.join("; ")})` : "";
3461
3897
  acc.unreadable.push({
3462
3898
  anchor: from,
3463
- reason: `\`${name}\` (reached from ${from}) is not a const object in this tree \u2014 the keys it carries are unread`
3899
+ reason: `\`${name}\` (reached from ${from}) is not a const object in this tree${bound} \u2014 the keys it carries are unread`
3464
3900
  });
3465
3901
  return;
3466
3902
  }
3467
3903
  addKeys(found.block, found.file, obj, acc);
3468
- for (const sp of found.block.text.matchAll(SPREAD_RE)) {
3469
- followIdent(tree, sp[1], obj, acc, hops - 1, seen, from);
3470
- }
3904
+ followSpreads(tree, found.block, found.col, found.file, obj, acc, hops - 1, seen, from);
3905
+ }
3906
+ var SPREAD_ANY_RE = /\.\.\.\s*/g;
3907
+ function followSpreads(tree, block, startCol, file, obj, acc, hops, seen, from) {
3908
+ const rows = block.text.split("\n");
3909
+ rows.forEach((row, i) => {
3910
+ for (const m of row.matchAll(SPREAD_ANY_RE)) {
3911
+ const lineNo = block.startLine + i;
3912
+ const at = (i === 0 ? startCol : 0) + (m.index ?? 0);
3913
+ if (!isCodeAt(file, lineNo, at)) continue;
3914
+ const core = unwrapValue(file, lineNo, at + m[0].length);
3915
+ if (core.kind === "ident") {
3916
+ followIdent(tree, core.name, obj, acc, hops, seen, from);
3917
+ } else if (core.kind === "other") {
3918
+ acc.unreadable.push({
3919
+ anchor: `${file.rel}:${lineNo}`,
3920
+ reason: `the spread at ${file.rel}:${lineNo} (reached from ${from}) is ${core.form} \u2014 the keys it carries are unread`
3921
+ });
3922
+ }
3923
+ }
3924
+ });
3471
3925
  }
3472
3926
  function readValue(tree, file, lineNo, col, context, acc) {
3473
3927
  const raw = file.lines[lineNo - 1].raw;
3474
3928
  const rest = raw.slice(col);
3475
3929
  const anchor = `${file.rel}:${lineNo}`;
3476
3930
  if (/^z\s*\./.test(rest.trim())) return;
3477
- const op = nextOpener(file, lineNo, col, "{[(", rest.trim() === "" ? 1 : 0);
3478
- const identMatch = rest.match(/^([A-Za-z_$][\w$]*)\s*(?:[,;)}]|as\b|$)/);
3479
3931
  const obj = { anchor, context, file, texts: [], keys: [] };
3480
- if (op && op.ch === "{" && (rest.trim() === "" || rest.trimStart().startsWith("{"))) {
3481
- const block = balancedBlock(file, op.line, op.col, "{", "}");
3932
+ const core = unwrapValue(file, lineNo, col);
3933
+ if (core.kind === "object") {
3934
+ const block = balancedBlock(file, core.line, core.col, "{", "}");
3482
3935
  if (!block) {
3483
3936
  acc.unreadable.push({
3484
3937
  anchor,
@@ -3488,28 +3941,41 @@ function readValue(tree, file, lineNo, col, context, acc) {
3488
3941
  }
3489
3942
  acc.objects.push(obj);
3490
3943
  addKeys(block, file, obj, acc);
3491
- const seen = /* @__PURE__ */ new Set();
3492
- for (const sp of block.text.matchAll(SPREAD_RE)) {
3493
- followIdent(tree, sp[1], obj, acc, 3, seen, anchor);
3494
- }
3944
+ followSpreads(tree, block, core.col, file, obj, acc, 3, /* @__PURE__ */ new Set(), anchor);
3495
3945
  return;
3496
3946
  }
3497
- if (identMatch && /^(true|false|null|undefined)$/.test(identMatch[1])) return;
3498
- if (identMatch) {
3947
+ if (core.kind === "literal") return;
3948
+ if (core.kind === "objects-inline") {
3949
+ const block = balancedBlock(file, core.line, core.col, "(", ")");
3950
+ if (block) {
3951
+ acc.objects.push(obj);
3952
+ addKeys(block, file, obj, acc);
3953
+ return;
3954
+ }
3955
+ }
3956
+ if (core.kind === "ident") {
3957
+ if (/^(?:undefined)$/.test(core.name)) return;
3499
3958
  acc.objects.push(obj);
3500
- followIdent(tree, identMatch[1], obj, acc, 3, /* @__PURE__ */ new Set(), anchor);
3959
+ followIdent(tree, core.name, obj, acc, 3, /* @__PURE__ */ new Set(), anchor);
3501
3960
  return;
3502
3961
  }
3503
- if (rest.trim() !== "" && !rest.trimStart().startsWith("{")) {
3504
- acc.unreadable.push({
3505
- anchor,
3506
- reason: `the ${context} value at ${anchor} is neither an object literal nor a same-tree const (\`${rest.trim().slice(0, 60)}\`) \u2014 its keys are unread`
3507
- });
3508
- }
3962
+ acc.unreadable.push({
3963
+ anchor,
3964
+ reason: `the ${context} value at ${anchor} is neither an object literal nor a same-tree const (${core.kind === "other" ? core.form : "a conditional whose parentheses never close"}) \u2014 its keys are unread`
3965
+ });
3966
+ }
3967
+ function isTypeMember(file, lineNo, col, matched) {
3968
+ if (/\?\s*:/.test(matched)) return true;
3969
+ if (!/:/.test(matched)) return false;
3970
+ const enc = enclosingOpener(file, lineNo, col);
3971
+ if (!enc || enc.ch !== "{") return false;
3972
+ const ctx = braceContext(file, enc.line, enc.col);
3973
+ return ctx.kind === "type" || ctx.kind === "pattern";
3509
3974
  }
3510
3975
  function collectNamespacedKeys(tree) {
3511
3976
  const acc = { keys: [], objects: [], arrayForms: [], unreadable: [] };
3512
3977
  for (const site of codeSites(tree, META_OPEN_RE)) {
3978
+ if (isTypeMember(site.file, site.line.n, site.col, site.match[0])) continue;
3513
3979
  readValue(tree, site.file, site.line.n, site.col + site.match[0].length, "_meta", acc);
3514
3980
  }
3515
3981
  for (const site of codeSites(tree, CAP_OPEN_RE)) {
@@ -3639,8 +4105,8 @@ function readSkillsSurface(tree) {
3639
4105
  function skillsCacheProblems(tree) {
3640
4106
  if (!readSkillsSurface(tree).declared) return null;
3641
4107
  const sites = methodSites(tree, ["skills/list", "skills/get"]);
3642
- const ttl = lineHits(tree, /\bttlMs\b/);
3643
- const scope = lineHits(tree, /\bcacheScope\b/);
4108
+ const ttl = fieldWrites(tree, ["ttlMs"]).writes;
4109
+ const scope = fieldWrites(tree, ["cacheScope"]).writes;
3644
4110
  const problems = [];
3645
4111
  let first = "";
3646
4112
  for (const [method, anchors] of sites) {
@@ -10249,7 +10715,7 @@ function absentBelowRevision(id, anchor, rule, fields, negotiated, where) {
10249
10715
  }
10250
10716
 
10251
10717
  // src/detectors/d3.ts
10252
- var RESULT_TYPE_RE = /\bresultType\b/;
10718
+ var RESULT_TYPE_FIELD = ["resultType"];
10253
10719
  var KIT_RESULT_CALL_RE = /\b(buildToolsListResult|buildListResult|buildToolCallResult)\s*\(/;
10254
10720
  var d3 = {
10255
10721
  id: "D3 resultType",
@@ -10257,17 +10723,31 @@ var d3 = {
10257
10723
  pin: STANDARD_PIN,
10258
10724
  run(tree) {
10259
10725
  const builders = findListReadBuilders(tree);
10260
- const rt = countKeywordInCode(tree, RESULT_TYPE_RE);
10726
+ const rt = fieldWrites(tree, RESULT_TYPE_FIELD);
10261
10727
  const kit = countKeywordInCode(tree, KIT_RESULT_CALL_RE);
10262
- if (rt.count > 0 || kit.count > 0) {
10263
- const src = rt.count > 0 ? rt : kit;
10728
+ if (rt.writes.length > 0) {
10729
+ return {
10730
+ id: this.id,
10731
+ anchor: rt.writes[0].anchor,
10732
+ state: "present",
10733
+ verdict: "resultType present"
10734
+ };
10735
+ }
10736
+ if (kit.count > 0) {
10264
10737
  return {
10265
10738
  id: this.id,
10266
- anchor: src.firstFile ? `${src.firstFile.rel}:${src.firstLine}` : "-",
10739
+ anchor: kit.firstFile ? `${kit.firstFile.rel}:${kit.firstLine}` : "-",
10267
10740
  state: "present",
10268
- verdict: rt.count > 0 ? "resultType present" : "resultType via kit result-builder call"
10741
+ verdict: "resultType via kit result-builder call"
10269
10742
  };
10270
10743
  }
10744
+ if (rt.unread.length > 0) {
10745
+ return couldNotJudge(
10746
+ this.id,
10747
+ rt.unread[0].anchor,
10748
+ `${rt.unread.length} resultType site(s) could not be read \u2014 ${rt.unread[0].reason} (S-2)`
10749
+ );
10750
+ }
10271
10751
  if (builders.length === 0) {
10272
10752
  const sdk = sdkFirstAnchor(tree);
10273
10753
  if (sdk) {
@@ -10382,7 +10862,7 @@ var d3 = {
10382
10862
  };
10383
10863
 
10384
10864
  // src/detectors/d4.ts
10385
- var CACHEABLE_RE = /\b(ttlMs|cacheScope)\b/;
10865
+ var CACHEABLE_FIELDS = ["ttlMs", "cacheScope"];
10386
10866
  var d4 = {
10387
10867
  id: "D4 CacheableResult",
10388
10868
  rule: "S-3",
@@ -10398,15 +10878,22 @@ var d4 = {
10398
10878
  };
10399
10879
  }
10400
10880
  const builders = findListReadBuilders(tree);
10401
- const cache2 = countKeywordInCode(tree, CACHEABLE_RE);
10402
- if (cache2.count > 0) {
10881
+ const cache2 = fieldWrites(tree, CACHEABLE_FIELDS);
10882
+ if (cache2.writes.length > 0) {
10403
10883
  return {
10404
10884
  id: this.id,
10405
- anchor: cache2.firstFile ? `${cache2.firstFile.rel}:${cache2.firstLine}` : "-",
10885
+ anchor: cache2.writes[0].anchor,
10406
10886
  state: "present",
10407
10887
  verdict: "CacheableResult present (ttlMs/cacheScope)"
10408
10888
  };
10409
10889
  }
10890
+ if (cache2.unread.length > 0) {
10891
+ return couldNotJudge(
10892
+ this.id,
10893
+ cache2.unread[0].anchor,
10894
+ `${cache2.unread.length} ttlMs/cacheScope site(s) could not be read \u2014 ${cache2.unread[0].reason} (S-3)`
10895
+ );
10896
+ }
10410
10897
  if (builders.length === 0) {
10411
10898
  const sdk = sdkFirstAnchor(tree);
10412
10899
  if (sdk) {
@@ -10709,34 +11196,72 @@ function sdkV2Dependency(pkgJson) {
10709
11196
  }
10710
11197
  return { kind: "none" };
10711
11198
  }
10712
- var HANDROLLED_FIELD_RE = /\b(resultType|ttlMs|cacheScope)\s*:/;
11199
+ var HANDROLLED_FIELDS = ["resultType", "ttlMs", "cacheScope"];
11200
+ var RESULT_PAYLOAD_KEYS = [
11201
+ "resultType",
11202
+ "content",
11203
+ "structuredContent",
11204
+ "isError",
11205
+ "tools",
11206
+ "resources",
11207
+ "resourceTemplates",
11208
+ "prompts",
11209
+ "contents",
11210
+ "messages",
11211
+ "completion",
11212
+ "nextCursor"
11213
+ ];
11214
+ function baseIsResult(file, base, tree) {
11215
+ if (!base) return false;
11216
+ const esc4 = base.replace(/[$]/g, "\\$&");
11217
+ const keys = RESULT_PAYLOAD_KEYS.join("|");
11218
+ const assigned = new RegExp(
11219
+ `\\b${esc4}\\s*(?:\\.\\s*(?:${keys})|\\[\\s*["'](?:${keys})["']\\s*\\])\\s*=(?![=>])`
11220
+ );
11221
+ if (file.lines.some((l) => !l.comment && assigned.test(l.raw))) return true;
11222
+ const one = { ...tree, files: [file] };
11223
+ const bound = findConstBinding(one, base).found;
11224
+ if (!bound) return false;
11225
+ const m = objectMembers(bound.file, { line: bound.block.startLine, col: bound.col });
11226
+ return RESULT_PAYLOAD_KEYS.some((k) => m.keys.has(k));
11227
+ }
10713
11228
  function handRolledBuilder(tree) {
10714
- for (const file of tree.files) {
10715
- const code = file.lines;
10716
- let hintsDepth = 0;
10717
- for (const line of code) {
10718
- if (line.comment) continue;
10719
- const opens = (line.raw.match(/\{/g) ?? []).length;
10720
- const closes = (line.raw.match(/\}/g) ?? []).length;
10721
- const startsHints = /\bcacheHints\s*:/.test(line.raw);
10722
- const inside = hintsDepth > 0 || startsHints;
10723
- if (!inside) {
10724
- const m = line.raw.match(HANDROLLED_FIELD_RE);
10725
- if (m) return { file: file.rel, line: line.n, field: m[1] };
10726
- }
10727
- if (startsHints || hintsDepth > 0) {
10728
- hintsDepth += opens - closes;
10729
- if (hintsDepth < 0) hintsDepth = 0;
11229
+ const scan = fieldWrites(tree, HANDROLLED_FIELDS);
11230
+ const unread = [...scan.unread];
11231
+ for (const w of scan.writes) {
11232
+ let result = w.name === "resultType";
11233
+ if (!result && w.object) {
11234
+ const m = objectMembers(w.file, w.object);
11235
+ result = RESULT_PAYLOAD_KEYS.some((k) => m.keys.has(k));
11236
+ if (!result && m.spreads.length > 0) {
11237
+ unread.push({
11238
+ anchor: w.anchor,
11239
+ reason: `\`${w.name}\` is written at ${w.anchor} into an object whose other members come from \`...${m.spreads[0]}\`: whether that object is a protocol result is unread (D7)`
11240
+ });
11241
+ continue;
10730
11242
  }
11243
+ } else if (!result) {
11244
+ result = baseIsResult(w.file, w.base, tree);
11245
+ }
11246
+ if (result) {
11247
+ return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread };
10731
11248
  }
10732
11249
  }
10733
- return null;
11250
+ return { hand: null, unread };
11251
+ }
11252
+ function controlTree2(text) {
11253
+ const file = {
11254
+ path: "<d7-control>.ts",
11255
+ rel: "<d7-control>",
11256
+ lines: text.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }))
11257
+ };
11258
+ return { root: "<d7-control>", files: [file], packageJson: null, skippedDirs: [] };
10734
11259
  }
10735
11260
  var d7Inner = {
10736
11261
  id: "D7 protocol-kit",
10737
11262
  run(tree) {
10738
11263
  const v2 = (r) => sdkV2Dependency({ dependencies: { [SDK_V2_PKG]: r } }).kind;
10739
- if (v2("^2.3.1") !== "v2" || v2(">=2 <3") !== "v2" || v2("^1.12.0") !== "below-v2" || v2("latest") !== "unreadable" || !HANDROLLED_FIELD_RE.test('{ resultType: "complete" }') || HANDROLLED_FIELD_RE.test("{ resultTypes: [] }")) {
11264
+ if (v2("^2.3.1") !== "v2" || v2(">=2 <3") !== "v2" || v2("^1.12.0") !== "below-v2" || v2("latest") !== "unreadable" || handRolledBuilder(controlTree2("export const r = () => ({ content: [], ttlMs: 0 });")).hand === null || handRolledBuilder(controlTree2("export const u = (ok: boolean) => (ok ? ttlMs : 0);")).hand !== null) {
10740
11265
  throw new Error(
10741
11266
  "D7 control FAILED: SDK v2 range reader / hand-rolled matcher broken \u2014 verdict untrustworthy"
10742
11267
  );
@@ -10782,13 +11307,23 @@ var d7Inner = {
10782
11307
  };
10783
11308
  }
10784
11309
  if (sdk.kind === "v2") {
10785
- const hand = handRolledBuilder(tree);
11310
+ const { hand, unread } = handRolledBuilder(tree);
10786
11311
  if (hand) {
10787
11312
  return {
10788
11313
  id: this.id,
10789
11314
  anchor: `${hand.file}:${hand.line}`,
10790
11315
  state: "non-conforming",
10791
- verdict: `hand-rolled result builder (\`${hand.field}:\` written in source at ${hand.file}:${hand.line}) and @vantageos/mcp-protocol-kit not a dependency -> let the SDK emit resultType/ttlMs/cacheScope (cacheHints) or adopt the kit (D7)`
11316
+ verdict: `hand-rolled result builder (\`${hand.field}\` written by hand as a ${hand.form} into a result object at ${hand.file}:${hand.line}) and @vantageos/mcp-protocol-kit not a dependency -> let the SDK emit resultType/ttlMs/cacheScope (cacheHints) or adopt the kit (D7)`
11317
+ };
11318
+ }
11319
+ if (unread.length > 0) {
11320
+ const reason = `${unread.length} protocol-field write(s) could not be judged \u2014 ${unread[0].reason}`;
11321
+ return {
11322
+ id: this.id,
11323
+ anchor: unread[0].anchor,
11324
+ state: "could-not-judge",
11325
+ reason,
11326
+ verdict: `could not judge: ${reason}`
10792
11327
  };
10793
11328
  }
10794
11329
  return {
@@ -13846,7 +14381,7 @@ var PII_RE = /\b(?:email|e[_-]?mail|ip[_-]?address|full[_-]?name|phone[_-]?numbe
13846
14381
  var INTERNAL_RE = /\b(?:hostname|host[_-]?name|absolute[_-]?path|internal[_-]?path|infra[_-]?version|server[_-]?version|__dirname|__filename)\b/;
13847
14382
  var STACK_RE = /\b(?:error|err|e|ex|exception)\.stack\b/;
13848
14383
  var CLIENT_SINK_RE = /\b(?:content|text|message|body)\s*:|(?:\breturn\b|\bthrow\b|JSON\.stringify)/;
13849
- var SPREAD_RE2 = /\.\.\.[A-Za-z_$]/;
14384
+ var SPREAD_RE = /\.\.\.[A-Za-z_$]/;
13850
14385
  var SECRET_POSITIVE = "apiKey";
13851
14386
  var SECRET_NEGATIVE = "customerId";
13852
14387
  var PII_POSITIVE = "email";
@@ -14068,7 +14603,7 @@ var dServer6 = {
14068
14603
  });
14069
14604
  }
14070
14605
  for (const call of calls) {
14071
- if (SPREAD_RE2.test(call.argText)) {
14606
+ if (SPREAD_RE.test(call.argText)) {
14072
14607
  unreadable.push({
14073
14608
  anchor: call.anchor,
14074
14609
  reason: `cannot inspect the spread argument of the log call at ${call.anchor} \u2014 a spread hides arbitrary content, secret/PII presence unverifiable (C-6)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vantageos/mcp-doctor",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
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",