diff --git a/docs/content/9.extending.md b/docs/content/9.extending.md index f6d96124b..d2e5e8512 100644 --- a/docs/content/9.extending.md +++ b/docs/content/9.extending.md @@ -450,7 +450,9 @@ export default defineDoctorConfig({ - **Reports:** `sources` in the JSON report lists each source with its `targets`. The rerun command repeats the flags from `toOptions`, with `secret` values replaced by ``. - **Network:** use the `fetch` from the context, which tests and other runtimes can replace through the run's `fetch` option. -A source's `name` shares one namespace with Runtime Evidence contributors. +A source the run reads can't share its `name` with a Runtime Evidence contributor, because both write `project.runtimeEvidence.`. + +Doctor's own [live MCP check](/mcp) is the `mcp` Evidence Source, which is why its flags are `--mcp-url` and `--mcp-header`. In code, pass its input as `sources: { mcp: [{ url, headers }] }`. ## Rule inputs diff --git a/docs/content/9.mcp.md b/docs/content/9.mcp.md index 56a026127..502fe7198 100644 --- a/docs/content/9.mcp.md +++ b/docs/content/9.mcp.md @@ -69,7 +69,7 @@ Source shows the tools as written; a running server shows the tools a client get pnpm vite-doctor . --mcp-url http://localhost:3000/mcp ``` -Run it in an empty directory to check only the server. The text report says `Checked: MCP server `. JSON and agent reports name the server in `subject.mcpServers`; JSON has `framework: null`, while the agent report has `project: null`. Doctor activates only the MCP Rule Pack and lists the server's origin as that pack's `activatedBy`. Rerun commands keep the original scan directory and repeat `--mcp-url` without adding `--framework`. +Run it in an empty directory to check only the server. The text report says `Checked: MCP server `. JSON and agent reports name the server in `subject.live`, as `{ source: "mcp", target: "" }`; JSON has `framework: null`, while the agent report has `project: null`. Doctor activates only the MCP Rule Pack and lists the server's origin as that pack's `activatedBy`. Rerun commands keep the original scan directory and repeat `--mcp-url` without adding `--framework`. Both flags repeat. Every `--mcp-header` goes to every `--mcp-url`: diff --git a/src/builtin-sources.ts b/src/builtin-sources.ts new file mode 100644 index 000000000..ef2e26da6 --- /dev/null +++ b/src/builtin-sources.ts @@ -0,0 +1,5 @@ +import type { EvidenceSource } from "./core/primitives.js"; +import { mcpEvidenceSource } from "./mcp/evidence.js"; + +/** Evidence Sources Doctor ships. The CLI declares their flags so `--help` lists them. */ +export const builtinEvidenceSources: readonly EvidenceSource[] = [mcpEvidenceSource]; diff --git a/src/cli-main.ts b/src/cli-main.ts index cd0a70531..406992f30 100644 --- a/src/cli-main.ts +++ b/src/cli-main.ts @@ -21,13 +21,17 @@ import { type DoctorPresentation, } from "./core/internal/agent-runtime.js"; import { applyDoctorOptions, stringFlag } from "./core/internal/cli.js"; -import { evidenceSourceFlags, evidenceSourceInputs } from "./core/internal/evidence-sources.js"; +import { + evidenceSourceFlags, + evidenceSourceInputs, + validateEvidenceSources, +} from "./core/internal/evidence-sources.js"; import { githubAnnotations } from "./core/internal/github-annotations.js"; import { readViteConfigDoctor } from "./core/internal/vite-config-doctor.js"; import { findViteConfigFile } from "./core/internal/vite-config-file.js"; import type { DoctorProcessStatus } from "./doctor-process/client.js"; import { DOCTOR_PROCESS_ENV } from "./doctor-process/protocol.js"; -import { assertAbsoluteMcpUrl } from "./mcp/evidence.js"; +import { builtinEvidenceSources } from "./builtin-sources.js"; import { viteDoctorVersion } from "./version.js"; type MetadataReportFormat = Exclude; @@ -44,8 +48,8 @@ const frameworks = new Set>([ ]); const severities = new Set>(["error", "warn", "info"]); const analyses = new Set(["dead-code", "graph", "dupes", "health"]); -// cac's `type: [String]` fills an absent array option with "undefined" once another one is set. -const repeatableOptions = new Set(["mcpUrl", "mcpHeader"]); +const builtinSourceFlags = evidenceSourceFlags(builtinEvidenceSources); +const builtinSourceFlagNames = new Set(builtinSourceFlags.map(({ flag }) => flag)); const sourceArgumentBoundary = "--doctorSourceArgument=1"; class CliConfigError extends Error { @@ -310,7 +314,7 @@ function applyHostExtensions( function validateSingleValueOptions(cli: ReturnType): void { for (const option of [...cli.globalCommand.options, ...(cli.matchedCommand?.options ?? [])]) { - if (option.isBoolean || option.config.type || repeatableOptions.has(option.name)) continue; + if (option.isBoolean || option.config.type) continue; if (!option.names.some((name) => Array.isArray(cli.options[name]))) continue; throw new Error(`Option --${kebabFlag(option.name)} may only be provided once.`); } @@ -326,7 +330,7 @@ function splitEvidenceSourceArgs( for (const command of [cli.globalCommand, ...cli.commands]) { for (const option of command.options) { for (const flag of option.rawName.split(/[,\s]+/)) { - if (flag.startsWith("-")) reserved.add(flag); + if (flag.startsWith("-") && !builtinSourceFlagNames.has(flag)) reserved.add(flag); } } } @@ -380,7 +384,10 @@ async function prepareEvidenceSourceRun( known.add(flag); } for (const flag of source.keys()) if (!known.has(flag)) throw unknownOption(flag); - const inputs = evidenceSourceInputs(declarations, source); + const inputs = evidenceSourceInputs( + declarations.filter(({ source }) => !builtinEvidenceSources.includes(source)), + source, + ); if (inputs) runOptions.sources = { ...runOptions.sources, ...inputs }; return runOptions; } @@ -427,14 +434,6 @@ function addDoctorRunCommand( .option("--full", "Print the whole text or agent report, without a Report Budget.") .option("--config ", "Explicitly load an executable Doctor config.") .option("--host-extensions", hostExtensionsHelp) - .option( - "--mcp-url ", - "Read tools/list from this MCP server as Runtime Evidence. Repeatable.", - ) - .option( - "--mcp-header
", - 'Request header for every --mcp-url, as "Name: value". Repeatable.', - ) .option("--watch", "Rerun Doctor when project files change.") .option( "--server", @@ -463,6 +462,11 @@ function addDoctorRunCommand( applyHostExtensions(runOptions, surface, options); validateCliRunOptions(runOptions); validateReportBudget(options, format); + const builtinInputs = evidenceSourceInputs(builtinSourceFlags, evidenceArgs().source); + if (builtinInputs) { + await validateEvidenceSources(builtinEvidenceSources, builtinInputs); + runOptions.sources = builtinInputs; + } const report = { cwd, formatFlag: stringFlag(options.format) as DoctorReportFormat, @@ -498,6 +502,8 @@ function addDoctorRunCommand( // cac defaults negated flags to true, which renders as `(default: true)` on `--no-cache` // and makes every run look like an explicit `--cache` in rerun commands. for (const option of command.options) if (option.negated) option.config.default = undefined; + for (const { flag, definition } of builtinSourceFlags) + command.option(`${flag} <${definition.value ?? "value"}>`, definition.help); } async function watchDoctorCommand( @@ -723,7 +729,6 @@ function validateReportBudget(flags: Record, format: DoctorRepo } function validateCliRunOptions(options: DoctorRunOptions): void { - for (const target of options.mcp ?? []) assertAbsoluteMcpUrl(target.url); if (options.updateBaseline && !options.baseline) throw new Error("--update-baseline requires --baseline ."); if (options.framework && !frameworks.has(options.framework)) { diff --git a/src/core/config.ts b/src/core/config.ts index 8e4052169..d21257992 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -8,7 +8,6 @@ import type { ProjectInfo, RuntimeTarget, } from "./primitives.js"; -import type { McpServerTarget } from "../mcp/evidence.js"; export type { DoctorConfigOverride, DoctorRuleConfig, @@ -61,11 +60,6 @@ export interface DoctorRunOptions { */ hostExtensions?: boolean; runtimeTarget?: RuntimeTarget; - /** - * MCP servers whose `tools/list` Vite Doctor reads as `mcp` Runtime Evidence. Headers can carry - * tokens, so this stays out of Doctor config files. - */ - mcp?: McpServerTarget[]; /** * Inputs for Evidence Sources, keyed by source name. A source without an input is not read. * Inputs can carry tokens, so they stay out of Doctor config files. diff --git a/src/core/internal/cli.ts b/src/core/internal/cli.ts index da13cce17..9c37e119f 100644 --- a/src/core/internal/cli.ts +++ b/src/core/internal/cli.ts @@ -1,5 +1,4 @@ import type { DoctorRunOptions } from "../config.js"; -import { isMcpHeaderName } from "@loadsheet/mcp"; export function applyDoctorOptions( options: DoctorRunOptions, @@ -29,39 +28,6 @@ export function applyDoctorOptions( options.format = (stringFlag(flags.format) as DoctorRunOptions["format"]) ?? options.format; if (flags.full) options.maxChars = Number.POSITIVE_INFINITY; if (flags.maxChars !== undefined) options.maxChars = Number(flags.maxChars); - options.mcp = parseMcpFlags(flags.mcpUrl, flags.mcpHeader) ?? options.mcp; -} - -/** `--mcp-url` and `--mcp-header` are repeatable; every header applies to every URL. */ -function parseMcpFlags(urls: unknown, headers: unknown): DoctorRunOptions["mcp"] { - const urlList = listFlag(urls, "--mcp-url"); - const headerList = listFlag(headers, "--mcp-header"); - if (!urlList.length) { - if (headerList.length) throw new Error("--mcp-header requires --mcp-url ."); - return undefined; - } - const parsed = new Map(); - for (const header of headerList) { - const colon = header.indexOf(":"); - const name = colon === -1 ? "" : header.slice(0, colon).trim(); - if (!isMcpHeaderName(name)) - throw new Error( - '--mcp-header must look like "Name: value", such as "Authorization: Bearer ".', - ); - parsed.set(name, header.slice(colon + 1).trim()); - } - return urlList.map((url) => ({ - url, - ...(parsed.size ? { headers: Object.fromEntries(parsed) } : {}), - })); -} - -function listFlag(value: unknown, flag: string): string[] { - const values = value === undefined ? [] : Array.isArray(value) ? value : [value]; - return values.map((item) => { - if (typeof item !== "string" || !item) throw new Error(`${flag} requires a value.`); - return item; - }); } function parseExtends(value: string | undefined): DoctorRunOptions["extends"] { diff --git a/src/core/internal/evidence-sources.ts b/src/core/internal/evidence-sources.ts index 25d08a03b..bde3da8d1 100644 --- a/src/core/internal/evidence-sources.ts +++ b/src/core/internal/evidence-sources.ts @@ -98,10 +98,10 @@ export async function validateEvidenceSources( export async function collectEvidenceSources( project: ProjectInfo, requested: readonly RequestedSource[], - fetch: typeof globalThis.fetch = globalThis.fetch, + contributeRuntimeEvidence: () => Promise, + fetch: typeof globalThis.fetch = (input, init) => globalThis.fetch(input, init), ): Promise { - const runs: EvidenceSourceRun[] = []; - for (const { source, input } of requested) { + async function collect(source: EvidenceSource, input: unknown): Promise { const { name } = source; const result = await source.collect(input, { project, fetch }); project.runtimeEvidence = { ...project.runtimeEvidence, [name]: result.evidence }; @@ -111,12 +111,21 @@ export async function collectEvidenceSources( ...result.gaps.map((gap) => ({ source: name, files: [], ...gap })), ]; } - runs.push({ + return { name, label: source.label, targets: result.targets ?? [], args: sourceArgs(source, input), - }); + }; + } + const earlyRuns = new Map(); + for (const { source, input } of requested) { + if (source.beforeRuntimeEvidence) earlyRuns.set(source.name, await collect(source, input)); + } + await contributeRuntimeEvidence(); + const runs: EvidenceSourceRun[] = []; + for (const { source, input } of requested) { + runs.push(earlyRuns.get(source.name) ?? (await collect(source, input))); } return runs; } diff --git a/src/core/internal/scan-session.ts b/src/core/internal/scan-session.ts index 8551b47b1..fd45f45f2 100644 --- a/src/core/internal/scan-session.ts +++ b/src/core/internal/scan-session.ts @@ -165,9 +165,23 @@ export async function createScanSession( sessionBase.config = config; const extensions = [...(config.extensions ?? []), ...(options.extensions ?? [])]; const registry = await collectRulePacks(extensions); + // A source's evidence is stored under its name, next to what contributors return. Only a source + // the run reads can clash, so an Extension may still contribute evidence under a builtin name. + assertUniqueContributors( + [ + ...registry.runtimeEvidenceContributors, + ...registry.sources.filter((source) => options.sources?.[source.name] !== undefined), + ], + "Runtime Evidence", + ); const requestedSources = await validateEvidenceSources(registry.sources, options.sources); - await applyProjectContributions(project, registry); - const evidenceSources = await collectEvidenceSources(project, requestedSources, options.fetch); + await applyProjectInventory(project, registry); + const evidenceSources = await collectEvidenceSources( + project, + requestedSources, + () => applyRuntimeEvidence(project, registry), + options.fetch, + ); if (options.affectedFiles && fullRunWhen?.(project)) { options = { ...options, affectedFiles: undefined }; sessionBase.options = options; @@ -425,8 +439,7 @@ export async function collectRulePacks(inputs: readonly DoctorExtensionInput[]): assertUniqueContributors(inventoryContributors, "Project Inventory"); const sources = extensions.flatMap((extension) => extension.sources ?? []); assertEvidenceSourceNames(sources); - // A source's evidence is stored under its name, next to what contributors return. - assertUniqueContributors([...runtimeEvidenceContributors, ...sources], "Runtime Evidence"); + assertUniqueContributors(sources, "Runtime Evidence"); return { packs, rules: packs.flatMap((pack) => pack.rules), @@ -449,14 +462,14 @@ function assertUniqueContributors( } } -async function applyProjectContributions( - project: ProjectInfo, - registry: RuleRegistry, -): Promise { +async function applyProjectInventory(project: ProjectInfo, registry: RuleRegistry): Promise { for (const contributor of registry.inventoryContributors) { const contribution = await contributor.contribute(project); project.inventory = { ...project.inventory, [contributor.name]: contribution }; } +} + +async function applyRuntimeEvidence(project: ProjectInfo, registry: RuleRegistry): Promise { for (const contributor of registry.runtimeEvidenceContributors) { const contribution = await contributor.contribute(project); project.runtimeEvidence = { ...project.runtimeEvidence, [contributor.name]: contribution }; diff --git a/src/core/primitives.ts b/src/core/primitives.ts index d45975071..7b97650b9 100644 --- a/src/core/primitives.ts +++ b/src/core/primitives.ts @@ -1602,6 +1602,8 @@ export interface DoctorRunResult { rulePacks?: RulePackActivation[]; /** Evidence Sources the run read because it was given an input for them. */ evidenceSources?: EvidenceSourceRun[]; + /** Live targets supplied by contributors rather than read through Evidence Sources. */ + contributedLiveTargets?: LiveTargetGroup[]; graph?: { files: number; importEdges: number; @@ -1638,6 +1640,8 @@ export interface EvidenceSource { name: string; /** What a target is, such as "MCP server". */ label: string; + /** Collect after Project Inventory but before Runtime Evidence contributors. Defaults to false. */ + beforeRuntimeEvidence?: boolean; /** CLI flags, keyed by option name in camelCase. */ options?: Record; /** Builds the input from CLI flag values, keyed by option name. Throws on a value it can't use. */ @@ -1681,11 +1685,15 @@ export interface EvidenceSourceResult { gaps?: Array<{ message: string; instanceKey?: string }>; } -/** An Evidence Source a Doctor Run read. */ -export interface EvidenceSourceRun { +/** Live targets grouped by the name and display label of their source. */ +export interface LiveTargetGroup { name: string; label: string; targets: string[]; +} + +/** An Evidence Source a Doctor Run read. */ +export interface EvidenceSourceRun extends LiveTargetGroup { /** CLI arguments that read the source again, with secret values redacted. */ args: string[]; } diff --git a/src/core/reports.ts b/src/core/reports.ts index 493168e3d..86018d58b 100644 --- a/src/core/reports.ts +++ b/src/core/reports.ts @@ -1,5 +1,4 @@ import { isAbsolute, relative } from "pathe"; -import { isMcpHeaderName, parseMcpEndpoint } from "@loadsheet/mcp"; import pc from "picocolors"; import { formatDiagnostic } from "nostics"; import type { @@ -10,6 +9,7 @@ import type { DoctorReportFormat, DoctorRunResult, DoctorSeverity, + LiveTargetGroup, FixSafety, RulePack, } from "./primitives.js"; @@ -23,7 +23,6 @@ import { diagnosticMetadataByCode, diagnosticMetadataByRuleId } from "./diagnost import type { DoctorRunOptions } from "./config.js"; import { shellArgument } from "./internal/utils.js"; import { REDACTED } from "./internal/evidence-sources.js"; -import { mcpServerLabels } from "../mcp/evidence.js"; import { unresolvedRuntimeInventory } from "./internal/runtime-packages.js"; import { defaultReportBudget, type ReportReader } from "./internal/agent-runtime.js"; import { scoreDiagnostics } from "./internal/scoring.js"; @@ -220,13 +219,32 @@ function evidenceKey(item: DiagnosticEvidence): string { } /** - * The MCP servers a Doctor Run without a project checked, by endpoint label. Without a project - * they are the run's subject, so reports name them instead of a fallback framework. + * Without a project, the live targets are the run's subject rather than a fallback framework. */ -function mcpSubject(result: DoctorRunResult): string[] | undefined { +function liveSubject(result: DoctorRunResult): LiveTargetGroup[] | undefined { if (!result.project.noProject) return undefined; - const servers = mcpServerLabels(result.project.runtimeEvidence); - return servers.length ? servers : undefined; + const groups = new Map(); + for (const { name, label, targets } of [ + ...(result.evidenceSources ?? []), + ...(result.contributedLiveTargets ?? []), + ]) { + if (!targets.length) continue; + const group = groups.get(name); + groups.set(name, { + name, + label: group?.label ?? label, + targets: [...new Set([...(group?.targets ?? []), ...targets])], + }); + } + return groups.size ? [...groups.values()] : undefined; +} + +function subjectTargets(subject: LiveTargetGroup[]) { + return { + live: subject.flatMap(({ name, targets }) => + targets.map((target) => ({ source: name, target })), + ), + }; } /** Diagnostic Codes with their counts, in report order. */ @@ -485,11 +503,12 @@ function textLayout( function textHead(result: DoctorRunResult, groups: ReportGroup[]): string[] { const lines: string[] = []; const status = reportStatus(result); - const subject = mcpSubject(result); + const subject = liveSubject(result); if (subject) { - lines.push( - `Checked: ${subject.length === 1 ? "MCP server" : "MCP servers"} ${subject.join(", ")}`, + const checked = subject.map( + ({ label, targets }) => `${label}${targets.length === 1 ? "" : "s"} ${targets.join(", ")}`, ); + lines.push(`Checked: ${checked.join("; ")}`); lines.push(`Project: none, ${result.root} has no package.json`); } else { lines.push(`Detected: ${frameworkLabel(result)}`); @@ -497,7 +516,7 @@ function textHead(result: DoctorRunResult, groups: ReportGroup[]): string[] { } if (status === "incomplete") { lines.push( - `Status: incomplete, required ${subject ? "MCP server" : "project"} evidence is missing`, + `Status: incomplete, required ${subject ? subject.map(({ label }) => label).join(", ") : "project"} evidence is missing`, ); } for (const gap of result.project.evidenceGaps ?? []) { @@ -602,14 +621,14 @@ function isEvidenceBacked(confidence: Confidence) { } export function createJsonReport(result: DoctorRunResult): string { - const subject = mcpSubject(result); + const subject = liveSubject(result); return `${JSON.stringify( { version: result.version, reportVersion: result.reportVersion ?? 4, fingerprintScheme: FINGERPRINT_SCHEME, status: reportStatus(result), - subject: subject && { mcpServers: subject }, + subject: subject && subjectTargets(subject), framework: subject ? null : result.framework, root: result.root, scope: result.scope, @@ -658,7 +677,7 @@ function agentLayout( ): ProgressiveLayout { const status = reportStatus(result); const plugin = context.surface === "plugin"; - const subject = mcpSubject(result); + const subject = liveSubject(result); const commandArgs = plugin ? undefined : { @@ -699,7 +718,7 @@ function agentLayout( `${JSON.stringify({ schema: "vite-doctor.agent/v3", status, - subject: subject && { mcpServers: subject }, + subject: subject && subjectTargets(subject), project: subject ? null : { @@ -1178,7 +1197,7 @@ function runArguments( context: DoctorReportContext, command: RunCommand, ): string[] { - const args = mcpSubject(result) + const args = liveSubject(result) ? ["vite-doctor", command.root ?? result.root] : ["vite-doctor", command.root ?? ".", "--framework", agentFramework(result, context)]; if (result.scope.mode === "changed") { @@ -1202,9 +1221,6 @@ function runArguments( ] as const) { if (value !== undefined) args.push(flag, String(value)); } - for (const target of options?.mcp ?? []) args.push("--mcp-url", commandMcpUrl(target.url)); - for (const name of Object.keys(options?.mcp?.[0]?.headers ?? {})) - if (isMcpHeaderName(name)) args.push("--mcp-header", `${name}: ${REDACTED}`); for (const source of result.evidenceSources ?? []) args.push(...source.args); if (options?.newOnly) args.push("--new-only"); if (options?.profile) args.push("--profile"); @@ -1215,17 +1231,7 @@ function runArguments( } const REDACTED_NOTE = - "Doctor redacts flag values that can carry secrets, such as --mcp-header values and the credentials, query strings, and custom paths of an --mcp-url. Replace each with the value you ran with."; -const PUBLIC_MCP_PATHS = new Set(["/", "/mcp", "/sse", "/v1/sse", "/github-copilot/mcp"]); - -function commandMcpUrl(value: string): string { - const url = parseMcpEndpoint(value); - if (!url) return REDACTED; - const credentials = url.username || url.password ? `${REDACTED}@` : ""; - const path = PUBLIC_MCP_PATHS.has(url.pathname) ? url.pathname : `/${REDACTED}`; - const query = url.search ? `?${REDACTED}` : ""; - return `${url.protocol}//${credentials}${url.host}${path}${query}`; -} + "Doctor redacts flag values that can carry secrets, such as tokens in headers or URLs. Replace each with the value you ran with."; // Workspace runs derive Rule Packs from every workspace package, which pinning the resolved // framework would replace with that framework's packs alone. diff --git a/src/doctor.ts b/src/doctor.ts index 7670c1863..b3972d7ec 100644 --- a/src/doctor.ts +++ b/src/doctor.ts @@ -34,8 +34,9 @@ import { packageRulePack } from "./rule-packs/package/index.js"; import { piniaRulePack } from "./rule-packs/pinia/index.js"; import { mcpRulePack } from "./rule-packs/mcp/index.js"; import { - mcpEvidenceExtension, + mcpEvidenceSource, mcpEvidenceUsed, + mcpServerLabels, readMcpServers, uncheckedMcpEvidenceGap, unreadMcpServerGaps, @@ -87,7 +88,11 @@ export async function viteDoctorExtensions( rulePacks: [designSystemRulePack], }), defineDoctorExtension({ name: "vite-doctor/builtin-pinia", rulePacks: [piniaRulePack] }), - defineDoctorExtension({ name: "vite-doctor/builtin-mcp", rulePacks: [mcpRulePack] }), + defineDoctorExtension({ + name: "vite-doctor/builtin-mcp", + rulePacks: [mcpRulePack], + sources: [mcpEvidenceSource], + }), ]; if (frameworks.has("nuxt")) { const { nuxtDoctorExtensions } = await import("./rule-packs/nuxt/rules/index.js"); @@ -140,6 +145,16 @@ export async function runPreparedViteDoctor( const gaps = [...unreadMcpServerGaps(result.project), ...(unchecked ? [unchecked] : [])]; if (gaps.length) result.project.evidenceGaps = [...(result.project.evidenceGaps ?? []), ...gaps]; if (used.length) result.project.evidenceUsed = [...(result.project.evidenceUsed ?? []), ...used]; + if (result.project.noProject) { + const { name, label } = mcpEvidenceSource; + const sourceTargets = new Set( + result.evidenceSources?.find((source) => source.name === name)?.targets, + ); + const targets = mcpServerLabels(result.project.runtimeEvidence).filter( + (target) => !sourceTargets.has(target), + ); + if (targets.length) result.contributedLiveTargets = [{ name, label, targets }]; + } return { ...result, version: viteDoctorVersion }; } @@ -149,7 +164,6 @@ export async function viteDoctorRunOptions(options: DoctorRunOptions): Promise readServer(target, options)), - ); - const gaps = new Map[number]>(); - for (const server of mcpServers) { - if (!("error" in server)) continue; - const instanceKey = unreadGapKey(server); - if (gaps.has(instanceKey)) continue; - gaps.set(instanceKey, { - source: MCP_EVIDENCE, - message: `Doctor could not read the tools of the MCP server at ${server.url}, so its tools were not checked: ${server.error}${authHint(server.status)}`, - files: [], - instanceKey, - }); - } - if (gaps.size) project.evidenceGaps = [...(project.evidenceGaps ?? []), ...gaps.values()]; - return { mcpServers }; - }, - }); +export const mcpEvidenceSource: EvidenceSource = { + name: MCP_EVIDENCE, + label: "MCP server", + beforeRuntimeEvidence: true, + options: { + url: { + help: "Read tools/list from this MCP server as Runtime Evidence. Repeatable.", + value: "url", + repeatable: true, + // Credentials, query strings, and custom paths can all carry secrets. + secret(value, redacted) { + const url = parseMcpEndpoint(value); + if (!url) return redacted; + const credentials = url.username || url.password ? `${redacted}@` : ""; + const path = PUBLIC_MCP_PATHS.has(url.pathname) ? url.pathname : `/${redacted}`; + return `${url.protocol}//${credentials}${url.host}${path}${url.search ? `?${redacted}` : ""}`; + }, }, - }; -} + header: { + help: 'Request header for every --mcp-url, as "Name: value". Repeatable.', + value: "header", + repeatable: true, + requires: "url", + secret: (value, redacted) => `${value.slice(0, value.indexOf(":"))}: ${redacted}`, + }, + }, + fromOptions({ url = [], header = [] }) { + const headers = new Map(); + for (const entry of header) { + const colon = entry.indexOf(":"); + const name = colon === -1 ? "" : entry.slice(0, colon).trim(); + if (!isMcpHeaderName(name)) + throw new Error( + '--mcp-header must look like "Name: value", such as "Authorization: Bearer ".', + ); + headers.set(name, entry.slice(colon + 1).trim()); + } + return url.map((target) => ({ + url: target, + ...(headers.size ? { headers: Object.fromEntries(headers) } : {}), + })); + }, + toOptions: (targets) => ({ + url: targets.map((target) => target.url), + header: Object.entries(targets[0]?.headers ?? {}) + .filter(([name]) => isMcpHeaderName(name)) + .map(([name, value]) => `${name}: ${value}`), + }), + validate(targets) { + for (const target of targets) assertAbsoluteMcpUrl(target.url); + }, + async collect(targets, { fetch }) { + const mcpServers = await Promise.all(targets.map((target) => readServer(target, { fetch }))); + const gaps = new Map(); + for (const server of mcpServers) { + if (!("error" in server)) continue; + const instanceKey = unreadGapKey(server); + if (gaps.has(instanceKey)) continue; + gaps.set(instanceKey, { + message: `Doctor could not read the tools of the MCP server at ${server.url}, so its tools were not checked: ${server.error}${authHint(server.status)}`, + instanceKey, + }); + } + return { + evidence: { mcpServers }, + targets: mcpServerLabels({ [MCP_EVIDENCE]: { mcpServers } }), + gaps: [...gaps.values()], + }; + }, +}; async function readServer( { url, headers, serverName }: McpServerTarget, diff --git a/src/plugin-run.ts b/src/plugin-run.ts index 17c94c9be..a4c9b8f04 100644 --- a/src/plugin-run.ts +++ b/src/plugin-run.ts @@ -138,7 +138,7 @@ export async function hasEnabledBuildEvidenceCandidate( if (!evidence) return false; const options = surfaceDoctorOptions(input, extensions); const session = await createScanSession( - await viteDoctorRunOptions({ ...options, rules: BUILD_EVIDENCE_RULE, mcp: undefined }), + await viteDoctorRunOptions({ ...options, rules: BUILD_EVIDENCE_RULE, sources: undefined }), ); if (!session.enabledRules.some((rule) => rule.meta.id === BUILD_EVIDENCE_RULE)) return false; const files = new Map(session.files.map((file) => [file.path, file])); @@ -168,7 +168,7 @@ export async function runBuildEvidenceDoctor( extensions: DoctorExtensionInput[], ): Promise { return runSurfaceDoctor( - { ...input, options: { ...input.options, rules: BUILD_EVIDENCE_RULE, mcp: undefined } }, + { ...input, options: { ...input.options, rules: BUILD_EVIDENCE_RULE, sources: undefined } }, extensions, ); } diff --git a/src/plugin.ts b/src/plugin.ts index 37e422ff8..e8640a62e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -840,7 +840,7 @@ function surfaceRunInput( cache: options.cache ?? true, format: options.format, maxChars: options.maxChars, - mcp: options.mcp && surfaceMcpTargets(options.mcp, devServer), + sources: options.mcp?.length ? { mcp: surfaceMcpTargets(options.mcp, devServer) } : undefined, }, vite: { inventory: viteInventory(config), diff --git a/tests/core/evidence-sources.test.ts b/tests/core/evidence-sources.test.ts index 8cf89e378..c7e6e4cba 100644 --- a/tests/core/evidence-sources.test.ts +++ b/tests/core/evidence-sources.test.ts @@ -1,4 +1,4 @@ -import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "pathe"; import { afterEach, expect, test, vi } from "vite-plus/test"; @@ -127,11 +127,12 @@ test("every input is validated before any source is collected", async () => { expect(collected).toEqual([]); }); -test("a source can't share its name with a Runtime Evidence contributor", async () => { +test("a source the run reads can't share its name with a Runtime Evidence contributor", async () => { await expect( runViteDoctor({ root: project(), cache: false, + sources: { status: { urls: ["https://status.example.test"] } }, extensions: [ extension(statusSource()), { @@ -352,3 +353,17 @@ test("an unknown flag stays an error without a config", async () => { expect(code).toBe(2); expect(output).toContain("Unknown option `--chnaged`"); }); + +test("the core and the CLI entry reach MCP only through its Evidence Source", () => { + const src = join(import.meta.dirname, "../../src"); + const files = [ + ...readdirSync(join(src, "core"), { recursive: true, encoding: "utf8" }) + .filter((file) => file.endsWith(".ts")) + .map((file) => join(src, "core", file)), + join(src, "cli-main.ts"), + ]; + for (const file of files) { + const code = readFileSync(file, "utf8"); + expect(code, file).not.toMatch(/@loadsheet\/mcp|from "(\.\.?\/)+mcp\/|--mcp-/); + } +}); diff --git a/tests/mcp/evidence.test.ts b/tests/mcp/evidence.test.ts index 1407ac874..e84ab9ec1 100644 --- a/tests/mcp/evidence.test.ts +++ b/tests/mcp/evidence.test.ts @@ -5,7 +5,7 @@ import { afterEach, expect, test, vi } from "vite-plus/test"; import { main } from "../../src/cli.ts"; import { createReport, reportStatus, runDoctor } from "../../src/core/index.ts"; import { runViteDoctor } from "../../src/doctor.ts"; -import { createRule, defineRulePack } from "../../src/extension.ts"; +import { createRule, defineDoctorExtension, defineRulePack } from "../../src/extension.ts"; import { readMcpServers } from "../../src/mcp/evidence.ts"; import { viteDoctorVersion } from "../../src/version.ts"; import { startMcpStub, stubTools, type StubRequest } from "./mcp-stub.ts"; @@ -33,10 +33,38 @@ async function stub(options: Parameters[0] = {}) { const mcpServerPackage = { "@modelcontextprotocol/sdk": "^1.32.0" }; +test("Runtime Evidence contributors can read the collected MCP tools", async () => { + const url = mockToolPages([[{ name: "search" }]]); + const result = await runViteDoctor({ + root: project(mcpServerPackage), + cache: false, + sources: { mcp: [{ url }] }, + extensions: [ + defineDoctorExtension({ + name: "fixture/tool-count", + setup(api) { + api.registerRuntimeEvidenceContributor({ + name: "tool-count", + contribute: ({ runtimeEvidence }) => { + const [server] = readMcpServers(runtimeEvidence); + return { count: server && "tools" in server ? server.tools.length : 0 }; + }, + }); + }, + }), + ], + }); + expect(result.project.runtimeEvidence?.["tool-count"]).toEqual({ count: 1 }); +}); + test("a Doctor Run reads an MCP server's tools/list as Runtime Evidence", async () => { const server = await stub(); const root = project(mcpServerPackage); - const result = await runViteDoctor({ root, cache: false, mcp: [{ url: server.url }] }); + const result = await runViteDoctor({ + root, + cache: false, + sources: { mcp: [{ url: server.url }] }, + }); const evidence = result.project.runtimeEvidence?.mcp as { mcpServers: Array<{ name?: string; url: string; tools: unknown[] }>; @@ -57,7 +85,7 @@ test("an MCP server that answers 401 leaves an evidence gap and an incomplete re const result = await runViteDoctor({ root, cache: false, - mcp: [{ url: server.url }, { url: server.url, serverName: "again" }], + sources: { mcp: [{ url: server.url }, { url: server.url, serverName: "again" }] }, }); expect(reportStatus(result)).toBe("incomplete"); @@ -79,7 +107,9 @@ test("headers reach the MCP server and never reach the report", async () => { const result = await runViteDoctor({ root, cache: false, - mcp: [{ url: server.url, headers: { authorization: "Bearer secret" }, serverName: "drops" }], + sources: { + mcp: [{ url: server.url, headers: { authorization: "Bearer secret" }, serverName: "drops" }], + }, }); expect(readMcpServers(result.project.runtimeEvidence)).toEqual([ @@ -107,16 +137,16 @@ test("malformed tool lists leave a gap without exposing the request URL", async }); const root = project(mcpServerPackage); const url = "https://user:password@example.test/path-secret?token=query-secret#fragment-secret"; - const result = await runViteDoctor({ root, cache: false, mcp: [{ url }] }); + const result = await runViteDoctor({ root, cache: false, sources: { mcp: [{ url }] } }); expect(reportStatus(result)).toBe("incomplete"); expect(result.project.evidenceGaps?.[0]?.message).toContain("tools[0]"); const report = createReport(result, "agent", { - runOptions: { root, mcp: [{ url, headers: { "invalid fake-secret": "value" } }] }, + runOptions: { root }, }); expect(JSON.parse(report).commandArgs.rerun).toEqual( expect.arrayContaining(["--mcp-url", "https://@example.test/?"]), ); - expect(report).not.toMatch(/path-secret|query-secret|fragment-secret|password|fake-secret/); + expect(report).not.toMatch(/path-secret|query-secret|fragment-secret|password/); expect(JSON.stringify(result.project.runtimeEvidence)).not.toMatch( /path-secret|query-secret|fragment-secret|password/, ); @@ -125,7 +155,11 @@ test("malformed tool lists leave a gap without exposing the request URL", async test("MCP evidence activates the MCP Rule Pack in a project without an MCP package", async () => { const server = await stub(); const origin = new URL(server.url).origin; - const result = await runViteDoctor({ root: project(), cache: false, mcp: [{ url: server.url }] }); + const result = await runViteDoctor({ + root: project(), + cache: false, + sources: { mcp: [{ url: server.url }] }, + }); expect(result.project.evidenceGaps ?? []).toEqual([]); expect(result.rulePacks).toContainEqual( @@ -142,7 +176,7 @@ test("MCP evidence activates the MCP Rule Pack in a project without an MCP packa root: project(), cache: false, extends: ["strict"], - mcp: [{ url: server.url }], + sources: { mcp: [{ url: server.url }] }, }); expect(strict.project.evidenceGaps ?? []).toEqual([]); }); @@ -156,7 +190,11 @@ test("MCP evidence activates the MCP Rule Pack for every workspace package", asy writeFileSync(join(root, "packages", name, "package.json"), JSON.stringify({ name })); writeFileSync(join(root, "packages", name, "index.ts"), "export const ok = 1;\n"); } - const result = await runViteDoctor({ root, cache: false, mcp: [{ url: server.url }] }); + const result = await runViteDoctor({ + root, + cache: false, + sources: { mcp: [{ url: server.url }] }, + }); const pack = result.rulePacks?.find((item) => item.name === "vite-doctor/mcp"); expect(pack?.selected).toBe(true); @@ -218,7 +256,11 @@ function mockRemoteToolWithIncompatibleSchema() { test("fetched MCP evidence is not reported as used when client Rules are filtered out", async () => { mockRemoteToolWithIncompatibleSchema(); - const options = { root: project(), cache: false, mcp: [{ url: "https://example.test/mcp" }] }; + const options = { + root: project(), + cache: false, + sources: { mcp: [{ url: "https://example.test/mcp" }] }, + }; const checked = await runViteDoctor(options); expect(checked.diagnostics.map(({ code }) => code)).toContain("MCP0005"); expect(checked.project.evidenceUsed).toEqual([ @@ -238,7 +280,7 @@ test("MCP tool Rules that check the tools a server sends report its evidence as const result = await runViteDoctor({ root: project(), cache: false, - mcp: [{ url: "https://example.test/mcp" }], + sources: { mcp: [{ url: "https://example.test/mcp" }] }, rules: "mcp/tools/*", }); expect(result.diagnostics.map(({ code }) => code)).toContain("MCP0001"); @@ -253,7 +295,7 @@ test("only project-wide client Rules cover remote-only MCP tools without the MCP root: project(), cache: false, extends: ["vite-doctor/typescript/recommended"], - mcp: [{ url: "https://example.test/mcp" }], + sources: { mcp: [{ url: "https://example.test/mcp" }] }, }; const rules = { "mcp/clients/no-excluded-tool": "error" } as const; const fileOnly = await runViteDoctor({ @@ -306,7 +348,7 @@ server.registerTool('remote', {}, async () => ({ content: [] })) config: { overrides: [{ files: ["index.ts"], rules: { "mcp/clients/no-excluded-tool": "error" } }], }, - mcp: [{ url: "https://example.test/mcp" }, { url: "https://other.test/mcp" }], + sources: { mcp: [{ url: "https://example.test/mcp" }, { url: "https://other.test/mcp" }] }, }); expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "MCP0005", file })); expect(reportStatus(result)).toBe("incomplete"); @@ -328,7 +370,7 @@ test("an extends list that leaves out the MCP Rule Pack leaves an evidence gap", root: project(), cache: false, extends: ["vite-doctor/typescript/recommended"], - mcp: [{ url: server.url }], + sources: { mcp: [{ url: server.url }] }, }); expect(reportStatus(result)).toBe("incomplete"); @@ -430,7 +472,7 @@ test("--mcp-url and --mcp-header repeat, and every header goes to every URL", as "--format", "agent", ]); - expect(report.placeholders[""]).toContain("--mcp-header values"); + expect(report.placeholders[""]).toContain("tokens in headers"); }); test("--mcp-url checks a server from an empty directory, naming Doctor as the client", async () => { @@ -459,7 +501,9 @@ test("--mcp-url checks a server from an empty directory, naming Doctor as the cl diagnostics: Array<{ code: string }>; }; expect(report.status).toBe("findings"); - expect(report.subject).toEqual({ mcpServers: [new URL(server.url).origin] }); + expect(report.subject).toEqual({ + live: [{ source: "mcp", target: new URL(server.url).origin }], + }); expect(report.framework).toBeNull(); expect(report).not.toHaveProperty("project"); expect(report.rulePacks.map((pack) => pack.name)).toEqual(["vite-doctor/mcp"]); @@ -539,7 +583,7 @@ test("Doctor reads all 50 pages of an MCP tool list", async () => { const result = await runViteDoctor({ root: emptyDirectory(), cache: false, - mcp: [{ url }], + sources: { mcp: [{ url }] }, }); expect(readMcpServers(result.project.runtimeEvidence)).toEqual([ expect.objectContaining({ tools }), @@ -558,7 +602,7 @@ test("an MCP server checked from an empty directory is the report's subject, not rulePacks: unknown[]; commandArgs: Record; }; - expect(report.subject).toEqual({ mcpServers: [origin] }); + expect(report.subject).toEqual({ live: [{ source: "mcp", target: origin }] }); expect(report.project).toBeNull(); expect(report.rulePacks).toEqual([ { name: "vite-doctor/mcp", selected: true, activatedBy: [origin] }, @@ -587,6 +631,95 @@ test("an MCP server checked from an empty directory is the report's subject, not expect(text.output).not.toMatch(/Detected:|Vite/); }); +test("a contributor's MCP targets are the live subject and rerun from another directory", async () => { + const root = emptyDirectory(); + const config = join(emptyDirectory(), "doctor.config.mjs"); + const target = "https://example.test"; + writeFileSync( + config, + `export default { extensions: [{ + name: "fixture/contributed-mcp", + setup(api) { + api.registerRuntimeEvidenceContributor({ + name: "mcp", + contribute: () => ({ mcpServers: [{ url: "${target}/private", tools: [{ name: "search" }] }] }), + }); + }, + }] };`, + ); + const args = ["--no-cache", "--config", config]; + const subject = { live: [{ source: "mcp", target }] }; + const json = await cli(root, [...args, "--format", "json"]); + expect(JSON.parse(json.output)).toMatchObject({ subject, framework: null }); + const agent = await cli(root, [...args, "--format", "agent"]); + const report = JSON.parse(agent.output); + expect(report).toMatchObject({ subject, project: null }); + expect(report.commandArgs.rerun).toEqual([ + "vite-doctor", + root, + "--config", + config, + "--no-cache", + "--format", + "agent", + ]); + const rerun = await cli(project(), report.commandArgs.rerun.slice(1)); + expect(JSON.parse(rerun.output)).toMatchObject({ + subject, + project: null, + rulePacks: report.rulePacks, + }); + const text = await cli(root, [...args, "--format", "text"]); + expect(text.output).toContain(`Checked: MCP server ${target}\n`); +}); + +test("builtin and extension source flags share the same string-preserving parser", async () => { + const url = mockToolPages([stubTools]); + const root = emptyDirectory(); + const config = "doctor.config.mjs"; + writeFileSync( + join(root, config), + `export default { extensions: [{ name: "fixture/status", sources: [{ + name: "status", label: "Status page", options: { revision: { help: "Revision." } }, + fromOptions: ({ revision }) => revision[0], + collect: (revision) => ({ evidence: {}, targets: [revision] }), + }] }] };`, + ); + const { code, output } = await cli(root, [ + "--mcp-url", + url, + "--status-revision=00123", + "--config", + config, + "--format", + "json", + ]); + expect(code).toBe(0); + expect(JSON.parse(output).sources).toEqual([ + expect.objectContaining({ name: "mcp", targets: [new URL(url).origin] }), + expect.objectContaining({ name: "status", targets: ["00123"] }), + ]); +}); + +test("malformed builtin source flags fail before executable config loads", async () => { + const root = emptyDirectory(); + const config = "doctor.config.mjs"; + writeFileSync(join(root, config), 'throw new Error("config should not load");'); + const { code, output } = await cli(root, [ + "--format", + "json", + "--config", + config, + "--mcp-url", + "/mcp", + ]); + expect(code).toBe(2); + expect(JSON.parse(output).error).toMatchObject({ + kind: "invocation", + message: expect.stringContaining("is not an absolute http(s) URL"), + }); +}); + async function rerunArgs(urls: string[]) { const args = urls.flatMap((url) => ["--mcp-url", url]); const root = emptyDirectory(); @@ -623,7 +756,7 @@ test("rerun commands redact custom --mcp-url paths and entire query strings", as new RegExp(`${zapier}|${hex}|short-secret|query-name-secret`), ); expect(report.placeholders).toEqual({ - "": expect.stringContaining("custom paths of an --mcp-url"), + "": expect.stringContaining("Replace each "), }); }); diff --git a/tests/mcp/progressive-report.test.ts b/tests/mcp/progressive-report.test.ts index 55b00ad96..b4e9ae88d 100644 --- a/tests/mcp/progressive-report.test.ts +++ b/tests/mcp/progressive-report.test.ts @@ -26,7 +26,7 @@ beforeAll(async () => { root, cache: false, extends: ["auto", "mcp/strict"], - mcp: [{ url: stub.url, headers: { authorization: "Bearer secret-token" } }], + sources: { mcp: [{ url: stub.url, headers: { authorization: "Bearer secret-token" } }] }, }; result = await runViteDoctor(options); expect(result.diagnostics.length).toBeGreaterThan(20); diff --git a/tests/rule-packs/mcp/client-limits.test.ts b/tests/rule-packs/mcp/client-limits.test.ts index fdf5327ba..167fb09b0 100644 --- a/tests/rule-packs/mcp/client-limits.test.ts +++ b/tests/rule-packs/mcp/client-limits.test.ts @@ -318,7 +318,7 @@ test("tools read from a running server through the mcp option are checked", asyn const server = await startMcpStub({ tools: [search, lookup] }); cleanups.push(server.close); const root = project(); - const { diagnostics } = await run(root, { mcp: [{ url: server.url }] }); + const { diagnostics } = await run(root, { sources: { mcp: [{ url: server.url }] } }); expect(summary(root, diagnostics)).toEqual([ "MCP0005 error .", @@ -354,23 +354,23 @@ test.each([false, true])( const exclusions = (diagnostics: Diagnostic[]) => diagnostics.filter((item) => item.code === "MCP0005"); - const initial = await run(root, { mcp: [first] }); + const initial = await run(root, { sources: { mcp: [first] } }); const [known] = exclusions(initial.diagnostics); expect(known?.range !== undefined).toBe(sourceMatch); writeBaseline(root, "baseline.json", initial.diagnostics); - const combined = await run(root, { mcp: [second, first] }); + const combined = await run(root, { sources: { mcp: [second, first] } }); const findings = exclusions(combined.diagnostics); expect(findings).toHaveLength(2); expect(new Set(findings.map((item) => item.fingerprint)).size).toBe(2); expect(JSON.stringify(findings)).not.toMatch(/private-[ab]|secret-[ab]/); const filtered = await run(root, { - mcp: [first, second], + sources: { mcp: [first, second] }, baseline: "baseline.json", newOnly: true, }); - const standalone = await run(root, { mcp: [second] }); + const standalone = await run(root, { sources: { mcp: [second] } }); expect(exclusions(filtered.diagnostics).map((item) => item.fingerprint)).toEqual( exclusions(standalone.diagnostics).map((item) => item.fingerprint), ); @@ -398,7 +398,7 @@ test.each(["HTTP", "extension"])( }); const options = (): DoctorRunOptions => source === "HTTP" - ? { mcp: [{ url: "https://example.test/mcp" }] } + ? { sources: { mcp: [{ url: "https://example.test/mcp" }] } } : { extensions: contributing([ { name: "stub", tools: [{ ...lookup, inputSchema: { type: "object", properties } }] }, @@ -443,7 +443,10 @@ test("the Recommended Preset reports only excluded tools and truncated text", as const server = await startMcpStub({ tools: [search, lookup] }); cleanups.push(server.close); const root = project(); - const { diagnostics } = await run(root, { extends: ["auto"], mcp: [{ url: server.url }] }); + const { diagnostics } = await run(root, { + extends: ["auto"], + sources: { mcp: [{ url: server.url }] }, + }); expect([...new Set(diagnostics.map((item) => item.code))]).toEqual(["MCP0005"]); }); @@ -491,7 +494,7 @@ test("an Extension's failed read of a URL Doctor also read adds no second gap", const other = "http://127.0.0.1:2/mcp"; const root = project(); const { result } = await run(root, { - mcp: [{ url }], + sources: { mcp: [{ url }] }, extensions: contributing([ { url, error: "x", status: 503 }, { url, endpointId: url, error: "x" }, diff --git a/tests/vite/plugin-mcp-evidence.test.ts b/tests/vite/plugin-mcp-evidence.test.ts index f9a9278b3..900699767 100644 --- a/tests/vite/plugin-mcp-evidence.test.ts +++ b/tests/vite/plugin-mcp-evidence.test.ts @@ -179,6 +179,29 @@ test("in a build, an MCP path is a config error", async () => { }); }); +test("an empty MCP target list leaves the MCP evidence key available to extensions", async () => { + await withProject(async (root) => { + const { logger, errors } = captureLogger(); + const extension = defineDoctorExtension({ + name: "fixture/contributed-mcp", + setup(api) { + api.registerRuntimeEvidenceContributor({ + name: "mcp", + contribute: () => ({ mcpServers: [{ name: "fixture", tools: stubTools }] }), + }); + }, + }); + await build({ + ...config(root, logger, { run: "build", mcp: [], extensions: [extension] }), + build: { write: false, lib: { entry: "entry.ts", formats: ["es"] } }, + }); + expect(doctorRuns).toHaveLength(1); + const result = await doctorRuns[0]!; + expect(readMcpServers(result.project.runtimeEvidence)).toMatchObject([{ name: "fixture" }]); + expect(errors).toEqual([]); + }); +}); + test("dev refreshes project findings as Extension MCP evidence appears and disappears", async () => { await withProject(async (root) => { const toggle = join(root, "toggle.ts");