@vitemcp/server 1.9.9 → 1.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2134,6 +2134,16 @@ Another way is to use the official [`MCP Inspector`](https://modelcontextprotoco
2134
2134
  npx @vitemcp/server inspect server.ts
2135
2135
  ```
2136
2136
 
2137
+ ### Validate with `vitemcp validate`
2138
+
2139
+ To check that a server file type-checks and loads:
2140
+
2141
+ ```bash
2142
+ npx @vitemcp/server validate server.ts
2143
+ ```
2144
+
2145
+ The file is loaded with [`tsx`](https://tsx.is) when your project has it installed, the way `vitemcp dev` runs it. Without tsx it is loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums; install tsx (`npm install --save-dev tsx`) to validate those files.
2146
+
2137
2147
  ## FAQ
2138
2148
 
2139
2149
  ### How to use with Claude Desktop?
@@ -55,6 +55,7 @@ var _crypto = require('crypto');
55
55
 
56
56
  var _fs = require('fs');
57
57
 
58
+ var _module = require('module');
58
59
 
59
60
  var _url = require('url');
60
61
  var STRUCTURE_CHECK_SCRIPT = `
@@ -95,8 +96,12 @@ var PROJECT_OVERRIDES = {
95
96
  incremental: false,
96
97
  isolatedDeclarations: false
97
98
  };
98
- var buildStructureCheckCommand = (file, execPath = process.execPath) => [
99
+ var buildStructureCheckCommand = (file, {
100
+ execPath = process.execPath,
101
+ tsxLoader
102
+ } = {}) => [
99
103
  execPath,
104
+ ...tsxLoader ? ["--disable-warning=DEP0205", "--import", tsxLoader] : [],
100
105
  "-e",
101
106
  STRUCTURE_CHECK_SCRIPT,
102
107
  _url.pathToFileURL.call(void 0, file).href
@@ -135,6 +140,22 @@ var findTsconfig = (dir) => {
135
140
  }
136
141
  };
137
142
  var formatCommandFailure = (result) => [result.stderr, result.stdout].map((output) => typeof output === "string" ? output.trim() : "").filter(Boolean).join("\n");
143
+ var missingTsxHint = (file, tsxLoader) => tsxLoader || !/\.[cm]?tsx?$/i.test(file) ? void 0 : "[ViteMCP] tsx is not installed in this project, so the file was loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums. Install tsx to validate the file the way `vitemcp dev` runs it: npm install --save-dev tsx";
144
+ var resolveTsxLoader = (file) => {
145
+ for (let current = _path.dirname.call(void 0, file); ; current = _path.dirname.call(void 0, current)) {
146
+ const manifest = _path.join.call(void 0, current, "node_modules", "tsx", "package.json");
147
+ if (_fs.existsSync.call(void 0, manifest)) {
148
+ try {
149
+ return _url.pathToFileURL.call(void 0, _module.createRequire.call(void 0, manifest).resolve("tsx")).href;
150
+ } catch (e) {
151
+ return void 0;
152
+ }
153
+ }
154
+ if (_path.dirname.call(void 0, current) === current) {
155
+ return void 0;
156
+ }
157
+ }
158
+ };
138
159
  var runTypeCheck = async (file, strict = false) => {
139
160
  const tsconfig = findTsconfig(_path.dirname.call(void 0, file));
140
161
  const config = _path.join.call(void 0,
@@ -297,7 +318,11 @@ await _yargs2.default.call(void 0, _helpers.hideBin.call(void 0, process.argv)).
297
318
  process.exit(1);
298
319
  }
299
320
  console.log("[ViteMCP] \u2713 TypeScript compilation successful");
300
- const [structureCommand, ...structureArgs] = buildStructureCheckCommand(filePath);
321
+ const tsxLoader = resolveTsxLoader(filePath);
322
+ const [structureCommand, ...structureArgs] = buildStructureCheckCommand(
323
+ filePath,
324
+ { tsxLoader }
325
+ );
301
326
  const structureCheck = await _execa.execa.call(void 0, structureCommand, structureArgs, {
302
327
  reject: false
303
328
  });
@@ -311,6 +336,10 @@ await _yargs2.default.call(void 0, _helpers.hideBin.call(void 0, process.argv)).
311
336
  "Make sure the file properly imports and uses ViteMCP"
312
337
  );
313
338
  }
339
+ const hint = missingTsxHint(filePath, tsxLoader);
340
+ if (hint) {
341
+ console.error(hint);
342
+ }
314
343
  process.exit(1);
315
344
  }
