@mcp-use/cli 2.11.2 → 2.12.0-canary.1

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/dist/index.js CHANGED
@@ -1112,6 +1112,7 @@ defineLazyProperty(apps, "safari", () => detectPlatformBinary({
1112
1112
  var open_default = open;
1113
1113
 
1114
1114
  // src/index.ts
1115
+ import { viteSingleFile } from "vite-plugin-singlefile";
1115
1116
  import { toJSONSchema } from "zod";
1116
1117
 
1117
1118
  // src/commands/auth.ts
@@ -4533,6 +4534,9 @@ async function waitForServer(port, host = "localhost", maxAttempts = 30) {
4533
4534
  }
4534
4535
  return false;
4535
4536
  }
4537
+ function normalizeBrowserHost(host) {
4538
+ return host === "0.0.0.0" ? "localhost" : host;
4539
+ }
4536
4540
  function runCommand(command, args, cwd, env2, filterStderr = false) {
4537
4541
  const proc = spawn(command, args, {
4538
4542
  cwd,
@@ -4640,7 +4644,8 @@ async function findServerFile(projectPath) {
4640
4644
  }
4641
4645
  throw new Error("No server file found");
4642
4646
  }
4643
- async function buildWidgets(projectPath) {
4647
+ async function buildWidgets(projectPath, options = {}) {
4648
+ const { inline = true } = options;
4644
4649
  const { promises: fs10 } = await import("fs");
4645
4650
  const { build } = await import("vite");
4646
4651
  const resourcesDir = path6.join(projectPath, "resources");
@@ -4685,7 +4690,11 @@ async function buildWidgets(projectPath) {
4685
4690
  console.log(source_default.gray("No widgets found in resources/ directory"));
4686
4691
  return [];
4687
4692
  }
4688
- console.log(source_default.gray(`Building ${entries.length} widget(s)...`));
4693
+ console.log(
4694
+ source_default.gray(
4695
+ `Building ${entries.length} widget(s)${inline ? " (inline mode for VS Code compatibility)" : ""}...`
4696
+ )
4697
+ );
4689
4698
  const react = (await import("@vitejs/plugin-react")).default;
4690
4699
  const tailwindcss = (await import("@tailwindcss/vite")).default;
4691
4700
  const packageJsonPath = path6.join(projectPath, "package.json");
@@ -4963,18 +4972,27 @@ export default {
4963
4972
  return null;
4964
4973
  }
4965
4974
  };
4975
+ const buildPlugins = inline ? [
4976
+ buildNodeStubsPlugin,
4977
+ tailwindcss(),
4978
+ react(),
4979
+ viteSingleFile({ removeViteModuleLoader: true })
4980
+ ] : [buildNodeStubsPlugin, tailwindcss(), react()];
4966
4981
  await build({
4967
4982
  root: tempDir,
4968
4983
  base: baseUrl,
4969
- plugins: [buildNodeStubsPlugin, tailwindcss(), react()],
4970
- experimental: {
4971
- renderBuiltUrl: (filename, { hostType }) => {
4972
- if (["js", "css"].includes(hostType)) {
4973
- return {
4974
- runtime: `window.__getFile(${JSON.stringify(filename)})`
4975
- };
4976
- } else {
4977
- return { relative: true };
4984
+ plugins: buildPlugins,
4985
+ // Only use renderBuiltUrl for non-inline builds (external assets need runtime URL resolution)
4986
+ ...inline ? {} : {
4987
+ experimental: {
4988
+ renderBuiltUrl: (filename, { hostType }) => {
4989
+ if (["js", "css"].includes(hostType)) {
4990
+ return {
4991
+ runtime: `window.__getFile(${JSON.stringify(filename)})`
4992
+ };
4993
+ } else {
4994
+ return { relative: true };
4995
+ }
4978
4996
  }
4979
4997
  }
4980
4998
  },
@@ -4990,6 +5008,17 @@ export default {
4990
5008
  build: {
4991
5009
  outDir,
4992
5010
  emptyOutDir: true,
5011
+ // Disable source maps to avoid CSP eval violations
5012
+ // Source maps can use eval-based mappings which break strict CSP policies
5013
+ sourcemap: false,
5014
+ // Minify for smaller bundle size
5015
+ minify: "esbuild",
5016
+ // For inline builds, disable CSS code splitting and inline all assets
5017
+ ...inline ? {
5018
+ cssCodeSplit: false,
5019
+ assetsInlineLimit: 1e8
5020
+ // Inline all assets under 100MB (effectively all)
5021
+ } : {},
4993
5022
  rollupOptions: {
4994
5023
  input: path6.join(tempDir, "index.html"),
4995
5024
  external: (id) => {
@@ -4998,6 +5027,40 @@ export default {
4998
5027
  }
4999
5028
  }
5000
5029
  });
5030
+ try {
5031
+ const assetsDir = path6.join(outDir, "assets");
5032
+ const assetFiles = await fs10.readdir(assetsDir);
5033
+ const jsFiles = assetFiles.filter((f) => f.endsWith(".js"));
5034
+ for (const jsFile of jsFiles) {
5035
+ const jsPath = path6.join(assetsDir, jsFile);
5036
+ let content = await fs10.readFile(jsPath, "utf8");
5037
+ const zodConfigPatterns = [
5038
+ // Non-minified: export const globalConfig = {}
5039
+ /export\s+const\s+globalConfig\s*=\s*\{\s*\}/g,
5040
+ // Minified pattern: ZodEncodeError"}}const X={};function followed by return X
5041
+ // This is the unique signature of Zod's globalConfig
5042
+ /ZodEncodeError[^}]*\}\}const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*\{\s*\}/g
5043
+ ];
5044
+ let patched = false;
5045
+ for (const pattern of zodConfigPatterns) {
5046
+ if (pattern.test(content)) {
5047
+ pattern.lastIndex = 0;
5048
+ content = content.replace(pattern, (match) => {
5049
+ return match.replace(/=\s*\{\s*\}/, "={jitless:true}");
5050
+ });
5051
+ patched = true;
5052
+ }
5053
+ }
5054
+ if (patched) {
5055
+ await fs10.writeFile(jsPath, content, "utf8");
5056
+ console.log(source_default.gray(` \u2192 Patched Zod JIT in ${jsFile}`));
5057
+ }
5058
+ }
5059
+ } catch (error) {
5060
+ if (error.code !== "ENOENT") {
5061
+ console.warn(source_default.yellow(` \u26A0 Failed to patch Zod JIT: ${error}`));
5062
+ }
5063
+ }
5001
5064
  const mcpServerUrl = process.env.MCP_SERVER_URL;
5002
5065
  if (mcpServerUrl) {
5003
5066
  try {
@@ -5051,12 +5114,17 @@ export default {
5051
5114
  );
5052
5115
  return builtWidgets;
5053
5116
  }
5054
- program.command("build").description("Build TypeScript and MCP UI widgets").option("-p, --path <path>", "Path to project directory", process.cwd()).option("--with-inspector", "Include inspector in production build").action(async (options) => {
5117
+ program.command("build").description("Build TypeScript and MCP UI widgets").option("-p, --path <path>", "Path to project directory", process.cwd()).option("--with-inspector", "Include inspector in production build").option(
5118
+ "--inline",
5119
+ "Inline all JS/CSS into HTML (required for VS Code MCP Apps)"
5120
+ ).option("--no-inline", "Keep JS/CSS as separate files (default)").action(async (options) => {
5055
5121
  try {
5056
5122
  const projectPath = path6.resolve(options.path);
5057
5123
  const { promises: fs10 } = await import("fs");
5058
5124
  displayPackageVersions(projectPath);
5059
- const builtWidgets = await buildWidgets(projectPath);
5125
+ const builtWidgets = await buildWidgets(projectPath, {
5126
+ inline: options.inline ?? false
5127
+ });
5060
5128
  console.log(source_default.gray("Building TypeScript..."));
5061
5129
  await runCommand("npx", ["tsc"], projectPath);
5062
5130
  console.log(source_default.green("\u2713 TypeScript build complete!"));
@@ -5113,7 +5181,11 @@ program.command("build").description("Build TypeScript and MCP UI widgets").opti
5113
5181
  process.exit(1);
5114
5182
  }
5115
5183
  });
5116
- program.command("dev").description("Run development server with auto-reload and inspector").option("-p, --path <path>", "Path to project directory", process.cwd()).option("--port <port>", "Server port", "3000").option("--host <host>", "Server host", "localhost").option("--no-open", "Do not auto-open inspector").option("--no-hmr", "Disable hot module reloading (use tsx watch instead)").action(async (options) => {
5184
+ program.command("dev").description("Run development server with auto-reload and inspector").option("-p, --path <path>", "Path to project directory", process.cwd()).option("--port <port>", "Server port", "3000").option(
5185
+ "--host <host>",
5186
+ "Server host (use 0.0.0.0 to listen on all interfaces)",
5187
+ "0.0.0.0"
5188
+ ).option("--no-open", "Do not auto-open inspector").option("--no-hmr", "Disable hot module reloading (use tsx watch instead)").action(async (options) => {
5117
5189
  try {
5118
5190
  const projectPath = path6.resolve(options.path);
5119
5191
  let port = parseInt(options.port, 10);
@@ -5177,11 +5249,14 @@ program.command("dev").description("Run development server with auto-reload and
5177
5249
  const startTime = Date.now();
5178
5250
  const ready = await waitForServer(port, host);
5179
5251
  if (ready) {
5180
- const mcpEndpoint = `http://${host}:${port}/mcp`;
5181
- const inspectorUrl = `http://${host}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5252
+ const browserHost = normalizeBrowserHost(host);
5253
+ const mcpEndpoint = `http://${browserHost}:${port}/mcp`;
5254
+ const inspectorUrl = `http://${browserHost}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5182
5255
  const readyTime = Date.now() - startTime;
5183
5256
  console.log(source_default.green.bold(`\u2713 Ready in ${readyTime}ms`));
5184
- console.log(source_default.whiteBright(`Local: http://${host}:${port}`));
5257
+ console.log(
5258
+ source_default.whiteBright(`Local: http://${browserHost}:${port}`)
5259
+ );
5185
5260
  console.log(source_default.whiteBright(`Network: http://${host}:${port}`));
5186
5261
  console.log(source_default.whiteBright(`MCP: ${mcpEndpoint}`));
5187
5262
  console.log(source_default.whiteBright(`Inspector: ${inspectorUrl}
@@ -5265,11 +5340,14 @@ program.command("dev").description("Run development server with auto-reload and
5265
5340
  if (options.open !== false) {
5266
5341
  const ready = await waitForServer(port, host);
5267
5342
  if (ready) {
5268
- const mcpEndpoint = `http://${host}:${port}/mcp`;
5269
- const inspectorUrl = `http://${host}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5343
+ const browserHost = normalizeBrowserHost(host);
5344
+ const mcpEndpoint = `http://${browserHost}:${port}/mcp`;
5345
+ const inspectorUrl = `http://${browserHost}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5270
5346
  const readyTime = Date.now() - startTime;
5271
5347
  console.log(source_default.green.bold(`\u2713 Ready in ${readyTime}ms`));
5272
- console.log(source_default.whiteBright(`Local: http://${host}:${port}`));
5348
+ console.log(
5349
+ source_default.whiteBright(`Local: http://${browserHost}:${port}`)
5350
+ );
5273
5351
  console.log(source_default.whiteBright(`Network: http://${host}:${port}`));
5274
5352
  console.log(source_default.whiteBright(`MCP: ${mcpEndpoint}`));
5275
5353
  console.log(source_default.whiteBright(`Inspector: ${inspectorUrl}`));