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

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.cjs CHANGED
@@ -1132,6 +1132,7 @@ defineLazyProperty(apps, "safari", () => detectPlatformBinary({
1132
1132
  var open_default = open;
1133
1133
 
1134
1134
  // src/index.ts
1135
+ var import_vite_plugin_singlefile = require("vite-plugin-singlefile");
1135
1136
  var import_zod = require("zod");
1136
1137
 
1137
1138
  // src/commands/auth.ts
@@ -4551,6 +4552,9 @@ async function waitForServer(port, host = "localhost", maxAttempts = 30) {
4551
4552
  }
4552
4553
  return false;
4553
4554
  }
4555
+ function normalizeBrowserHost(host) {
4556
+ return host === "0.0.0.0" ? "localhost" : host;
4557
+ }
4554
4558
  function runCommand(command, args, cwd, env2, filterStderr = false) {
4555
4559
  const proc = (0, import_node_child_process9.spawn)(command, args, {
4556
4560
  cwd,
@@ -4658,7 +4662,8 @@ async function findServerFile(projectPath) {
4658
4662
  }
4659
4663
  throw new Error("No server file found");
4660
4664
  }
4661
- async function buildWidgets(projectPath) {
4665
+ async function buildWidgets(projectPath, options = {}) {
4666
+ const { inline = true } = options;
4662
4667
  const { promises: fs10 } = await import("fs");
4663
4668
  const { build } = await import("vite");
4664
4669
  const resourcesDir = import_node_path6.default.join(projectPath, "resources");
@@ -4703,7 +4708,11 @@ async function buildWidgets(projectPath) {
4703
4708
  console.log(source_default.gray("No widgets found in resources/ directory"));
4704
4709
  return [];
4705
4710
  }
4706
- console.log(source_default.gray(`Building ${entries.length} widget(s)...`));
4711
+ console.log(
4712
+ source_default.gray(
4713
+ `Building ${entries.length} widget(s)${inline ? " (inline mode for VS Code compatibility)" : ""}...`
4714
+ )
4715
+ );
4707
4716
  const react = (await import("@vitejs/plugin-react")).default;
4708
4717
  const tailwindcss = (await import("@tailwindcss/vite")).default;
4709
4718
  const packageJsonPath = import_node_path6.default.join(projectPath, "package.json");
@@ -4981,18 +4990,27 @@ export default {
4981
4990
  return null;
4982
4991
  }
4983
4992
  };
4993
+ const buildPlugins = inline ? [
4994
+ buildNodeStubsPlugin,
4995
+ tailwindcss(),
4996
+ react(),
4997
+ (0, import_vite_plugin_singlefile.viteSingleFile)({ removeViteModuleLoader: true })
4998
+ ] : [buildNodeStubsPlugin, tailwindcss(), react()];
4984
4999
  await build({
4985
5000
  root: tempDir,
4986
5001
  base: baseUrl,
4987
- plugins: [buildNodeStubsPlugin, tailwindcss(), react()],
4988
- experimental: {
4989
- renderBuiltUrl: (filename, { hostType }) => {
4990
- if (["js", "css"].includes(hostType)) {
4991
- return {
4992
- runtime: `window.__getFile(${JSON.stringify(filename)})`
4993
- };
4994
- } else {
4995
- return { relative: true };
5002
+ plugins: buildPlugins,
5003
+ // Only use renderBuiltUrl for non-inline builds (external assets need runtime URL resolution)
5004
+ ...inline ? {} : {
5005
+ experimental: {
5006
+ renderBuiltUrl: (filename, { hostType }) => {
5007
+ if (["js", "css"].includes(hostType)) {
5008
+ return {
5009
+ runtime: `window.__getFile(${JSON.stringify(filename)})`
5010
+ };
5011
+ } else {
5012
+ return { relative: true };
5013
+ }
4996
5014
  }
4997
5015
  }
4998
5016
  },
@@ -5008,6 +5026,17 @@ export default {
5008
5026
  build: {
5009
5027
  outDir,
5010
5028
  emptyOutDir: true,
5029
+ // Disable source maps to avoid CSP eval violations
5030
+ // Source maps can use eval-based mappings which break strict CSP policies
5031
+ sourcemap: false,
5032
+ // Minify for smaller bundle size
5033
+ minify: "esbuild",
5034
+ // For inline builds, disable CSS code splitting and inline all assets
5035
+ ...inline ? {
5036
+ cssCodeSplit: false,
5037
+ assetsInlineLimit: 1e8
5038
+ // Inline all assets under 100MB (effectively all)
5039
+ } : {},
5011
5040
  rollupOptions: {
5012
5041
  input: import_node_path6.default.join(tempDir, "index.html"),
5013
5042
  external: (id) => {
@@ -5016,6 +5045,40 @@ export default {
5016
5045
  }
5017
5046
  }
5018
5047
  });
5048
+ try {
5049
+ const assetsDir = import_node_path6.default.join(outDir, "assets");
5050
+ const assetFiles = await fs10.readdir(assetsDir);
5051
+ const jsFiles = assetFiles.filter((f) => f.endsWith(".js"));
5052
+ for (const jsFile of jsFiles) {
5053
+ const jsPath = import_node_path6.default.join(assetsDir, jsFile);
5054
+ let content = await fs10.readFile(jsPath, "utf8");
5055
+ const zodConfigPatterns = [
5056
+ // Non-minified: export const globalConfig = {}
5057
+ /export\s+const\s+globalConfig\s*=\s*\{\s*\}/g,
5058
+ // Minified pattern: ZodEncodeError"}}const X={};function followed by return X
5059
+ // This is the unique signature of Zod's globalConfig
5060
+ /ZodEncodeError[^}]*\}\}const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*\{\s*\}/g
5061
+ ];
5062
+ let patched = false;
5063
+ for (const pattern of zodConfigPatterns) {
5064
+ if (pattern.test(content)) {
5065
+ pattern.lastIndex = 0;
5066
+ content = content.replace(pattern, (match) => {
5067
+ return match.replace(/=\s*\{\s*\}/, "={jitless:true}");
5068
+ });
5069
+ patched = true;
5070
+ }
5071
+ }
5072
+ if (patched) {
5073
+ await fs10.writeFile(jsPath, content, "utf8");
5074
+ console.log(source_default.gray(` \u2192 Patched Zod JIT in ${jsFile}`));
5075
+ }
5076
+ }
5077
+ } catch (error) {
5078
+ if (error.code !== "ENOENT") {
5079
+ console.warn(source_default.yellow(` \u26A0 Failed to patch Zod JIT: ${error}`));
5080
+ }
5081
+ }
5019
5082
  const mcpServerUrl = process.env.MCP_SERVER_URL;
5020
5083
  if (mcpServerUrl) {
5021
5084
  try {
@@ -5069,12 +5132,17 @@ export default {
5069
5132
  );
5070
5133
  return builtWidgets;
5071
5134
  }
5072
- 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) => {
5135
+ 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(
5136
+ "--inline",
5137
+ "Inline all JS/CSS into HTML (required for VS Code MCP Apps)"
5138
+ ).option("--no-inline", "Keep JS/CSS as separate files (default)").action(async (options) => {
5073
5139
  try {
5074
5140
  const projectPath = import_node_path6.default.resolve(options.path);
5075
5141
  const { promises: fs10 } = await import("fs");
5076
5142
  displayPackageVersions(projectPath);
5077
- const builtWidgets = await buildWidgets(projectPath);
5143
+ const builtWidgets = await buildWidgets(projectPath, {
5144
+ inline: options.inline ?? false
5145
+ });
5078
5146
  console.log(source_default.gray("Building TypeScript..."));
5079
5147
  await runCommand("npx", ["tsc"], projectPath);
5080
5148
  console.log(source_default.green("\u2713 TypeScript build complete!"));
@@ -5131,7 +5199,11 @@ program.command("build").description("Build TypeScript and MCP UI widgets").opti
5131
5199
  process.exit(1);
5132
5200
  }
5133
5201
  });
5134
- 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) => {
5202
+ 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(
5203
+ "--host <host>",
5204
+ "Server host (use 0.0.0.0 to listen on all interfaces)",
5205
+ "0.0.0.0"
5206
+ ).option("--no-open", "Do not auto-open inspector").option("--no-hmr", "Disable hot module reloading (use tsx watch instead)").action(async (options) => {
5135
5207
  try {
5136
5208
  const projectPath = import_node_path6.default.resolve(options.path);
5137
5209
  let port = parseInt(options.port, 10);
@@ -5195,11 +5267,14 @@ program.command("dev").description("Run development server with auto-reload and
5195
5267
  const startTime = Date.now();
5196
5268
  const ready = await waitForServer(port, host);
5197
5269
  if (ready) {
5198
- const mcpEndpoint = `http://${host}:${port}/mcp`;
5199
- const inspectorUrl = `http://${host}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5270
+ const browserHost = normalizeBrowserHost(host);
5271
+ const mcpEndpoint = `http://${browserHost}:${port}/mcp`;
5272
+ const inspectorUrl = `http://${browserHost}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5200
5273
  const readyTime = Date.now() - startTime;
5201
5274
  console.log(source_default.green.bold(`\u2713 Ready in ${readyTime}ms`));
5202
- console.log(source_default.whiteBright(`Local: http://${host}:${port}`));
5275
+ console.log(
5276
+ source_default.whiteBright(`Local: http://${browserHost}:${port}`)
5277
+ );
5203
5278
  console.log(source_default.whiteBright(`Network: http://${host}:${port}`));
5204
5279
  console.log(source_default.whiteBright(`MCP: ${mcpEndpoint}`));
5205
5280
  console.log(source_default.whiteBright(`Inspector: ${inspectorUrl}
@@ -5283,11 +5358,14 @@ program.command("dev").description("Run development server with auto-reload and
5283
5358
  if (options.open !== false) {
5284
5359
  const ready = await waitForServer(port, host);
5285
5360
  if (ready) {
5286
- const mcpEndpoint = `http://${host}:${port}/mcp`;
5287
- const inspectorUrl = `http://${host}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5361
+ const browserHost = normalizeBrowserHost(host);
5362
+ const mcpEndpoint = `http://${browserHost}:${port}/mcp`;
5363
+ const inspectorUrl = `http://${browserHost}:${port}/inspector?autoConnect=${encodeURIComponent(mcpEndpoint)}`;
5288
5364
  const readyTime = Date.now() - startTime;
5289
5365
  console.log(source_default.green.bold(`\u2713 Ready in ${readyTime}ms`));
5290
- console.log(source_default.whiteBright(`Local: http://${host}:${port}`));
5366
+ console.log(
5367
+ source_default.whiteBright(`Local: http://${browserHost}:${port}`)
5368
+ );
5291
5369
  console.log(source_default.whiteBright(`Network: http://${host}:${port}`));
5292
5370
  console.log(source_default.whiteBright(`MCP: ${mcpEndpoint}`));
5293
5371
  console.log(source_default.whiteBright(`Inspector: ${inspectorUrl}`));