316
345
  console.log(
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/server/server/dist/bin/vitemcp.cjs","../../src/bin/vitemcp.ts","../../src/bin/devCommand.ts","../../src/b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AAAQ,YAAA;AACN,UAAA;AACF,QAAA;AAGF,QAAA;AACF,MAAA;AAEA,MAAA;AAAQ,QAAA;AAER,MAAA;AACF,IAAA;AACE,MAAA;AAAQ,QAAA;AACN,QAAA;AAEF,MAAA;AAEA,MAAA;AACF,IAAA;AACF,EAAA;AAGI","file":"/home/runner/work/server/server/dist/bin/vitemcp.cjs","sourcesContent":[null,"#!/usr/bin/env node\n\nimport { execa } from \"execa\";\nimport { mkdtemp, rm, writeFile } from \"fs/promises\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nimport { buildDevCommand, buildDevConfig } from \"./devCommand.js\";\nimport {\n buildStructureCheckCommand,\n formatCommandFailure,\n runTypeCheck,\n} from \"./validateCommand.js\";\n\nawait yargs(hideBin(process.argv))\n .scriptName(\"vitemcp\")\n .command(\n \"dev <file>\",\n \"Start a development server\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"args\", {\n describe:\n \"JSON arguments passed to the tool (requires --tool), e.g. '{\\\"a\\\":1}'\",\n type: \"string\",\n })\n\n .option(\"tool\", {\n alias: \"t\",\n describe:\n \"Call a tool non-interactively instead of launching the inspector\",\n type: \"string\",\n })\n\n .option(\"watch\", {\n alias: \"w\",\n default: false,\n describe: \"Watch for file changes and restart server\",\n type: \"boolean\",\n })\n\n .option(\"verbose\", {\n alias: \"v\",\n default: false,\n describe: \"Enable verbose logging\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n let configDir: string | undefined;\n\n try {\n if (argv.args !== undefined && !argv.tool) {\n console.error(\"[ViteMCP Error] --args requires --tool\");\n process.exitCode = 1;\n return;\n }\n\n if (argv.tool && argv.watch) {\n console.warn(\n \"[ViteMCP] --watch is ignored when calling a tool with --tool: the server runs for a single call.\",\n );\n }\n\n let configPath: string | undefined;\n\n if (argv.tool) {\n configDir = await mkdtemp(join(tmpdir(), \"vitemcp-dev-\"));\n configPath = join(configDir, \"mcp-cli.json\");\n await writeFile(configPath, buildDevConfig(argv.file), \"utf8\");\n }\n\n const [command, ...commandArgs] = buildDevCommand({\n configPath,\n file: argv.file,\n tool: argv.tool,\n toolArgs: argv.args,\n watch: argv.watch,\n });\n\n if (argv.verbose) {\n console.log(\n `[ViteMCP] Starting server: ${[command, ...commandArgs].join(\" \")}`,\n );\n console.log(`[ViteMCP] File: ${argv.file}`);\n console.log(\n `[ViteMCP] Watch mode: ${argv.watch ? \"enabled\" : \"disabled\"}`,\n );\n\n if (argv.tool) {\n console.log(`[ViteMCP] Tool: ${argv.tool}`);\n }\n }\n\n await execa(command, commandArgs, {\n stderr: \"inherit\",\n stdin: \"inherit\",\n stdout: \"inherit\",\n });\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to start development server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n if (argv.verbose && error instanceof Error && error.stack) {\n console.error(\"[ViteMCP Debug] Stack trace:\", error.stack);\n }\n\n // Not process.exit(): that would skip the `finally` block below and\n // leak the temporary config directory on every failed tool call.\n process.exitCode = 1;\n } finally {\n if (configDir) {\n await rm(configDir, { force: true, recursive: true });\n }\n }\n },\n )\n\n .command(\n \"inspect <file>\",\n \"Inspect a server file\",\n (yargs) => {\n return yargs.positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n });\n },\n\n async (argv) => {\n try {\n await execa({\n stderr: \"inherit\",\n stdout: \"inherit\",\n })`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to inspect server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .command(\n \"validate <file>\",\n \"Validate a ViteMCP server file for syntax and basic structure\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"strict\", {\n alias: \"s\",\n default: false,\n describe: \"Enable strict validation (type checking)\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n try {\n const { existsSync } = await import(\"fs\");\n const { resolve } = await import(\"path\");\n const filePath = resolve(argv.file);\n\n if (!existsSync(filePath)) {\n console.error(`[ViteMCP Error] File not found: ${filePath}`);\n process.exit(1);\n }\n\n console.log(`[ViteMCP] Validating server file: ${filePath}`);\n\n const typeCheck = await runTypeCheck(filePath, argv.strict);\n\n if (typeCheck.failed) {\n console.error(\"[ViteMCP] ✗ TypeScript compilation failed\");\n\n const diagnostics = formatCommandFailure(typeCheck);\n\n if (diagnostics) {\n console.error(diagnostics);\n }\n\n process.exit(1);\n }\n\n console.log(\"[ViteMCP] ✓ TypeScript compilation successful\");\n\n const [structureCommand, ...structureArgs] =\n buildStructureCheckCommand(filePath);\n const structureCheck = await execa(structureCommand, structureArgs, {\n reject: false,\n });\n\n if (structureCheck.failed) {\n // The child explains the failure on stderr, which execa captures.\n // Without replaying it the user only ever sees the generic hint, even\n // when their server file has an error they could act on.\n const reason = formatCommandFailure(structureCheck);\n\n if (reason) {\n console.error(reason);\n } else {\n console.error(\"[ViteMCP] ✗ Server structure validation failed\");\n console.error(\n \"Make sure the file properly imports and uses ViteMCP\",\n );\n }\n\n process.exit(1);\n }\n\n console.log(\n \"[ViteMCP] ✓ All validations passed! Server file looks good.\",\n );\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Validation failed:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .help()\n .parseAsync();\n","export type DevCommandOptions = {\n /**\n * Path to a temporary mcp-cli config file that registers the dev server.\n * Only used in non-interactive mode (when `tool` is set).\n */\n configPath?: string;\n /**\n * Path to the server file to run.\n */\n file: string;\n /**\n * Name of the tool to call non-interactively. When omitted, the dev\n * command launches the interactive mcp-cli inspector instead.\n */\n tool?: string;\n /**\n * JSON string of arguments forwarded to the tool via mcp-cli `--args`.\n * Only used in non-interactive mode.\n */\n toolArgs?: string;\n /**\n * Watch the file for changes and restart the server. Only used in\n * interactive mode; a non-interactive call runs the server once.\n */\n watch?: boolean;\n};\n\n/**\n * The server name registered in the generated mcp-cli config. mcp-cli\n * addresses non-interactive targets as `<server-name>:<tool>`.\n */\nexport const DEV_SERVER_NAME = \"dev\";\n\n/**\n * Build the JSON config that registers the dev server with mcp-cli so it can\n * be invoked non-interactively. mcp-cli's non-interactive mode resolves the\n * server by name from a config file's `mcpServers` map, so an inline command\n * cannot be passed directly alongside `call-tool`.\n *\n * The server is never started in watch mode here: a non-interactive call\n * connects, calls one tool, and exits, so there is nothing to restart into.\n */\nexport const buildDevConfig = (file: string): string =>\n JSON.stringify(\n {\n mcpServers: {\n [DEV_SERVER_NAME]: {\n args: [\"tsx\", file],\n command: \"npx\",\n },\n },\n },\n null,\n 2,\n );\n\n/**\n * Build the argv that the dev command runs.\n *\n * This is an argv array rather than a shell string so that nothing has to be\n * quoted: file paths, tool names and JSON `--args` are passed to the child\n * process verbatim. Quoting through a shell would be wrong on Windows, where\n * cmd.exe treats single quotes as literal characters rather than as quoting.\n *\n * - Without `tool`: launches the interactive @wong2/mcp-cli inspector\n * against an inline `npx tsx <file>` server (existing behaviour).\n * - With `tool`: runs @wong2/mcp-cli in non-interactive mode against a\n * generated config file, calling the named tool and forwarding `--args`.\n */\nexport const buildDevCommand = (\n options: DevCommandOptions,\n): [string, ...string[]] => {\n const { configPath, file, tool, toolArgs, watch = false } = options;\n\n if (tool) {\n if (!configPath) {\n throw new Error(\n \"configPath is required when calling a tool non-interactively\",\n );\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"-c\",\n configPath,\n \"call-tool\",\n `${DEV_SERVER_NAME}:${tool}`,\n ...(toolArgs === undefined ? [] : [\"--args\", toolArgs]),\n ];\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"npx\",\n \"tsx\",\n ...(watch ? [\"--watch\"] : []),\n file,\n ];\n};\n","import { randomUUID } from \"crypto\";\nimport { execa } from \"execa\";\nimport { existsSync } from \"fs\";\nimport { rm, writeFile } from \"fs/promises\";\nimport { dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * The script `vitemcp validate` runs to check that a server file loads.\n *\n * The file arrives as `process.argv[1]` rather than being spliced into this\n * source. Spliced into a string literal, a Windows path loses its backslashes\n * to the child's own parser (`C:\\Users\\dev\\server.ts` reaches the import as\n * `C:Usersdevserver.ts`), and a quote or `#` in any path breaks the import —\n * each reported to the user as a problem with their file.\n *\n * It exits as soon as the import settles, once its verdict is flushed. A\n * server file normally starts its transport on load, which would otherwise\n * keep this process, and the command waiting on it, alive forever.\n */\nexport const STRUCTURE_CHECK_SCRIPT = `\n(async () => {\n let failure;\n\n try {\n await import(\"@vitemcp/server\");\n await import(process.argv[1]);\n } catch (error) {\n failure = error instanceof Error ? error.message : String(error);\n }\n\n if (failure === undefined) {\n process.stdout.write(\n \"[ViteMCP] ✓ Server structure validation passed\\\\n\",\n () => process.exit(0),\n );\n } else {\n process.stderr.write(\n \"[ViteMCP] ✗ Server structure validation failed: \" + failure + \"\\\\n\",\n () => process.exit(1),\n );\n }\n})();\n`;\n\n/**\n * Compiler options for a file with no `tsconfig.json` above it. The compiler's\n * own defaults target ES5, which rejects top-level await and the `#private`\n * members in `@vitemcp/server`'s declarations, so no server file could pass.\n */\nconst STANDALONE_COMPILER_OPTIONS = {\n allowImportingTsExtensions: true,\n module: \"esnext\",\n moduleResolution: \"bundler\",\n skipLibCheck: true,\n target: \"es2022\",\n};\n\n/**\n * What the throwaway config overrides in the project's own. `composite`\n * demands that every file the server imports be listed as a root, and only the\n * server file is; `incremental` writes a `.tsbuildinfo` named after the\n * throwaway config into the project.\n *\n * `composite` also implies `declaration`, which `declarationMap`,\n * `emitDeclarationOnly` and `isolatedDeclarations` each require, so a composite\n * project may set them without it — and with `composite` off, its check failed\n * with TS5069. Nothing is emitted, so they are switched off as well.\n */\nconst PROJECT_OVERRIDES = {\n composite: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n incremental: false,\n isolatedDeclarations: false,\n};\n\n/**\n * Build the argv for the structure check.\n *\n * An argv array rather than a shell string, as in `buildDevCommand`, so nothing\n * has to be quoted. The file is converted to a `file:` URL here, so the child\n * imports it as given and never has to build the URL itself; and the child is\n * the Node binary running this CLI, so no PATH lookup is involved.\n */\nexport const buildStructureCheckCommand = (\n file: string,\n execPath: string = process.execPath,\n): [string, ...string[]] => [\n execPath,\n \"-e\",\n STRUCTURE_CHECK_SCRIPT,\n pathToFileURL(file).href,\n];\n\n/**\n * Build the argv for the type check. An argv array for the same reason as the\n * structure check: through a shell, a path containing a space reaches `tsc` as\n * several root files.\n */\nexport const buildTypeCheckCommand = (\n config: string,\n strict = false,\n): [string, ...string[]] => [\n \"npx\",\n \"tsc\",\n \"--noEmit\",\n \"--project\",\n config,\n ...(strict ? [\"--strict\"] : []),\n];\n\n/**\n * Build the throwaway config that type-checks one file.\n *\n * `tsc` ignores `tsconfig.json` whenever a file is named on its command line\n * and falls back to defaults no server file passes, so the file is named in a\n * config that extends the project's own instead. `include: []` keeps an\n * inherited `include` from pulling the rest of the project in.\n */\nexport const buildTypeCheckConfig = (file: string, tsconfig?: string): string =>\n JSON.stringify(\n tsconfig\n ? {\n compilerOptions: PROJECT_OVERRIDES,\n extends: tsconfig,\n files: [file],\n include: [],\n }\n : {\n compilerOptions: STANDALONE_COMPILER_OPTIONS,\n files: [file],\n include: [],\n },\n null,\n 2,\n );\n\n/**\n * The `tsconfig.json` that governs a file in `dir`: the nearest one at or above\n * it, which is also the one an editor checks the file against.\n */\nexport const findTsconfig = (dir: string): string | undefined => {\n for (let current = dir; ; current = dirname(current)) {\n const candidate = join(current, \"tsconfig.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * The output of a failed check, for replaying to the user.\n *\n * `tsc` writes its diagnostics to stdout, and only a failure to launch it\n * reaches stderr, so reading stderr alone reported every real type error with\n * no detail. The structure check explains itself on stderr.\n */\nexport const formatCommandFailure = (result: {\n stderr?: unknown;\n stdout?: unknown;\n}): string =>\n [result.stderr, result.stdout]\n .map((output) => (typeof output === \"string\" ? output.trim() : \"\"))\n .filter(Boolean)\n .join(\"\\n\");\n\n/**\n * Type-check `file` under the compiler options of the project it belongs to.\n *\n * The throwaway config is written beside the project's own rather than to the\n * OS temp directory, because the compiler resolves type packages — the `types`\n * option and every visible `@types` package — from the config's directory. It\n * is removed before this returns, so a caller may exit straight away.\n */\nexport const runTypeCheck = async (file: string, strict = false) => {\n const tsconfig = findTsconfig(dirname(file));\n const config = join(\n dirname(tsconfig ?? file),\n `tsconfig.vitemcp-validate-${randomUUID()}.json`,\n );\n\n await writeFile(config, buildTypeCheckConfig(file, tsconfig), {\n flag: \"wx\",\n });\n\n try {\n const [command, ...args] = buildTypeCheckCommand(config, strict);\n\n return await execa(command, args, { reject: false });\n } finally {\n await rm(config, { force: true });\n }\n};\n"]}
1
+ {"version":3,"sources":["/home/runner/work/server/server/dist/bin/vitemcp.cjs","../../src/bin/vitemcp.ts","../../src/bin/devCommand.ts","../../src/bin/validateCommand.ts"],"names":["yargs"],"mappings":"AAAA;AACA;AACA;ACAA,8BAAsB;AACtB,uCAAuC;AACvC,wBAAuB;AACvB,4BAAqB;AACrB,4EAAkB;AAClB,wCAAwB;ADExB;AACA;AEqBO,IAAM,gBAAA,EAAkB,KAAA;AAWxB,IAAM,eAAA,EAAiB,CAAC,IAAA,EAAA,GAC7B,IAAA,CAAK,SAAA;AAAA,EACH;AAAA,IACE,UAAA,EAAY;AAAA,MACV,CAAC,eAAe,CAAA,EAAG;AAAA,QACjB,IAAA,EAAM,CAAC,KAAA,EAAO,IAAI,CAAA;AAAA,QAClB,OAAA,EAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA;AAeK,IAAM,gBAAA,EAAkB,CAC7B,OAAA,EAAA,GAC0B;AAC1B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cjs","sourcesContent":[null,"#!/usr/bin/env node\n\nimport { execa } from \"execa\";\nimport { mkdtemp, rm, writeFile } from \"fs/promises\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nimport { buildDevCommand, buildDevConfig } from \"./devCommand.js\";\nimport {\n buildStructureCheckCommand,\n formatCommandFailure,\n missingTsxHint,\n resolveTsxLoader,\n runTypeCheck,\n} from \"./validateCommand.js\";\n\nawait yargs(hideBin(process.argv))\n .scriptName(\"vitemcp\")\n .command(\n \"dev <file>\",\n \"Start a development server\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"args\", {\n describe:\n \"JSON arguments passed to the tool (requires --tool), e.g. '{\\\"a\\\":1}'\",\n type: \"string\",\n })\n\n .option(\"tool\", {\n alias: \"t\",\n describe:\n \"Call a tool non-interactively instead of launching the inspector\",\n type: \"string\",\n })\n\n .option(\"watch\", {\n alias: \"w\",\n default: false,\n describe: \"Watch for file changes and restart server\",\n type: \"boolean\",\n })\n\n .option(\"verbose\", {\n alias: \"v\",\n default: false,\n describe: \"Enable verbose logging\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n let configDir: string | undefined;\n\n try {\n if (argv.args !== undefined && !argv.tool) {\n console.error(\"[ViteMCP Error] --args requires --tool\");\n process.exitCode = 1;\n return;\n }\n\n if (argv.tool && argv.watch) {\n console.warn(\n \"[ViteMCP] --watch is ignored when calling a tool with --tool: the server runs for a single call.\",\n );\n }\n\n let configPath: string | undefined;\n\n if (argv.tool) {\n configDir = await mkdtemp(join(tmpdir(), \"vitemcp-dev-\"));\n configPath = join(configDir, \"mcp-cli.json\");\n await writeFile(configPath, buildDevConfig(argv.file), \"utf8\");\n }\n\n const [command, ...commandArgs] = buildDevCommand({\n configPath,\n file: argv.file,\n tool: argv.tool,\n toolArgs: argv.args,\n watch: argv.watch,\n });\n\n if (argv.verbose) {\n console.log(\n `[ViteMCP] Starting server: ${[command, ...commandArgs].join(\" \")}`,\n );\n console.log(`[ViteMCP] File: ${argv.file}`);\n console.log(\n `[ViteMCP] Watch mode: ${argv.watch ? \"enabled\" : \"disabled\"}`,\n );\n\n if (argv.tool) {\n console.log(`[ViteMCP] Tool: ${argv.tool}`);\n }\n }\n\n await execa(command, commandArgs, {\n stderr: \"inherit\",\n stdin: \"inherit\",\n stdout: \"inherit\",\n });\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to start development server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n if (argv.verbose && error instanceof Error && error.stack) {\n console.error(\"[ViteMCP Debug] Stack trace:\", error.stack);\n }\n\n // Not process.exit(): that would skip the `finally` block below and\n // leak the temporary config directory on every failed tool call.\n process.exitCode = 1;\n } finally {\n if (configDir) {\n await rm(configDir, { force: true, recursive: true });\n }\n }\n },\n )\n\n .command(\n \"inspect <file>\",\n \"Inspect a server file\",\n (yargs) => {\n return yargs.positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n });\n },\n\n async (argv) => {\n try {\n await execa({\n stderr: \"inherit\",\n stdout: \"inherit\",\n })`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to inspect server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .command(\n \"validate <file>\",\n \"Validate a ViteMCP server file for syntax and basic structure\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"strict\", {\n alias: \"s\",\n default: false,\n describe: \"Enable strict validation (type checking)\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n try {\n const { existsSync } = await import(\"fs\");\n const { resolve } = await import(\"path\");\n const filePath = resolve(argv.file);\n\n if (!existsSync(filePath)) {\n console.error(`[ViteMCP Error] File not found: ${filePath}`);\n process.exit(1);\n }\n\n console.log(`[ViteMCP] Validating server file: ${filePath}`);\n\n const typeCheck = await runTypeCheck(filePath, argv.strict);\n\n if (typeCheck.failed) {\n console.error(\"[ViteMCP] ✗ TypeScript compilation failed\");\n\n const diagnostics = formatCommandFailure(typeCheck);\n\n if (diagnostics) {\n console.error(diagnostics);\n }\n\n process.exit(1);\n }\n\n console.log(\"[ViteMCP] ✓ TypeScript compilation successful\");\n\n const tsxLoader = resolveTsxLoader(filePath);\n const [structureCommand, ...structureArgs] = buildStructureCheckCommand(\n filePath,\n { tsxLoader },\n );\n const structureCheck = await execa(structureCommand, structureArgs, {\n reject: false,\n });\n\n if (structureCheck.failed) {\n // The child explains the failure on stderr, which execa captures.\n // Without replaying it the user only ever sees the generic hint, even\n // when their server file has an error they could act on.\n const reason = formatCommandFailure(structureCheck);\n\n if (reason) {\n console.error(reason);\n } else {\n console.error(\"[ViteMCP] ✗ Server structure validation failed\");\n console.error(\n \"Make sure the file properly imports and uses ViteMCP\",\n );\n }\n\n const hint = missingTsxHint(filePath, tsxLoader);\n\n if (hint) {\n console.error(hint);\n }\n\n process.exit(1);\n }\n\n console.log(\n \"[ViteMCP] ✓ All validations passed! Server file looks good.\",\n );\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Validation failed:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .help()\n .parseAsync();\n","export type DevCommandOptions = {\n /**\n * Path to a temporary mcp-cli config file that registers the dev server.\n * Only used in non-interactive mode (when `tool` is set).\n */\n configPath?: string;\n /**\n * Path to the server file to run.\n */\n file: string;\n /**\n * Name of the tool to call non-interactively. When omitted, the dev\n * command launches the interactive mcp-cli inspector instead.\n */\n tool?: string;\n /**\n * JSON string of arguments forwarded to the tool via mcp-cli `--args`.\n * Only used in non-interactive mode.\n */\n toolArgs?: string;\n /**\n * Watch the file for changes and restart the server. Only used in\n * interactive mode; a non-interactive call runs the server once.\n */\n watch?: boolean;\n};\n\n/**\n * The server name registered in the generated mcp-cli config. mcp-cli\n * addresses non-interactive targets as `<server-name>:<tool>`.\n */\nexport const DEV_SERVER_NAME = \"dev\";\n\n/**\n * Build the JSON config that registers the dev server with mcp-cli so it can\n * be invoked non-interactively. mcp-cli's non-interactive mode resolves the\n * server by name from a config file's `mcpServers` map, so an inline command\n * cannot be passed directly alongside `call-tool`.\n *\n * The server is never started in watch mode here: a non-interactive call\n * connects, calls one tool, and exits, so there is nothing to restart into.\n */\nexport const buildDevConfig = (file: string): string =>\n JSON.stringify(\n {\n mcpServers: {\n [DEV_SERVER_NAME]: {\n args: [\"tsx\", file],\n command: \"npx\",\n },\n },\n },\n null,\n 2,\n );\n\n/**\n * Build the argv that the dev command runs.\n *\n * This is an argv array rather than a shell string so that nothing has to be\n * quoted: file paths, tool names and JSON `--args` are passed to the child\n * process verbatim. Quoting through a shell would be wrong on Windows, where\n * cmd.exe treats single quotes as literal characters rather than as quoting.\n *\n * - Without `tool`: launches the interactive @wong2/mcp-cli inspector\n * against an inline `npx tsx <file>` server (existing behaviour).\n * - With `tool`: runs @wong2/mcp-cli in non-interactive mode against a\n * generated config file, calling the named tool and forwarding `--args`.\n */\nexport const buildDevCommand = (\n options: DevCommandOptions,\n): [string, ...string[]] => {\n const { configPath, file, tool, toolArgs, watch = false } = options;\n\n if (tool) {\n if (!configPath) {\n throw new Error(\n \"configPath is required when calling a tool non-interactively\",\n );\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"-c\",\n configPath,\n \"call-tool\",\n `${DEV_SERVER_NAME}:${tool}`,\n ...(toolArgs === undefined ? [] : [\"--args\", toolArgs]),\n ];\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"npx\",\n \"tsx\",\n ...(watch ? [\"--watch\"] : []),\n file,\n ];\n};\n","import { randomUUID } from \"crypto\";\nimport { execa } from \"execa\";\nimport { existsSync } from \"fs\";\nimport { rm, writeFile } from \"fs/promises\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * The script `vitemcp validate` runs to check that a server file loads.\n *\n * The file arrives as `process.argv[1]` rather than being spliced into this\n * source. Spliced into a string literal, a Windows path loses its backslashes\n * to the child's own parser (`C:\\Users\\dev\\server.ts` reaches the import as\n * `C:Usersdevserver.ts`), and a quote or `#` in any path breaks the import —\n * each reported to the user as a problem with their file.\n *\n * It exits as soon as the import settles, once its verdict is flushed. A\n * server file normally starts its transport on load, which would otherwise\n * keep this process, and the command waiting on it, alive forever.\n */\nexport const STRUCTURE_CHECK_SCRIPT = `\n(async () => {\n let failure;\n\n try {\n await import(\"@vitemcp/server\");\n await import(process.argv[1]);\n } catch (error) {\n failure = error instanceof Error ? error.message : String(error);\n }\n\n if (failure === undefined) {\n process.stdout.write(\n \"[ViteMCP] ✓ Server structure validation passed\\\\n\",\n () => process.exit(0),\n );\n } else {\n process.stderr.write(\n \"[ViteMCP] ✗ Server structure validation failed: \" + failure + \"\\\\n\",\n () => process.exit(1),\n );\n }\n})();\n`;\n\n/**\n * Compiler options for a file with no `tsconfig.json` above it. The compiler's\n * own defaults target ES5, which rejects top-level await and the `#private`\n * members in `@vitemcp/server`'s declarations, so no server file could pass.\n */\nconst STANDALONE_COMPILER_OPTIONS = {\n allowImportingTsExtensions: true,\n module: \"esnext\",\n moduleResolution: \"bundler\",\n skipLibCheck: true,\n target: \"es2022\",\n};\n\n/**\n * What the throwaway config overrides in the project's own. `composite`\n * demands that every file the server imports be listed as a root, and only the\n * server file is; `incremental` writes a `.tsbuildinfo` named after the\n * throwaway config into the project.\n *\n * `composite` also implies `declaration`, which `declarationMap`,\n * `emitDeclarationOnly` and `isolatedDeclarations` each require, so a composite\n * project may set them without it — and with `composite` off, its check failed\n * with TS5069. Nothing is emitted, so they are switched off as well.\n */\nconst PROJECT_OVERRIDES = {\n composite: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n incremental: false,\n isolatedDeclarations: false,\n};\n\n/**\n * Build the argv for the structure check.\n *\n * An argv array rather than a shell string, as in `buildDevCommand`, so nothing\n * has to be quoted. The file is converted to a `file:` URL here, so the child\n * imports it as given and never has to build the URL itself; and the child is\n * the Node binary running this CLI, so no PATH lookup is involved.\n *\n * Given the project's tsx loader (see `resolveTsxLoader`), the child imports\n * the file through it, so the file loads the way `vitemcp dev` runs it. tsx\n * registers itself with `module.register()`, which Node 26 deprecates\n * (DEP0205); that warning alone is switched off, because it would otherwise be\n * replayed with a failure as though the file had caused it.\n */\nexport const buildStructureCheckCommand = (\n file: string,\n {\n execPath = process.execPath,\n tsxLoader,\n }: { execPath?: string; tsxLoader?: string } = {},\n): [string, ...string[]] => [\n execPath,\n ...(tsxLoader ? [\"--disable-warning=DEP0205\", \"--import\", tsxLoader] : []),\n \"-e\",\n STRUCTURE_CHECK_SCRIPT,\n pathToFileURL(file).href,\n];\n\n/**\n * Build the argv for the type check. An argv array for the same reason as the\n * structure check: through a shell, a path containing a space reaches `tsc` as\n * several root files.\n */\nexport const buildTypeCheckCommand = (\n config: string,\n strict = false,\n): [string, ...string[]] => [\n \"npx\",\n \"tsc\",\n \"--noEmit\",\n \"--project\",\n config,\n ...(strict ? [\"--strict\"] : []),\n];\n\n/**\n * Build the throwaway config that type-checks one file.\n *\n * `tsc` ignores `tsconfig.json` whenever a file is named on its command line\n * and falls back to defaults no server file passes, so the file is named in a\n * config that extends the project's own instead. `include: []` keeps an\n * inherited `include` from pulling the rest of the project in.\n */\nexport const buildTypeCheckConfig = (file: string, tsconfig?: string): string =>\n JSON.stringify(\n tsconfig\n ? {\n compilerOptions: PROJECT_OVERRIDES,\n extends: tsconfig,\n files: [file],\n include: [],\n }\n : {\n compilerOptions: STANDALONE_COMPILER_OPTIONS,\n files: [file],\n include: [],\n },\n null,\n 2,\n );\n\n/**\n * The `tsconfig.json` that governs a file in `dir`: the nearest one at or above\n * it, which is also the one an editor checks the file against.\n */\nexport const findTsconfig = (dir: string): string | undefined => {\n for (let current = dir; ; current = dirname(current)) {\n const candidate = join(current, \"tsconfig.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * The output of a failed check, for replaying to the user.\n *\n * `tsc` writes its diagnostics to stdout, and only a failure to launch it\n * reaches stderr, so reading stderr alone reported every real type error with\n * no detail. The structure check explains itself on stderr.\n */\nexport const formatCommandFailure = (result: {\n stderr?: unknown;\n stdout?: unknown;\n}): string =>\n [result.stderr, result.stdout]\n .map((output) => (typeof output === \"string\" ? output.trim() : \"\"))\n .filter(Boolean)\n .join(\"\\n\");\n\n/**\n * What to add when the structure check fails without tsx. Plain Node rejects\n * TypeScript that tsx runs, so the failure may be the loader's rather than the\n * file's. Nothing for a JavaScript file, which loads the same either way.\n */\nexport const missingTsxHint = (\n file: string,\n tsxLoader: string | undefined,\n): string | undefined =>\n tsxLoader || !/\\.[cm]?tsx?$/i.test(file)\n ? undefined\n : \"[ViteMCP] tsx is not installed in this project, so the file was loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums. Install tsx to validate the file the way `vitemcp dev` runs it: npm install --save-dev tsx\";\n\n/**\n * The project's tsx loader, as a `file:` URL for `--import`, or `undefined`\n * when the project does not have tsx installed.\n *\n * `vitemcp dev` runs a server file with tsx, but plain Node only strips types:\n * it rejects a `.js` import of a `.ts` file, and syntax it would have to\n * transform, such as an enum. So without tsx, a file `dev` ran fine failed the\n * check.\n *\n * Looked up in the `node_modules` at or above the file, as an `import` from the\n * file would look, so it is the tsx of the project the file belongs to.\n * `require.resolve` alone also searches `NODE_PATH`, which can point outside\n * the project: pnpm's bin shims set it to a store. A URL, because `--import`\n * takes a specifier, which a Windows path is not.\n */\nexport const resolveTsxLoader = (file: string): string | undefined => {\n for (let current = dirname(file); ; current = dirname(current)) {\n const manifest = join(current, \"node_modules\", \"tsx\", \"package.json\");\n\n if (existsSync(manifest)) {\n try {\n return pathToFileURL(createRequire(manifest).resolve(\"tsx\")).href;\n } catch {\n // Installed, but without the loader `--import tsx` would load.\n return undefined;\n }\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * Type-check `file` under the compiler options of the project it belongs to.\n *\n * The throwaway config is written beside the project's own rather than to the\n * OS temp directory, because the compiler resolves type packages — the `types`\n * option and every visible `@types` package — from the config's directory. It\n * is removed before this returns, so a caller may exit straight away.\n */\nexport const runTypeCheck = async (file: string, strict = false) => {\n const tsconfig = findTsconfig(dirname(file));\n const config = join(\n dirname(tsconfig ?? file),\n `tsconfig.vitemcp-validate-${randomUUID()}.json`,\n );\n\n await writeFile(config, buildTypeCheckConfig(file, tsconfig), {\n flag: \"wx\",\n });\n\n try {\n const [command, ...args] = buildTypeCheckCommand(config, strict);\n\n return await execa(command, args, { reject: false });\n } finally {\n await rm(config, { force: true });\n }\n};\n"]}
@@ -55,6 +55,7 @@ import { randomUUID } from "crypto";
55
55
  import { execa } from "execa";
56
56
  import { existsSync } from "fs";
57
57
  import { rm, writeFile } from "fs/promises";
58
+ import { createRequire } from "module";
58
59
  import { dirname, join } from "path";
59
60
  import { pathToFileURL } from "url";
60
61
  var STRUCTURE_CHECK_SCRIPT = `
@@ -95,8 +96,12 @@ var PROJECT_OVERRIDES = {
95
96
  incremental: false,
96
97
  isolatedDeclarations: false
97
98
  };
98
- var buildStructureCheckCommand = (file, execPath = process.execPath) => [
99
+ var buildStructureCheckCommand = (file, {
100
+ execPath = process.execPath,
101
+ tsxLoader
102
+ } = {}) => [
99
103
  execPath,
104
+ ...tsxLoader ? ["--disable-warning=DEP0205", "--import", tsxLoader] : [],
100
105
  "-e",
101
106
  STRUCTURE_CHECK_SCRIPT,
102
107
  pathToFileURL(file).href
@@ -135,6 +140,22 @@ var findTsconfig = (dir) => {
135
140
  }
136
141
  };
137
142
  var formatCommandFailure = (result) => [result.stderr, result.stdout].map((output) => typeof output === "string" ? output.trim() : "").filter(Boolean).join("\n");
143
+ var missingTsxHint = (file, tsxLoader) => tsxLoader || !/\.[cm]?tsx?$/i.test(file) ? void 0 : "[ViteMCP] tsx is not installed in this project, so the file was loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums. Install tsx to validate the file the way `vitemcp dev` runs it: npm install --save-dev tsx";
144
+ var resolveTsxLoader = (file) => {
145
+ for (let current = dirname(file); ; current = dirname(current)) {
146
+ const manifest = join(current, "node_modules", "tsx", "package.json");
147
+ if (existsSync(manifest)) {
148
+ try {
149
+ return pathToFileURL(createRequire(manifest).resolve("tsx")).href;
150
+ } catch {
151
+ return void 0;
152
+ }
153
+ }
154
+ if (dirname(current) === current) {
155
+ return void 0;
156
+ }
157
+ }
158
+ };
138
159
  var runTypeCheck = async (file, strict = false) => {
139
160
  const tsconfig = findTsconfig(dirname(file));
140
161
  const config = join(
@@ -297,7 +318,11 @@ await yargs(hideBin(process.argv)).scriptName("vitemcp").command(
297
318
  process.exit(1);
298
319
  }
299
320
  console.log("[ViteMCP] \u2713 TypeScript compilation successful");
300
- const [structureCommand, ...structureArgs] = buildStructureCheckCommand(filePath);
321
+ const tsxLoader = resolveTsxLoader(filePath);
322
+ const [structureCommand, ...structureArgs] = buildStructureCheckCommand(
323
+ filePath,
324
+ { tsxLoader }
325
+ );
301
326
  const structureCheck = await execa2(structureCommand, structureArgs, {
302
327
  reject: false
303
328
  });
@@ -311,6 +336,10 @@ await yargs(hideBin(process.argv)).scriptName("vitemcp").command(
311
336
  "Make sure the file properly imports and uses ViteMCP"
312
337
  );
313
338
  }
339
+ const hint = missingTsxHint(filePath, tsxLoader);
340
+ if (hint) {
341
+ console.error(hint);
342
+ }
314
343
  process.exit(1);
315
344
  }
316
345
  console.log(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/vitemcp.ts","../../src/bin/devCommand.ts","../../src/bin/validateCommand.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { execa } from \"execa\";\nimport { mkdtemp, rm, writeFile } from \"fs/promises\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nimport { buildDevCommand, buildDevConfig } from \"./devCommand.js\";\nimport {\n buildStructureCheckCommand,\n formatCommandFailure,\n runTypeCheck,\n} from \"./validateCommand.js\";\n\nawait yargs(hideBin(process.argv))\n .scriptName(\"vitemcp\")\n .command(\n \"dev <file>\",\n \"Start a development server\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"args\", {\n describe:\n \"JSON arguments passed to the tool (requires --tool), e.g. '{\\\"a\\\":1}'\",\n type: \"string\",\n })\n\n .option(\"tool\", {\n alias: \"t\",\n describe:\n \"Call a tool non-interactively instead of launching the inspector\",\n type: \"string\",\n })\n\n .option(\"watch\", {\n alias: \"w\",\n default: false,\n describe: \"Watch for file changes and restart server\",\n type: \"boolean\",\n })\n\n .option(\"verbose\", {\n alias: \"v\",\n default: false,\n describe: \"Enable verbose logging\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n let configDir: string | undefined;\n\n try {\n if (argv.args !== undefined && !argv.tool) {\n console.error(\"[ViteMCP Error] --args requires --tool\");\n process.exitCode = 1;\n return;\n }\n\n if (argv.tool && argv.watch) {\n console.warn(\n \"[ViteMCP] --watch is ignored when calling a tool with --tool: the server runs for a single call.\",\n );\n }\n\n let configPath: string | undefined;\n\n if (argv.tool) {\n configDir = await mkdtemp(join(tmpdir(), \"vitemcp-dev-\"));\n configPath = join(configDir, \"mcp-cli.json\");\n await writeFile(configPath, buildDevConfig(argv.file), \"utf8\");\n }\n\n const [command, ...commandArgs] = buildDevCommand({\n configPath,\n file: argv.file,\n tool: argv.tool,\n toolArgs: argv.args,\n watch: argv.watch,\n });\n\n if (argv.verbose) {\n console.log(\n `[ViteMCP] Starting server: ${[command, ...commandArgs].join(\" \")}`,\n );\n console.log(`[ViteMCP] File: ${argv.file}`);\n console.log(\n `[ViteMCP] Watch mode: ${argv.watch ? \"enabled\" : \"disabled\"}`,\n );\n\n if (argv.tool) {\n console.log(`[ViteMCP] Tool: ${argv.tool}`);\n }\n }\n\n await execa(command, commandArgs, {\n stderr: \"inherit\",\n stdin: \"inherit\",\n stdout: \"inherit\",\n });\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to start development server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n if (argv.verbose && error instanceof Error && error.stack) {\n console.error(\"[ViteMCP Debug] Stack trace:\", error.stack);\n }\n\n // Not process.exit(): that would skip the `finally` block below and\n // leak the temporary config directory on every failed tool call.\n process.exitCode = 1;\n } finally {\n if (configDir) {\n await rm(configDir, { force: true, recursive: true });\n }\n }\n },\n )\n\n .command(\n \"inspect <file>\",\n \"Inspect a server file\",\n (yargs) => {\n return yargs.positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n });\n },\n\n async (argv) => {\n try {\n await execa({\n stderr: \"inherit\",\n stdout: \"inherit\",\n })`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to inspect server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .command(\n \"validate <file>\",\n \"Validate a ViteMCP server file for syntax and basic structure\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"strict\", {\n alias: \"s\",\n default: false,\n describe: \"Enable strict validation (type checking)\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n try {\n const { existsSync } = await import(\"fs\");\n const { resolve } = await import(\"path\");\n const filePath = resolve(argv.file);\n\n if (!existsSync(filePath)) {\n console.error(`[ViteMCP Error] File not found: ${filePath}`);\n process.exit(1);\n }\n\n console.log(`[ViteMCP] Validating server file: ${filePath}`);\n\n const typeCheck = await runTypeCheck(filePath, argv.strict);\n\n if (typeCheck.failed) {\n console.error(\"[ViteMCP] ✗ TypeScript compilation failed\");\n\n const diagnostics = formatCommandFailure(typeCheck);\n\n if (diagnostics) {\n console.error(diagnostics);\n }\n\n process.exit(1);\n }\n\n console.log(\"[ViteMCP] ✓ TypeScript compilation successful\");\n\n const [structureCommand, ...structureArgs] =\n buildStructureCheckCommand(filePath);\n const structureCheck = await execa(structureCommand, structureArgs, {\n reject: false,\n });\n\n if (structureCheck.failed) {\n // The child explains the failure on stderr, which execa captures.\n // Without replaying it the user only ever sees the generic hint, even\n // when their server file has an error they could act on.\n const reason = formatCommandFailure(structureCheck);\n\n if (reason) {\n console.error(reason);\n } else {\n console.error(\"[ViteMCP] ✗ Server structure validation failed\");\n console.error(\n \"Make sure the file properly imports and uses ViteMCP\",\n );\n }\n\n process.exit(1);\n }\n\n console.log(\n \"[ViteMCP] ✓ All validations passed! Server file looks good.\",\n );\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Validation failed:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .help()\n .parseAsync();\n","export type DevCommandOptions = {\n /**\n * Path to a temporary mcp-cli config file that registers the dev server.\n * Only used in non-interactive mode (when `tool` is set).\n */\n configPath?: string;\n /**\n * Path to the server file to run.\n */\n file: string;\n /**\n * Name of the tool to call non-interactively. When omitted, the dev\n * command launches the interactive mcp-cli inspector instead.\n */\n tool?: string;\n /**\n * JSON string of arguments forwarded to the tool via mcp-cli `--args`.\n * Only used in non-interactive mode.\n */\n toolArgs?: string;\n /**\n * Watch the file for changes and restart the server. Only used in\n * interactive mode; a non-interactive call runs the server once.\n */\n watch?: boolean;\n};\n\n/**\n * The server name registered in the generated mcp-cli config. mcp-cli\n * addresses non-interactive targets as `<server-name>:<tool>`.\n */\nexport const DEV_SERVER_NAME = \"dev\";\n\n/**\n * Build the JSON config that registers the dev server with mcp-cli so it can\n * be invoked non-interactively. mcp-cli's non-interactive mode resolves the\n * server by name from a config file's `mcpServers` map, so an inline command\n * cannot be passed directly alongside `call-tool`.\n *\n * The server is never started in watch mode here: a non-interactive call\n * connects, calls one tool, and exits, so there is nothing to restart into.\n */\nexport const buildDevConfig = (file: string): string =>\n JSON.stringify(\n {\n mcpServers: {\n [DEV_SERVER_NAME]: {\n args: [\"tsx\", file],\n command: \"npx\",\n },\n },\n },\n null,\n 2,\n );\n\n/**\n * Build the argv that the dev command runs.\n *\n * This is an argv array rather than a shell string so that nothing has to be\n * quoted: file paths, tool names and JSON `--args` are passed to the child\n * process verbatim. Quoting through a shell would be wrong on Windows, where\n * cmd.exe treats single quotes as literal characters rather than as quoting.\n *\n * - Without `tool`: launches the interactive @wong2/mcp-cli inspector\n * against an inline `npx tsx <file>` server (existing behaviour).\n * - With `tool`: runs @wong2/mcp-cli in non-interactive mode against a\n * generated config file, calling the named tool and forwarding `--args`.\n */\nexport const buildDevCommand = (\n options: DevCommandOptions,\n): [string, ...string[]] => {\n const { configPath, file, tool, toolArgs, watch = false } = options;\n\n if (tool) {\n if (!configPath) {\n throw new Error(\n \"configPath is required when calling a tool non-interactively\",\n );\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"-c\",\n configPath,\n \"call-tool\",\n `${DEV_SERVER_NAME}:${tool}`,\n ...(toolArgs === undefined ? [] : [\"--args\", toolArgs]),\n ];\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"npx\",\n \"tsx\",\n ...(watch ? [\"--watch\"] : []),\n file,\n ];\n};\n","import { randomUUID } from \"crypto\";\nimport { execa } from \"execa\";\nimport { existsSync } from \"fs\";\nimport { rm, writeFile } from \"fs/promises\";\nimport { dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * The script `vitemcp validate` runs to check that a server file loads.\n *\n * The file arrives as `process.argv[1]` rather than being spliced into this\n * source. Spliced into a string literal, a Windows path loses its backslashes\n * to the child's own parser (`C:\\Users\\dev\\server.ts` reaches the import as\n * `C:Usersdevserver.ts`), and a quote or `#` in any path breaks the import —\n * each reported to the user as a problem with their file.\n *\n * It exits as soon as the import settles, once its verdict is flushed. A\n * server file normally starts its transport on load, which would otherwise\n * keep this process, and the command waiting on it, alive forever.\n */\nexport const STRUCTURE_CHECK_SCRIPT = `\n(async () => {\n let failure;\n\n try {\n await import(\"@vitemcp/server\");\n await import(process.argv[1]);\n } catch (error) {\n failure = error instanceof Error ? error.message : String(error);\n }\n\n if (failure === undefined) {\n process.stdout.write(\n \"[ViteMCP] ✓ Server structure validation passed\\\\n\",\n () => process.exit(0),\n );\n } else {\n process.stderr.write(\n \"[ViteMCP] ✗ Server structure validation failed: \" + failure + \"\\\\n\",\n () => process.exit(1),\n );\n }\n})();\n`;\n\n/**\n * Compiler options for a file with no `tsconfig.json` above it. The compiler's\n * own defaults target ES5, which rejects top-level await and the `#private`\n * members in `@vitemcp/server`'s declarations, so no server file could pass.\n */\nconst STANDALONE_COMPILER_OPTIONS = {\n allowImportingTsExtensions: true,\n module: \"esnext\",\n moduleResolution: \"bundler\",\n skipLibCheck: true,\n target: \"es2022\",\n};\n\n/**\n * What the throwaway config overrides in the project's own. `composite`\n * demands that every file the server imports be listed as a root, and only the\n * server file is; `incremental` writes a `.tsbuildinfo` named after the\n * throwaway config into the project.\n *\n * `composite` also implies `declaration`, which `declarationMap`,\n * `emitDeclarationOnly` and `isolatedDeclarations` each require, so a composite\n * project may set them without it — and with `composite` off, its check failed\n * with TS5069. Nothing is emitted, so they are switched off as well.\n */\nconst PROJECT_OVERRIDES = {\n composite: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n incremental: false,\n isolatedDeclarations: false,\n};\n\n/**\n * Build the argv for the structure check.\n *\n * An argv array rather than a shell string, as in `buildDevCommand`, so nothing\n * has to be quoted. The file is converted to a `file:` URL here, so the child\n * imports it as given and never has to build the URL itself; and the child is\n * the Node binary running this CLI, so no PATH lookup is involved.\n */\nexport const buildStructureCheckCommand = (\n file: string,\n execPath: string = process.execPath,\n): [string, ...string[]] => [\n execPath,\n \"-e\",\n STRUCTURE_CHECK_SCRIPT,\n pathToFileURL(file).href,\n];\n\n/**\n * Build the argv for the type check. An argv array for the same reason as the\n * structure check: through a shell, a path containing a space reaches `tsc` as\n * several root files.\n */\nexport const buildTypeCheckCommand = (\n config: string,\n strict = false,\n): [string, ...string[]] => [\n \"npx\",\n \"tsc\",\n \"--noEmit\",\n \"--project\",\n config,\n ...(strict ? [\"--strict\"] : []),\n];\n\n/**\n * Build the throwaway config that type-checks one file.\n *\n * `tsc` ignores `tsconfig.json` whenever a file is named on its command line\n * and falls back to defaults no server file passes, so the file is named in a\n * config that extends the project's own instead. `include: []` keeps an\n * inherited `include` from pulling the rest of the project in.\n */\nexport const buildTypeCheckConfig = (file: string, tsconfig?: string): string =>\n JSON.stringify(\n tsconfig\n ? {\n compilerOptions: PROJECT_OVERRIDES,\n extends: tsconfig,\n files: [file],\n include: [],\n }\n : {\n compilerOptions: STANDALONE_COMPILER_OPTIONS,\n files: [file],\n include: [],\n },\n null,\n 2,\n );\n\n/**\n * The `tsconfig.json` that governs a file in `dir`: the nearest one at or above\n * it, which is also the one an editor checks the file against.\n */\nexport const findTsconfig = (dir: string): string | undefined => {\n for (let current = dir; ; current = dirname(current)) {\n const candidate = join(current, \"tsconfig.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * The output of a failed check, for replaying to the user.\n *\n * `tsc` writes its diagnostics to stdout, and only a failure to launch it\n * reaches stderr, so reading stderr alone reported every real type error with\n * no detail. The structure check explains itself on stderr.\n */\nexport const formatCommandFailure = (result: {\n stderr?: unknown;\n stdout?: unknown;\n}): string =>\n [result.stderr, result.stdout]\n .map((output) => (typeof output === \"string\" ? output.trim() : \"\"))\n .filter(Boolean)\n .join(\"\\n\");\n\n/**\n * Type-check `file` under the compiler options of the project it belongs to.\n *\n * The throwaway config is written beside the project's own rather than to the\n * OS temp directory, because the compiler resolves type packages — the `types`\n * option and every visible `@types` package — from the config's directory. It\n * is removed before this returns, so a caller may exit straight away.\n */\nexport const runTypeCheck = async (file: string, strict = false) => {\n const tsconfig = findTsconfig(dirname(file));\n const config = join(\n dirname(tsconfig ?? file),\n `tsconfig.vitemcp-validate-${randomUUID()}.json`,\n );\n\n await writeFile(config, buildTypeCheckConfig(file, tsconfig), {\n flag: \"wx\",\n });\n\n try {\n const [command, ...args] = buildTypeCheckCommand(config, strict);\n\n return await execa(command, args, { reject: false });\n } finally {\n await rm(config, { force: true });\n }\n};\n"],"mappings":";;;AAEA,SAAS,SAAAA,cAAa;AACtB,SAAS,SAAS,MAAAC,KAAI,aAAAC,kBAAiB;AACvC,SAAS,cAAc;AACvB,SAAS,QAAAC,aAAY;AACrB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACwBjB,IAAM,kBAAkB;AAWxB,IAAM,iBAAiB,CAAC,SAC7B,KAAK;AAAA,EACH;AAAA,IACE,YAAY;AAAA,MACV,CAAC,eAAe,GAAG;AAAA,QACjB,MAAM,CAAC,OAAO,IAAI;AAAA,QAClB,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;AAeK,IAAM,kBAAkB,CAC7B,YAC0B;AAC1B,QAAM,EAAE,YAAY,MAAM,MAAM,UAAU,QAAQ,MAAM,IAAI;AAE5D,MAAI,MAAM;AACR,QAAI,CAAC,YAAY;AACf,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG,eAAe,IAAI,IAAI;AAAA,MAC1B,GAAI,aAAa,SAAY,CAAC,IAAI,CAAC,UAAU,QAAQ;AAAA,IACvD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,QAAQ,CAAC,SAAS,IAAI,CAAC;AAAA,IAC3B;AAAA,EACF;AACF;;;ACpGA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,IAAI,iBAAiB;AAC9B,SAAS,SA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C,QAAQ,EAAE;AAE3D,YAAM,YAAY,MAAM,aAAa,UAAU,KAAK,MAAM;AAE1D,UAAI,UAAU,QAAQ;AACpB,gBAAQ,MAAM,gDAA2C;AAEzD,cAAM,cAAc,qBAAqB,SAAS;AAElD,YAAI,aAAa;AACf,kBAAQ,MAAM,WAAW;AAAA,QAC3B;AAEA,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAEA,cAAQ,IAAI,oDAA+C;AAE3D,YAAM,CAAC,kBAAkB,GAAG,aAAa,IACvC,2BAA2B,QAAQ;AACrC,YAAM,iBAAiB,MAAMF,OAAM,kBAAkB,eAAe;AAAA,QAClE,QAAQ;AAAA,MACV,CAAC;AAED,UAAI,eAAe,QAAQ;AAIzB,cAAM,SAAS,qBAAqB,cAAc;AAElD,YAAI,QAAQ;AACV,kBAAQ,MAAM,MAAM;AAAA,QACtB,OAAO;AACL,kBAAQ,MAAM,qDAAgD;AAC9D,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAEA,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAEA,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ;AAAA,QACN;AAAA,QACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MACvD;AAEA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF,EAEC,KAAK,EACL,WAAW;","names":["execa","rm","writeFile","join","yargs","join","writeFile","execa","rm","existsSync"]}
1
+ {"version":3,"sources":["../../src/bin/vitemcp.ts","../../src/bin/devCommand.ts","../../src/bin/validateCommand.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { execa } from \"execa\";\nimport { mkdtemp, rm, writeFile } from \"fs/promises\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nimport { buildDevCommand, buildDevConfig } from \"./devCommand.js\";\nimport {\n buildStructureCheckCommand,\n formatCommandFailure,\n missingTsxHint,\n resolveTsxLoader,\n runTypeCheck,\n} from \"./validateCommand.js\";\n\nawait yargs(hideBin(process.argv))\n .scriptName(\"vitemcp\")\n .command(\n \"dev <file>\",\n \"Start a development server\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"args\", {\n describe:\n \"JSON arguments passed to the tool (requires --tool), e.g. '{\\\"a\\\":1}'\",\n type: \"string\",\n })\n\n .option(\"tool\", {\n alias: \"t\",\n describe:\n \"Call a tool non-interactively instead of launching the inspector\",\n type: \"string\",\n })\n\n .option(\"watch\", {\n alias: \"w\",\n default: false,\n describe: \"Watch for file changes and restart server\",\n type: \"boolean\",\n })\n\n .option(\"verbose\", {\n alias: \"v\",\n default: false,\n describe: \"Enable verbose logging\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n let configDir: string | undefined;\n\n try {\n if (argv.args !== undefined && !argv.tool) {\n console.error(\"[ViteMCP Error] --args requires --tool\");\n process.exitCode = 1;\n return;\n }\n\n if (argv.tool && argv.watch) {\n console.warn(\n \"[ViteMCP] --watch is ignored when calling a tool with --tool: the server runs for a single call.\",\n );\n }\n\n let configPath: string | undefined;\n\n if (argv.tool) {\n configDir = await mkdtemp(join(tmpdir(), \"vitemcp-dev-\"));\n configPath = join(configDir, \"mcp-cli.json\");\n await writeFile(configPath, buildDevConfig(argv.file), \"utf8\");\n }\n\n const [command, ...commandArgs] = buildDevCommand({\n configPath,\n file: argv.file,\n tool: argv.tool,\n toolArgs: argv.args,\n watch: argv.watch,\n });\n\n if (argv.verbose) {\n console.log(\n `[ViteMCP] Starting server: ${[command, ...commandArgs].join(\" \")}`,\n );\n console.log(`[ViteMCP] File: ${argv.file}`);\n console.log(\n `[ViteMCP] Watch mode: ${argv.watch ? \"enabled\" : \"disabled\"}`,\n );\n\n if (argv.tool) {\n console.log(`[ViteMCP] Tool: ${argv.tool}`);\n }\n }\n\n await execa(command, commandArgs, {\n stderr: \"inherit\",\n stdin: \"inherit\",\n stdout: \"inherit\",\n });\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to start development server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n if (argv.verbose && error instanceof Error && error.stack) {\n console.error(\"[ViteMCP Debug] Stack trace:\", error.stack);\n }\n\n // Not process.exit(): that would skip the `finally` block below and\n // leak the temporary config directory on every failed tool call.\n process.exitCode = 1;\n } finally {\n if (configDir) {\n await rm(configDir, { force: true, recursive: true });\n }\n }\n },\n )\n\n .command(\n \"inspect <file>\",\n \"Inspect a server file\",\n (yargs) => {\n return yargs.positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n });\n },\n\n async (argv) => {\n try {\n await execa({\n stderr: \"inherit\",\n stdout: \"inherit\",\n })`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to inspect server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .command(\n \"validate <file>\",\n \"Validate a ViteMCP server file for syntax and basic structure\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"strict\", {\n alias: \"s\",\n default: false,\n describe: \"Enable strict validation (type checking)\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n try {\n const { existsSync } = await import(\"fs\");\n const { resolve } = await import(\"path\");\n const filePath = resolve(argv.file);\n\n if (!existsSync(filePath)) {\n console.error(`[ViteMCP Error] File not found: ${filePath}`);\n process.exit(1);\n }\n\n console.log(`[ViteMCP] Validating server file: ${filePath}`);\n\n const typeCheck = await runTypeCheck(filePath, argv.strict);\n\n if (typeCheck.failed) {\n console.error(\"[ViteMCP] ✗ TypeScript compilation failed\");\n\n const diagnostics = formatCommandFailure(typeCheck);\n\n if (diagnostics) {\n console.error(diagnostics);\n }\n\n process.exit(1);\n }\n\n console.log(\"[ViteMCP] ✓ TypeScript compilation successful\");\n\n const tsxLoader = resolveTsxLoader(filePath);\n const [structureCommand, ...structureArgs] = buildStructureCheckCommand(\n filePath,\n { tsxLoader },\n );\n const structureCheck = await execa(structureCommand, structureArgs, {\n reject: false,\n });\n\n if (structureCheck.failed) {\n // The child explains the failure on stderr, which execa captures.\n // Without replaying it the user only ever sees the generic hint, even\n // when their server file has an error they could act on.\n const reason = formatCommandFailure(structureCheck);\n\n if (reason) {\n console.error(reason);\n } else {\n console.error(\"[ViteMCP] ✗ Server structure validation failed\");\n console.error(\n \"Make sure the file properly imports and uses ViteMCP\",\n );\n }\n\n const hint = missingTsxHint(filePath, tsxLoader);\n\n if (hint) {\n console.error(hint);\n }\n\n process.exit(1);\n }\n\n console.log(\n \"[ViteMCP] ✓ All validations passed! Server file looks good.\",\n );\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Validation failed:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .help()\n .parseAsync();\n","export type DevCommandOptions = {\n /**\n * Path to a temporary mcp-cli config file that registers the dev server.\n * Only used in non-interactive mode (when `tool` is set).\n */\n configPath?: string;\n /**\n * Path to the server file to run.\n */\n file: string;\n /**\n * Name of the tool to call non-interactively. When omitted, the dev\n * command launches the interactive mcp-cli inspector instead.\n */\n tool?: string;\n /**\n * JSON string of arguments forwarded to the tool via mcp-cli `--args`.\n * Only used in non-interactive mode.\n */\n toolArgs?: string;\n /**\n * Watch the file for changes and restart the server. Only used in\n * interactive mode; a non-interactive call runs the server once.\n */\n watch?: boolean;\n};\n\n/**\n * The server name registered in the generated mcp-cli config. mcp-cli\n * addresses non-interactive targets as `<server-name>:<tool>`.\n */\nexport const DEV_SERVER_NAME = \"dev\";\n\n/**\n * Build the JSON config that registers the dev server with mcp-cli so it can\n * be invoked non-interactively. mcp-cli's non-interactive mode resolves the\n * server by name from a config file's `mcpServers` map, so an inline command\n * cannot be passed directly alongside `call-tool`.\n *\n * The server is never started in watch mode here: a non-interactive call\n * connects, calls one tool, and exits, so there is nothing to restart into.\n */\nexport const buildDevConfig = (file: string): string =>\n JSON.stringify(\n {\n mcpServers: {\n [DEV_SERVER_NAME]: {\n args: [\"tsx\", file],\n command: \"npx\",\n },\n },\n },\n null,\n 2,\n );\n\n/**\n * Build the argv that the dev command runs.\n *\n * This is an argv array rather than a shell string so that nothing has to be\n * quoted: file paths, tool names and JSON `--args` are passed to the child\n * process verbatim. Quoting through a shell would be wrong on Windows, where\n * cmd.exe treats single quotes as literal characters rather than as quoting.\n *\n * - Without `tool`: launches the interactive @wong2/mcp-cli inspector\n * against an inline `npx tsx <file>` server (existing behaviour).\n * - With `tool`: runs @wong2/mcp-cli in non-interactive mode against a\n * generated config file, calling the named tool and forwarding `--args`.\n */\nexport const buildDevCommand = (\n options: DevCommandOptions,\n): [string, ...string[]] => {\n const { configPath, file, tool, toolArgs, watch = false } = options;\n\n if (tool) {\n if (!configPath) {\n throw new Error(\n \"configPath is required when calling a tool non-interactively\",\n );\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"-c\",\n configPath,\n \"call-tool\",\n `${DEV_SERVER_NAME}:${tool}`,\n ...(toolArgs === undefined ? [] : [\"--args\", toolArgs]),\n ];\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"npx\",\n \"tsx\",\n ...(watch ? [\"--watch\"] : []),\n file,\n ];\n};\n","import { randomUUID } from \"crypto\";\nimport { execa } from \"execa\";\nimport { existsSync } from \"fs\";\nimport { rm, writeFile } from \"fs/promises\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * The script `vitemcp validate` runs to check that a server file loads.\n *\n * The file arrives as `process.argv[1]` rather than being spliced into this\n * source. Spliced into a string literal, a Windows path loses its backslashes\n * to the child's own parser (`C:\\Users\\dev\\server.ts` reaches the import as\n * `C:Usersdevserver.ts`), and a quote or `#` in any path breaks the import —\n * each reported to the user as a problem with their file.\n *\n * It exits as soon as the import settles, once its verdict is flushed. A\n * server file normally starts its transport on load, which would otherwise\n * keep this process, and the command waiting on it, alive forever.\n */\nexport const STRUCTURE_CHECK_SCRIPT = `\n(async () => {\n let failure;\n\n try {\n await import(\"@vitemcp/server\");\n await import(process.argv[1]);\n } catch (error) {\n failure = error instanceof Error ? error.message : String(error);\n }\n\n if (failure === undefined) {\n process.stdout.write(\n \"[ViteMCP] ✓ Server structure validation passed\\\\n\",\n () => process.exit(0),\n );\n } else {\n process.stderr.write(\n \"[ViteMCP] ✗ Server structure validation failed: \" + failure + \"\\\\n\",\n () => process.exit(1),\n );\n }\n})();\n`;\n\n/**\n * Compiler options for a file with no `tsconfig.json` above it. The compiler's\n * own defaults target ES5, which rejects top-level await and the `#private`\n * members in `@vitemcp/server`'s declarations, so no server file could pass.\n */\nconst STANDALONE_COMPILER_OPTIONS = {\n allowImportingTsExtensions: true,\n module: \"esnext\",\n moduleResolution: \"bundler\",\n skipLibCheck: true,\n target: \"es2022\",\n};\n\n/**\n * What the throwaway config overrides in the project's own. `composite`\n * demands that every file the server imports be listed as a root, and only the\n * server file is; `incremental` writes a `.tsbuildinfo` named after the\n * throwaway config into the project.\n *\n * `composite` also implies `declaration`, which `declarationMap`,\n * `emitDeclarationOnly` and `isolatedDeclarations` each require, so a composite\n * project may set them without it — and with `composite` off, its check failed\n * with TS5069. Nothing is emitted, so they are switched off as well.\n */\nconst PROJECT_OVERRIDES = {\n composite: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n incremental: false,\n isolatedDeclarations: false,\n};\n\n/**\n * Build the argv for the structure check.\n *\n * An argv array rather than a shell string, as in `buildDevCommand`, so nothing\n * has to be quoted. The file is converted to a `file:` URL here, so the child\n * imports it as given and never has to build the URL itself; and the child is\n * the Node binary running this CLI, so no PATH lookup is involved.\n *\n * Given the project's tsx loader (see `resolveTsxLoader`), the child imports\n * the file through it, so the file loads the way `vitemcp dev` runs it. tsx\n * registers itself with `module.register()`, which Node 26 deprecates\n * (DEP0205); that warning alone is switched off, because it would otherwise be\n * replayed with a failure as though the file had caused it.\n */\nexport const buildStructureCheckCommand = (\n file: string,\n {\n execPath = process.execPath,\n tsxLoader,\n }: { execPath?: string; tsxLoader?: string } = {},\n): [string, ...string[]] => [\n execPath,\n ...(tsxLoader ? [\"--disable-warning=DEP0205\", \"--import\", tsxLoader] : []),\n \"-e\",\n STRUCTURE_CHECK_SCRIPT,\n pathToFileURL(file).href,\n];\n\n/**\n * Build the argv for the type check. An argv array for the same reason as the\n * structure check: through a shell, a path containing a space reaches `tsc` as\n * several root files.\n */\nexport const buildTypeCheckCommand = (\n config: string,\n strict = false,\n): [string, ...string[]] => [\n \"npx\",\n \"tsc\",\n \"--noEmit\",\n \"--project\",\n config,\n ...(strict ? [\"--strict\"] : []),\n];\n\n/**\n * Build the throwaway config that type-checks one file.\n *\n * `tsc` ignores `tsconfig.json` whenever a file is named on its command line\n * and falls back to defaults no server file passes, so the file is named in a\n * config that extends the project's own instead. `include: []` keeps an\n * inherited `include` from pulling the rest of the project in.\n */\nexport const buildTypeCheckConfig = (file: string, tsconfig?: string): string =>\n JSON.stringify(\n tsconfig\n ? {\n compilerOptions: PROJECT_OVERRIDES,\n extends: tsconfig,\n files: [file],\n include: [],\n }\n : {\n compilerOptions: STANDALONE_COMPILER_OPTIONS,\n files: [file],\n include: [],\n },\n null,\n 2,\n );\n\n/**\n * The `tsconfig.json` that governs a file in `dir`: the nearest one at or above\n * it, which is also the one an editor checks the file against.\n */\nexport const findTsconfig = (dir: string): string | undefined => {\n for (let current = dir; ; current = dirname(current)) {\n const candidate = join(current, \"tsconfig.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * The output of a failed check, for replaying to the user.\n *\n * `tsc` writes its diagnostics to stdout, and only a failure to launch it\n * reaches stderr, so reading stderr alone reported every real type error with\n * no detail. The structure check explains itself on stderr.\n */\nexport const formatCommandFailure = (result: {\n stderr?: unknown;\n stdout?: unknown;\n}): string =>\n [result.stderr, result.stdout]\n .map((output) => (typeof output === \"string\" ? output.trim() : \"\"))\n .filter(Boolean)\n .join(\"\\n\");\n\n/**\n * What to add when the structure check fails without tsx. Plain Node rejects\n * TypeScript that tsx runs, so the failure may be the loader's rather than the\n * file's. Nothing for a JavaScript file, which loads the same either way.\n */\nexport const missingTsxHint = (\n file: string,\n tsxLoader: string | undefined,\n): string | undefined =>\n tsxLoader || !/\\.[cm]?tsx?$/i.test(file)\n ? undefined\n : \"[ViteMCP] tsx is not installed in this project, so the file was loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums. Install tsx to validate the file the way `vitemcp dev` runs it: npm install --save-dev tsx\";\n\n/**\n * The project's tsx loader, as a `file:` URL for `--import`, or `undefined`\n * when the project does not have tsx installed.\n *\n * `vitemcp dev` runs a server file with tsx, but plain Node only strips types:\n * it rejects a `.js` import of a `.ts` file, and syntax it would have to\n * transform, such as an enum. So without tsx, a file `dev` ran fine failed the\n * check.\n *\n * Looked up in the `node_modules` at or above the file, as an `import` from the\n * file would look, so it is the tsx of the project the file belongs to.\n * `require.resolve` alone also searches `NODE_PATH`, which can point outside\n * the project: pnpm's bin shims set it to a store. A URL, because `--import`\n * takes a specifier, which a Windows path is not.\n */\nexport const resolveTsxLoader = (file: string): string | undefined => {\n for (let current = dirname(file); ; current = dirname(current)) {\n const manifest = join(current, \"node_modules\", \"tsx\", \"package.json\");\n\n if (existsSync(manifest)) {\n try {\n return pathToFileURL(createRequire(manifest).resolve(\"tsx\")).href;\n } catch {\n // Installed, but without the loader `--import tsx` would load.\n return undefined;\n }\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * Type-check `file` under the compiler options of the project it belongs to.\n *\n * The throwaway config is written beside the project's own rather than to the\n * OS temp directory, because the compiler resolves type packages — the `types`\n * option and every visible `@types` package — from the config's directory. It\n * is removed before this returns, so a caller may exit straight away.\n */\nexport const runTypeCheck = async (file: string, strict = false) => {\n const tsconfig = findTsconfig(dirname(file));\n const config = join(\n dirname(tsconfig ?? file),\n `tsconfig.vitemcp-validate-${randomUUID()}.json`,\n );\n\n await writeFile(config, buildTypeCheckConfig(file, tsconfig), {\n flag: \"wx\",\n });\n\n try {\n const [command, ...args] = buildTypeCheckCommand(config, strict);\n\n return await execa(command, args, { reject: false });\n } finally {\n await rm(config, { force: true });\n }\n};\n"],"mappings":";;;AAEA,SAAS,SAAAA,cAAa;AACtB,SAAS,SAAS,MAAAC,KAAI,aAAAC,kBAAiB;AACvC,SAAS,cAAc;AACvB,SAAS,QAAAC,aAAY;AACrB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACwBjB,IAAM,kBAAkB;AAWxB,IAAM,iBAAiB,CAAC,SAC7B,KAAK;AAAA,EACH;AAAA,IACE,YAAY;AAAA,MACV,CAAC,eAAe,GAAG;AAAA,QACjB,MAAM,CAAC,OAAO,IAAI;AAAA,QAClB,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;AAeK,IAAM,kBAAkB,CAC7B,YAC0B;AAC1B,QAAM,EAAE,YAAY,MAAM,MAAM,UAAU,QAAQ,MAAM,IAAI;AAE5D,MAAI,MAAM;AACR,QAAI,CAAC,YAAY;AACf,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG,eAAe,IAAI,IAAI;AAAA,MAC1B,GAAI,aAAa,SAAY,CAAC,IAAI,CAAC,UAAU,QAAQ;AAAA,IACvD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,QAAQ,CAAC,SAAS,IAAI,CAAC;AAAA,IAC3B;AAAA,EACF;AACF;;;ACpGA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3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,OAAO;AACL,kBAAQ,MAAM,qDAAgD;AAC9D,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAEA,cAAM,OAAO,eAAe,UAAU,SAAS;AAE/C,YAAI,MAAM;AACR,kBAAQ,MAAM,IAAI;AAAA,QACpB;AAEA,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAEA,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ;AAAA,QACN;AAAA,QACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MACvD;AAEA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF,EAEC,KAAK,EACL,WAAW;","names":["execa","rm","writeFile","join","yargs","join","writeFile","execa","rm","existsSync"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitemcp/server",
3
- "version": "1.9.9",
3
+ "version": "1.9.10",
4
4
  "main": "./dist/ViteMCP.cjs",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -86,7 +86,8 @@
86
86
  "@valibot/to-json-schema": "^1.0.0",
87
87
  "ajv": "^8.0.0",
88
88
  "ajv-formats": "^3.0.0",
89
- "jose": "^5.0.0 || ^6.0.0"
89
+ "jose": "^5.0.0 || ^6.0.0",
90
+ "tsx": "^4.0.0"
90
91
  },
91
92
  "peerDependenciesMeta": {
92
93
  "@apidevtools/swagger-parser": {
@@ -103,6 +104,9 @@
103
104
  },
104
105
  "jose": {
105
106
  "optional": true
107
+ },
108
+ "tsx": {
109
+ "optional": true
106
110
  }
107
111
  },
108
112
  "repository": {
@@ -153,6 +157,7 @@
153
157
  "prettier": "^3.7.4",
154
158
  "semantic-release": "^25.0.2",
155
159
  "tsup": "^8.5.1",
160
+ "tsx": "^4.21.0",
156
161
  "typescript": "^5.9.3",
157
162
  "typescript-eslint": "^8.48.1",
158
163
  "valibot": "^1.2.0",