@vitemcp/server 1.9.7 → 1.9.9
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 +15 -3
- package/dist/{OAuthProvider-BaPwgWny.d.cts → OAuthProvider-Dt3F-oDh.d.cts} +54 -0
- package/dist/{OAuthProvider-BaPwgWny.d.ts → OAuthProvider-Dt3F-oDh.d.ts} +54 -0
- package/dist/ViteMCP.cjs +4 -4
- package/dist/ViteMCP.d.cts +3 -3
- package/dist/ViteMCP.d.ts +3 -3
- package/dist/ViteMCP.js +3 -3
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +10 -2
- package/dist/auth/index.d.ts +10 -2
- package/dist/auth/index.js +1 -1
- package/dist/bin/vitemcp.cjs +7 -1
- package/dist/bin/vitemcp.cjs.map +1 -1
- package/dist/bin/vitemcp.js +7 -1
- package/dist/bin/vitemcp.js.map +1 -1
- package/dist/{chunk-R7AFGJBR.cjs → chunk-2FAJF3V6.cjs} +146 -48
- package/dist/chunk-2FAJF3V6.cjs.map +1 -0
- package/dist/{chunk-ZVA6Y7EO.cjs → chunk-DURXYPPR.cjs} +4 -2
- package/dist/chunk-DURXYPPR.cjs.map +1 -0
- package/dist/{chunk-NSHLX6PZ.cjs → chunk-PNWCRGJY.cjs} +215 -48
- package/dist/chunk-PNWCRGJY.cjs.map +1 -0
- package/dist/{chunk-XQI4HYU6.js → chunk-TYR2KJIV.js} +4 -2
- package/dist/{chunk-XQI4HYU6.js.map → chunk-TYR2KJIV.js.map} +1 -1
- package/dist/{chunk-FAONEXUK.js → chunk-UVKIOOZA.js} +118 -20
- package/dist/chunk-UVKIOOZA.js.map +1 -0
- package/dist/{chunk-WXZQZWBE.js → chunk-ZVK5GKEO.js} +215 -48
- package/dist/chunk-ZVK5GKEO.js.map +1 -0
- package/dist/edge/index.cjs +5 -5
- package/dist/edge/index.js +1 -1
- package/dist/openapi/index.cjs +13 -13
- package/dist/openapi/index.d.cts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-FAONEXUK.js.map +0 -1
- package/dist/chunk-NSHLX6PZ.cjs.map +0 -1
- package/dist/chunk-R7AFGJBR.cjs.map +0 -1
- package/dist/chunk-WXZQZWBE.js.map +0 -1
- package/dist/chunk-ZVA6Y7EO.cjs.map +0 -1
package/dist/bin/vitemcp.js.map
CHANGED
|
@@ -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 */\nconst PROJECT_OVERRIDES = { composite: false, incremental: false };\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,eA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itemcp.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,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MAAM,OAAO,MAAM;AACvC,YAAM,WAAW,QAAQ,KAAK,IAAI;AAElC,UAAI,CAACA,YAAW,QAAQ,GAAG;AACzB,gBAAQ,MAAM,mCAAmC,QAAQ,EAAE;AAC3D,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAEA,cAAQ,IAAI,qCAAqC,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,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkPNWCRGJYcjs = require('./chunk-PNWCRGJY.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkDURXYPPRcjs = require('./chunk-DURXYPPR.cjs');
|
|
10
10
|
|
|
11
11
|
// src/ViteMCP.ts
|
|
12
12
|
|
|
@@ -106,6 +106,27 @@ var noStore = {
|
|
|
106
106
|
"Cache-Control": "no-store",
|
|
107
107
|
Pragma: "no-cache"
|
|
108
108
|
};
|
|
109
|
+
var invalidClientHeaders = {
|
|
110
|
+
...noStore,
|
|
111
|
+
"WWW-Authenticate": 'Basic realm="oauth", charset="UTF-8"'
|
|
112
|
+
};
|
|
113
|
+
var parseBasicCredentials = (authorization) => {
|
|
114
|
+
const decoded = Buffer.from(authorization.slice(6).trim(), "base64").toString(
|
|
115
|
+
"utf8"
|
|
116
|
+
);
|
|
117
|
+
const separator = decoded.indexOf(":");
|
|
118
|
+
if (separator <= 0) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
return {
|
|
123
|
+
clientId: decodeURIComponent(decoded.slice(0, separator)),
|
|
124
|
+
clientSecret: decodeURIComponent(decoded.slice(separator + 1))
|
|
125
|
+
};
|
|
126
|
+
} catch (e4) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
109
130
|
var toSnakeCase = (value) => {
|
|
110
131
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
111
132
|
return value;
|
|
@@ -173,21 +194,47 @@ var createOAuthRouter = (options) => {
|
|
|
173
194
|
const params = Object.fromEntries(new URLSearchParams(text).entries());
|
|
174
195
|
const authHeader = raw.headers.get("authorization");
|
|
175
196
|
if (_optionalChain([authHeader, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4(), 'access', _5 => _5.startsWith, 'call', _6 => _6("basic ")])) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
const credentials = parseBasicCredentials(authHeader);
|
|
198
|
+
if (!credentials) {
|
|
199
|
+
return c.json(
|
|
200
|
+
{
|
|
201
|
+
error: "invalid_client",
|
|
202
|
+
error_description: "Malformed Basic Authorization header"
|
|
203
|
+
},
|
|
204
|
+
401,
|
|
205
|
+
invalidClientHeaders
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (params.client_secret !== void 0) {
|
|
209
|
+
return c.json(
|
|
210
|
+
{
|
|
211
|
+
error: "invalid_request",
|
|
212
|
+
error_description: "Send client credentials in the Authorization header or the request body, not both"
|
|
213
|
+
},
|
|
214
|
+
400,
|
|
215
|
+
noStore
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
if (params.client_id !== void 0 && params.client_id !== credentials.clientId) {
|
|
219
|
+
return c.json(
|
|
220
|
+
{
|
|
221
|
+
error: "invalid_request",
|
|
222
|
+
error_description: "client_id in the request body does not match the Authorization header"
|
|
223
|
+
},
|
|
224
|
+
400,
|
|
225
|
+
noStore
|
|
184
226
|
);
|
|
185
227
|
}
|
|
228
|
+
params.client_id = credentials.clientId;
|
|
229
|
+
params.client_secret = credentials.clientSecret;
|
|
186
230
|
}
|
|
187
231
|
const result = params.grant_type === "refresh_token" ? await proxy.exchangeRefreshToken(params) : await proxy.exchangeAuthorizationCode(params);
|
|
188
232
|
return c.json(result, 200, noStore);
|
|
189
233
|
} catch (error) {
|
|
190
234
|
const { body, status } = errorResponse(error);
|
|
235
|
+
if (body.error === "invalid_client") {
|
|
236
|
+
return c.json(body, 401, invalidClientHeaders);
|
|
237
|
+
}
|
|
191
238
|
return c.json(body, status, noStore);
|
|
192
239
|
}
|
|
193
240
|
});
|
|
@@ -209,7 +256,7 @@ var cancelResponseBody = async (response) => {
|
|
|
209
256
|
}
|
|
210
257
|
try {
|
|
211
258
|
await response.body.cancel();
|
|
212
|
-
} catch (
|
|
259
|
+
} catch (e5) {
|
|
213
260
|
}
|
|
214
261
|
};
|
|
215
262
|
|
|
@@ -358,11 +405,30 @@ function jsonSchemaAdapter(schema) {
|
|
|
358
405
|
}
|
|
359
406
|
};
|
|
360
407
|
}
|
|
408
|
+
var dialectOf = ($schema) => {
|
|
409
|
+
if (typeof $schema !== "string") {
|
|
410
|
+
return "2020-12";
|
|
411
|
+
}
|
|
412
|
+
switch ($schema.replace(/^https?:\/\//, "").replace(/#$/, "")) {
|
|
413
|
+
case "json-schema.org/draft-06/schema":
|
|
414
|
+
case "json-schema.org/draft-07/schema":
|
|
415
|
+
return "draft-07";
|
|
416
|
+
case "json-schema.org/draft/2019-09/schema":
|
|
417
|
+
return "2019-09";
|
|
418
|
+
case "json-schema.org/draft/2020-12/schema":
|
|
419
|
+
return "2020-12";
|
|
420
|
+
}
|
|
421
|
+
throw new Error(
|
|
422
|
+
`JSON Schema declares an unsupported dialect ("$schema": "${$schema}"). jsonSchemaAdapter validates 2020-12, 2019-09, draft-07 and draft-06.`
|
|
423
|
+
);
|
|
424
|
+
};
|
|
361
425
|
async function compileSchema(schema) {
|
|
426
|
+
const { $schema, ...body } = schema;
|
|
427
|
+
const dialect = dialectOf($schema);
|
|
362
428
|
let ajvModule;
|
|
363
429
|
try {
|
|
364
|
-
ajvModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
|
|
365
|
-
} catch (
|
|
430
|
+
ajvModule = dialect === "2020-12" ? await Promise.resolve().then(() => _interopRequireWildcard(require("ajv/dist/2020.js"))) : dialect === "2019-09" ? await Promise.resolve().then(() => _interopRequireWildcard(require("ajv/dist/2019.js"))) : await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
|
|
431
|
+
} catch (e6) {
|
|
366
432
|
throw new Error(
|
|
367
433
|
'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
|
|
368
434
|
);
|
|
@@ -375,9 +441,9 @@ async function compileSchema(schema) {
|
|
|
375
441
|
unwrapDefault(formatsModule)
|
|
376
442
|
);
|
|
377
443
|
addFormats(ajv);
|
|
378
|
-
} catch (
|
|
444
|
+
} catch (e7) {
|
|
379
445
|
}
|
|
380
|
-
return ajv.compile(
|
|
446
|
+
return ajv.compile(body);
|
|
381
447
|
}
|
|
382
448
|
function toIssue(error) {
|
|
383
449
|
const path = error.instancePath.split("/").slice(1).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
|
|
@@ -644,6 +710,8 @@ var ViteMCP = class {
|
|
|
644
710
|
for (const tool of tools) {
|
|
645
711
|
assertStandardSchema(tool.parameters, tool.name, "parameters");
|
|
646
712
|
assertStandardSchema(tool.outputSchema, tool.name, "outputSchema");
|
|
713
|
+
}
|
|
714
|
+
for (const tool of tools) {
|
|
647
715
|
this.#tools = this.#tools.filter((t) => t.name !== tool.name);
|
|
648
716
|
this.#tools.push(tool);
|
|
649
717
|
}
|
|
@@ -755,6 +823,11 @@ var ViteMCP = class {
|
|
|
755
823
|
this.#notifyListChanged("tools");
|
|
756
824
|
}
|
|
757
825
|
async start(options) {
|
|
826
|
+
if (options.transportType === "stdio" ? this.#stdioHandle : this.#httpServer) {
|
|
827
|
+
throw new UnexpectedStateError(
|
|
828
|
+
`ViteMCP is already running on ${options.transportType === "stdio" ? "stdio" : "HTTP"}; call stop() before starting it again`
|
|
829
|
+
);
|
|
830
|
+
}
|
|
758
831
|
this.#serverState = "starting" /* Starting */;
|
|
759
832
|
try {
|
|
760
833
|
if (options.transportType === "stdio") {
|
|
@@ -876,10 +949,11 @@ var ViteMCP = class {
|
|
|
876
949
|
return normalizeToolResult(result, tool.outputSchema !== void 0);
|
|
877
950
|
} catch (error) {
|
|
878
951
|
if (error instanceof UserError) {
|
|
952
|
+
const structuredContent = error.extras && await matchesOutputSchema(schemas.outputSchema, error.extras) ? error.extras : void 0;
|
|
879
953
|
return {
|
|
880
954
|
content: [{ text: error.message, type: "text" }],
|
|
881
955
|
isError: true,
|
|
882
|
-
...
|
|
956
|
+
...structuredContent ? { structuredContent } : {}
|
|
883
957
|
};
|
|
884
958
|
}
|
|
885
959
|
throw error;
|
|
@@ -1064,23 +1138,31 @@ var ViteMCP = class {
|
|
|
1064
1138
|
*
|
|
1065
1139
|
* `timeoutSignal` is folded into `context.signal` for a tool that declares
|
|
1066
1140
|
* `timeoutMs`; everything else mirrors the SDK's request signal alone. Call
|
|
1067
|
-
* `release()` once the handler has settled — see {@link requestScope}.
|
|
1141
|
+
* `release()` once the handler has settled — see {@link requestScope}. It
|
|
1142
|
+
* also ends the context's notifications, as an abort does.
|
|
1068
1143
|
*/
|
|
1069
1144
|
#makeContext(auth, rawCtx, timeoutSignal) {
|
|
1070
1145
|
const ctx = rawCtx;
|
|
1071
1146
|
const mcpReq = _optionalChain([ctx, 'optionalAccess', _40 => _40.mcpReq]);
|
|
1072
|
-
const
|
|
1147
|
+
const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _41 => _41.signal]), timeoutSignal);
|
|
1148
|
+
let settled = false;
|
|
1149
|
+
const notify = async (notification) => {
|
|
1150
|
+
if (settled || scope.signal.aborted) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
await _optionalChain([mcpReq, 'optionalAccess', _42 => _42.notify, 'optionalCall', _43 => _43(notification)]);
|
|
1154
|
+
};
|
|
1155
|
+
const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _44 => _44.envelope, 'optionalAccess', _45 => _45[_server.LOG_LEVEL_META_KEY]]);
|
|
1073
1156
|
const emit = (level, message, data) => {
|
|
1074
1157
|
if (!requestedLevel || LOG_LEVELS.indexOf(level) < LOG_LEVELS.indexOf(requestedLevel)) {
|
|
1075
1158
|
return;
|
|
1076
1159
|
}
|
|
1077
|
-
void
|
|
1160
|
+
void notify({
|
|
1078
1161
|
method: "notifications/message",
|
|
1079
1162
|
params: { data: { context: data, message }, level }
|
|
1080
|
-
})
|
|
1081
|
-
})
|
|
1163
|
+
}).catch(() => {
|
|
1164
|
+
});
|
|
1082
1165
|
};
|
|
1083
|
-
const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _47 => _47.signal]), timeoutSignal);
|
|
1084
1166
|
return {
|
|
1085
1167
|
context: {
|
|
1086
1168
|
auth,
|
|
@@ -1089,12 +1171,12 @@ var ViteMCP = class {
|
|
|
1089
1171
|
requestedSchema: params.requestedSchema
|
|
1090
1172
|
}),
|
|
1091
1173
|
input: (key, schema) => _server.acceptedContent.call(void 0,
|
|
1092
|
-
_optionalChain([mcpReq, 'optionalAccess',
|
|
1174
|
+
_optionalChain([mcpReq, 'optionalAccess', _46 => _46.inputResponses]),
|
|
1093
1175
|
key,
|
|
1094
1176
|
schema
|
|
1095
1177
|
),
|
|
1096
1178
|
inputRequired: (inputRequests, requestState) => _server.inputRequired.call(void 0, { inputRequests, requestState }),
|
|
1097
|
-
inputResponses: _optionalChain([mcpReq, 'optionalAccess',
|
|
1179
|
+
inputResponses: _optionalChain([mcpReq, 'optionalAccess', _47 => _47.inputResponses]),
|
|
1098
1180
|
log: {
|
|
1099
1181
|
debug: (m, d) => emit("debug", m, d),
|
|
1100
1182
|
error: (m, d) => emit("error", m, d),
|
|
@@ -1102,11 +1184,11 @@ var ViteMCP = class {
|
|
|
1102
1184
|
warn: (m, d) => emit("warning", m, d)
|
|
1103
1185
|
},
|
|
1104
1186
|
reportProgress: async (progress) => {
|
|
1105
|
-
const progressToken = _optionalChain([mcpReq, 'optionalAccess',
|
|
1187
|
+
const progressToken = _optionalChain([mcpReq, 'optionalAccess', _48 => _48._meta, 'optionalAccess', _49 => _49.progressToken]);
|
|
1106
1188
|
if (progressToken === void 0) {
|
|
1107
1189
|
return;
|
|
1108
1190
|
}
|
|
1109
|
-
await
|
|
1191
|
+
await notify({
|
|
1110
1192
|
method: "notifications/progress",
|
|
1111
1193
|
params: {
|
|
1112
1194
|
message: progress.message,
|
|
@@ -1114,15 +1196,18 @@ var ViteMCP = class {
|
|
|
1114
1196
|
progressToken,
|
|
1115
1197
|
total: progress.total
|
|
1116
1198
|
}
|
|
1117
|
-
})
|
|
1199
|
+
});
|
|
1118
1200
|
},
|
|
1119
|
-
requestId: _optionalChain([mcpReq, 'optionalAccess',
|
|
1201
|
+
requestId: _optionalChain([mcpReq, 'optionalAccess', _50 => _50.id]),
|
|
1120
1202
|
// The SDK exposes this as an accessor; call it so callers get the
|
|
1121
1203
|
// value.
|
|
1122
|
-
requestState: _optionalChain([mcpReq, 'optionalAccess',
|
|
1204
|
+
requestState: _optionalChain([mcpReq, 'optionalAccess', _51 => _51.requestState, 'optionalCall', _52 => _52()]),
|
|
1123
1205
|
signal: scope.signal
|
|
1124
1206
|
},
|
|
1125
|
-
release:
|
|
1207
|
+
release: () => {
|
|
1208
|
+
settled = true;
|
|
1209
|
+
scope.release();
|
|
1210
|
+
}
|
|
1126
1211
|
};
|
|
1127
1212
|
}
|
|
1128
1213
|
/**
|
|
@@ -1131,7 +1216,7 @@ var ViteMCP = class {
|
|
|
1131
1216
|
* no addressee on a stateless transport.
|
|
1132
1217
|
*/
|
|
1133
1218
|
#notifyListChanged(kind) {
|
|
1134
|
-
const notifier = _optionalChain([this, 'access',
|
|
1219
|
+
const notifier = _optionalChain([this, 'access', _53 => _53.#handler, 'optionalAccess', _54 => _54.notify]);
|
|
1135
1220
|
if (!notifier) {
|
|
1136
1221
|
return;
|
|
1137
1222
|
}
|
|
@@ -1179,7 +1264,7 @@ var ViteMCP = class {
|
|
|
1179
1264
|
// Authentication has already run in the route below, which is the only
|
|
1180
1265
|
// place that can turn a refusal into an HTTP status. What reaches here
|
|
1181
1266
|
// is either an authenticated session or a deliberately anonymous one.
|
|
1182
|
-
async ({ era }) => this.#buildServer(_optionalChain([this, 'access',
|
|
1267
|
+
async ({ era }) => this.#buildServer(_optionalChain([this, 'access', _55 => _55.#authStore, 'access', _56 => _56.getStore, 'call', _57 => _57(), 'optionalAccess', _58 => _58.auth]), {
|
|
1183
1268
|
era,
|
|
1184
1269
|
// A 2025-era client reads `resources.subscribe` as a promise of
|
|
1185
1270
|
// `resources/subscribe`, which is not served.
|
|
@@ -1200,7 +1285,7 @@ var ViteMCP = class {
|
|
|
1200
1285
|
provider.getOAuthConfig(),
|
|
1201
1286
|
_nullishCoalesce(config.endpoint, () => ( "/mcp"))
|
|
1202
1287
|
))));
|
|
1203
|
-
if (_optionalChain([oauth, 'optionalAccess',
|
|
1288
|
+
if (_optionalChain([oauth, 'optionalAccess', _59 => _59.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _60 => _60.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _61 => _61.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _62 => _62.protectedResource]))))) {
|
|
1204
1289
|
this.#honoApp.route(
|
|
1205
1290
|
"/",
|
|
1206
1291
|
createOAuthRouter({
|
|
@@ -1214,10 +1299,10 @@ var ViteMCP = class {
|
|
|
1214
1299
|
this.#protectedResource = oauth.protectedResource;
|
|
1215
1300
|
}
|
|
1216
1301
|
const health = this.#options.health;
|
|
1217
|
-
if (_optionalChain([health, 'optionalAccess',
|
|
1302
|
+
if (_optionalChain([health, 'optionalAccess', _63 => _63.enabled]) !== false) {
|
|
1218
1303
|
this.#honoApp.get(
|
|
1219
|
-
_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
1220
|
-
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
1304
|
+
_nullishCoalesce(_optionalChain([health, 'optionalAccess', _64 => _64.path]), () => ( "/health")),
|
|
1305
|
+
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess', _65 => _65.message]), () => ( "ok")), _nullishCoalesce(_optionalChain([health, 'optionalAccess', _66 => _66.status]), () => ( 200)))
|
|
1221
1306
|
);
|
|
1222
1307
|
}
|
|
1223
1308
|
const endpoint = `${_nullishCoalesce(config.basePath, () => ( ""))}${_nullishCoalesce(config.endpoint, () => ( "/mcp"))}`;
|
|
@@ -1254,11 +1339,11 @@ var ViteMCP = class {
|
|
|
1254
1339
|
"Content-Type": "application/json"
|
|
1255
1340
|
});
|
|
1256
1341
|
req.resume();
|
|
1257
|
-
res.once("finish", () => _optionalChain([res, 'access',
|
|
1342
|
+
res.once("finish", () => _optionalChain([res, 'access', _67 => _67.socket, 'optionalAccess', _68 => _68.end, 'call', _69 => _69()]));
|
|
1258
1343
|
res.end(
|
|
1259
1344
|
JSON.stringify({
|
|
1260
1345
|
error: "invalid_request",
|
|
1261
|
-
error_description: `Request body exceeds ${
|
|
1346
|
+
error_description: `Request body exceeds ${_chunkDURXYPPRcjs.formatBytes.call(void 0, maxBodySize)}`
|
|
1262
1347
|
})
|
|
1263
1348
|
);
|
|
1264
1349
|
return;
|
|
@@ -1333,7 +1418,7 @@ var ViteMCP = class {
|
|
|
1333
1418
|
*/
|
|
1334
1419
|
async #toSdkSchema(schema, label, io) {
|
|
1335
1420
|
try {
|
|
1336
|
-
return await
|
|
1421
|
+
return await _chunkDURXYPPRcjs.toSdkSchema.call(void 0, schema, io, convertToJsonSchema);
|
|
1337
1422
|
} catch (error) {
|
|
1338
1423
|
throw new UnexpectedStateError(
|
|
1339
1424
|
`${label} is not a supported Standard Schema: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -1374,7 +1459,7 @@ var withEndpointAsResource = (config, endpoint) => ({
|
|
|
1374
1459
|
...config,
|
|
1375
1460
|
protectedResource: {
|
|
1376
1461
|
...config.protectedResource,
|
|
1377
|
-
resource: `${
|
|
1462
|
+
resource: `${_chunkPNWCRGJYcjs.withoutTrailingSlash.call(void 0, config.protectedResource.resource)}${endpoint}`
|
|
1378
1463
|
}
|
|
1379
1464
|
});
|
|
1380
1465
|
var nodeToWebRequest = (req, body, secure, signal) => {
|
|
@@ -1470,36 +1555,49 @@ var readCappedNodeBody = async (req, maxBytes) => {
|
|
|
1470
1555
|
}
|
|
1471
1556
|
return Buffer.concat(chunks);
|
|
1472
1557
|
};
|
|
1473
|
-
var convertToJsonSchema = async (schema, io) => schema["~standard"].vendor === "valibot" ?
|
|
1558
|
+
var convertToJsonSchema = async (schema, io) => schema["~standard"].vendor === "valibot" ? _chunkDURXYPPRcjs.valibotToJsonSchema.call(void 0, schema, io) : _xsschema.toJsonSchema.call(void 0, schema);
|
|
1474
1559
|
var assertStandardSchema = (schema, toolName, field) => {
|
|
1475
1560
|
if (schema === void 0) {
|
|
1476
1561
|
return;
|
|
1477
1562
|
}
|
|
1478
|
-
const standard = _optionalChain([schema, 'optionalAccess',
|
|
1479
|
-
if (typeof _optionalChain([standard, 'optionalAccess',
|
|
1563
|
+
const standard = _optionalChain([schema, 'optionalAccess', _70 => _70["~standard"]]);
|
|
1564
|
+
if (typeof _optionalChain([standard, 'optionalAccess', _71 => _71.validate]) !== "function") {
|
|
1480
1565
|
throw new UnexpectedStateError(
|
|
1481
1566
|
`Tool '${toolName}' ${field} must implement Standard Schema. If you are using Zod, upgrade to version 3.24 or later.`,
|
|
1482
1567
|
{ toolName }
|
|
1483
1568
|
);
|
|
1484
1569
|
}
|
|
1485
1570
|
};
|
|
1571
|
+
var matchesOutputSchema = async (schema, value) => {
|
|
1572
|
+
if (!schema) {
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
try {
|
|
1576
|
+
const result = await schema["~standard"].validate(
|
|
1577
|
+
value
|
|
1578
|
+
);
|
|
1579
|
+
return !result.issues;
|
|
1580
|
+
} catch (e8) {
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1486
1584
|
var promptArgsSchema = (prompt) => {
|
|
1487
1585
|
const args = prompt.arguments;
|
|
1488
|
-
if (!_optionalChain([args, 'optionalAccess',
|
|
1586
|
+
if (!_optionalChain([args, 'optionalAccess', _72 => _72.length])) {
|
|
1489
1587
|
return void 0;
|
|
1490
1588
|
}
|
|
1491
1589
|
const shape = {};
|
|
1492
1590
|
for (const arg of args) {
|
|
1493
1591
|
const explicitCompleter = _nullishCoalesce(arg.complete, () => ( (prompt.complete ? (value) => prompt.complete(arg.name, value) : void 0)));
|
|
1494
1592
|
const enumValues = arg.enum;
|
|
1495
|
-
const completer = _nullishCoalesce(explicitCompleter, () => ( (_optionalChain([enumValues, 'optionalAccess',
|
|
1593
|
+
const completer = _nullishCoalesce(explicitCompleter, () => ( (_optionalChain([enumValues, 'optionalAccess', _73 => _73.length]) ? async (value) => ({
|
|
1496
1594
|
// An empty value is how an editor asks for the whole set before the
|
|
1497
1595
|
// user has typed anything; filtering it would answer with nothing.
|
|
1498
1596
|
values: value ? enumValues.filter(
|
|
1499
1597
|
(option) => option.toLowerCase().includes(value.toLowerCase())
|
|
1500
1598
|
) : [...enumValues]
|
|
1501
1599
|
}) : void 0)));
|
|
1502
|
-
const valueSchema = _optionalChain([enumValues, 'optionalAccess',
|
|
1600
|
+
const valueSchema = _optionalChain([enumValues, 'optionalAccess', _74 => _74.length]) ? _zod.z.enum(enumValues) : _zod.z.string();
|
|
1503
1601
|
const described = arg.description ? valueSchema.describe(arg.description) : valueSchema;
|
|
1504
1602
|
const base = completer ? _server.completable.call(void 0,
|
|
1505
1603
|
described,
|
|
@@ -1507,7 +1605,7 @@ var promptArgsSchema = (prompt) => {
|
|
|
1507
1605
|
) : described;
|
|
1508
1606
|
shape[arg.name] = arg.required ? base : base.optional();
|
|
1509
1607
|
}
|
|
1510
|
-
return
|
|
1608
|
+
return _chunkDURXYPPRcjs.ownKeysOnly.call(void 0, _zod.z.object(shape));
|
|
1511
1609
|
};
|
|
1512
1610
|
var isStructuredResult = (value) => {
|
|
1513
1611
|
if (!Object.hasOwn(value, "structuredContent") || value.structuredContent === void 0) {
|
|
@@ -1576,4 +1674,4 @@ var normalizeToolResult = (result, hasOutputSchema) => {
|
|
|
1576
1674
|
|
|
1577
1675
|
|
|
1578
1676
|
exports.cancelResponseBody = cancelResponseBody; exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.delay = _promises5.setTimeout; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.ViteMCPError = ViteMCPError; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.ServerState = ServerState; exports.ViteMCP = ViteMCP;
|
|
1579
|
-
//# sourceMappingURL=chunk-
|
|
1677
|
+
//# sourceMappingURL=chunk-2FAJF3V6.cjs.map
|