@mcp-use/cli 3.2.0-canary.6 → 3.2.0-canary.7

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.
@@ -13,6 +13,7 @@ interface ScreenshotOptions {
13
13
  delay?: string;
14
14
  quiet?: boolean;
15
15
  timeout: string;
16
+ cdpUrl?: string;
16
17
  }
17
18
  /**
18
19
  * Inspect a tool's `_meta` for the UI resource URI it renders, if any. Falls back
@@ -38,6 +39,12 @@ export interface CaptureToolScreenshotOptions {
38
39
  timeoutMs?: number;
39
40
  inspector?: string;
40
41
  quiet?: boolean;
42
+ /**
43
+ * Pre-existing CDP WebSocket URL. When set, the screenshot is captured via
44
+ * the remote browser instead of spawning a local Chrome. The inspector URL
45
+ * must be reachable from that remote browser.
46
+ */
47
+ cdpUrl?: string;
41
48
  }
42
49
  export interface CaptureToolScreenshotResult {
43
50
  outputPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../../src/commands/screenshot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAkBjD,UAAU,iBAAiB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AASD;;;GAGG;AACH,wBAAgB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AAC;CACrB;AAED,MAAM,WAAW,4BAA4B;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,2BAA2B,EACnC,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CA0DtC;AAqLD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,OAAa,GAAG,MAAM,CAKzD;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMhE;AAyCD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAC7B,OAAO,CAAC,IAAI,CAAC,CAoHf;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAsDjD"}
package/dist/index.cjs CHANGED
@@ -2958,52 +2958,67 @@ function waitForDevToolsUrl(child, timeoutMs = 5e3) {
2958
2958
  });
2959
2959
  }
2960
2960
  async function captureScreenshot(opts) {
2961
- const userDataDir = (0, import_node_fs6.mkdtempSync)(import_node_path4.default.join(import_node_os5.default.tmpdir(), "mcp-use-chrome-"));
2962
- const chromeArgs = [
2963
- "--headless=new",
2964
- "--remote-debugging-port=0",
2965
- `--user-data-dir=${userDataDir}`,
2966
- "--no-first-run",
2967
- "--no-default-browser-check",
2968
- "--disable-extensions",
2969
- "--disable-gpu",
2970
- "--hide-scrollbars",
2971
- "--mute-audio",
2972
- `--window-size=${opts.width},${opts.height}`,
2973
- "about:blank"
2974
- ];
2975
- const child = (0, import_node_child_process8.spawn)(opts.chromePath, chromeArgs, {
2976
- stdio: ["ignore", "pipe", "pipe"]
2977
- });
2978
- child.stdout?.resume();
2961
+ let userDataDir;
2962
+ let child;
2979
2963
  let cdp;
2980
2964
  let cleanedUp = false;
2981
2965
  const cleanup = () => {
2982
2966
  if (cleanedUp) return;
2983
2967
  cleanedUp = true;
2984
2968
  cdp?.close();
2985
- if (!child.killed) {
2969
+ if (child && !child.killed) {
2986
2970
  try {
2987
2971
  child.kill("SIGTERM");
2988
2972
  } catch {
2989
2973
  }
2974
+ const localChild = child;
2990
2975
  const killTimer = setTimeout(() => {
2991
- if (!child.killed) {
2976
+ if (!localChild.killed) {
2992
2977
  try {
2993
- child.kill("SIGKILL");
2978
+ localChild.kill("SIGKILL");
2994
2979
  } catch {
2995
2980
  }
2996
2981
  }
2997
2982
  }, 2e3);
2998
2983
  killTimer.unref();
2999
2984
  }
3000
- try {
3001
- (0, import_node_fs6.rmSync)(userDataDir, { recursive: true, force: true });
3002
- } catch {
2985
+ if (userDataDir) {
2986
+ try {
2987
+ (0, import_node_fs6.rmSync)(userDataDir, { recursive: true, force: true });
2988
+ } catch {
2989
+ }
3003
2990
  }
3004
2991
  };
3005
2992
  try {
3006
- const wsUrl = await waitForDevToolsUrl(child);
2993
+ let wsUrl;
2994
+ if (opts.cdpUrl) {
2995
+ wsUrl = opts.cdpUrl;
2996
+ } else {
2997
+ if (!opts.chromePath) {
2998
+ throw new Error(
2999
+ "captureScreenshot requires either `cdpUrl` or `chromePath`"
3000
+ );
3001
+ }
3002
+ userDataDir = (0, import_node_fs6.mkdtempSync)(import_node_path4.default.join(import_node_os5.default.tmpdir(), "mcp-use-chrome-"));
3003
+ const chromeArgs = [
3004
+ "--headless=new",
3005
+ "--remote-debugging-port=0",
3006
+ `--user-data-dir=${userDataDir}`,
3007
+ "--no-first-run",
3008
+ "--no-default-browser-check",
3009
+ "--disable-extensions",
3010
+ "--disable-gpu",
3011
+ "--hide-scrollbars",
3012
+ "--mute-audio",
3013
+ `--window-size=${opts.width},${opts.height}`,
3014
+ "about:blank"
3015
+ ];
3016
+ child = (0, import_node_child_process8.spawn)(opts.chromePath, chromeArgs, {
3017
+ stdio: ["ignore", "pipe", "pipe"]
3018
+ });
3019
+ child.stdout?.resume();
3020
+ wsUrl = await waitForDevToolsUrl(child);
3021
+ }
3007
3022
  const ws = new import_ws.default(wsUrl);
3008
3023
  await new Promise((resolve2, reject) => {
3009
3024
  const onOpen = () => {
@@ -3018,14 +3033,47 @@ async function captureScreenshot(opts) {
3018
3033
  ws.once("error", onError);
3019
3034
  });
3020
3035
  cdp = new CdpClient(ws);
3021
- const { targetId } = await cdp.send(
3022
- "Target.createTarget",
3023
- { url: "about:blank" }
3024
- );
3025
- const { sessionId } = await cdp.send(
3026
- "Target.attachToTarget",
3027
- { targetId, flatten: true }
3028
- );
3036
+ let sessionId;
3037
+ if (opts.cdpUrl) {
3038
+ const attachPromise = new Promise((resolve2, reject) => {
3039
+ const timer = setTimeout(
3040
+ () => reject(
3041
+ new Error(
3042
+ "Timed out waiting for Target.attachedToTarget event from remote CDP"
3043
+ )
3044
+ ),
3045
+ 1e4
3046
+ );
3047
+ const onMessage = (data) => {
3048
+ try {
3049
+ const msg = JSON.parse(data.toString());
3050
+ if (msg.method === "Target.attachedToTarget" && msg.params?.targetInfo?.type === "page" && typeof msg.params.sessionId === "string") {
3051
+ clearTimeout(timer);
3052
+ ws.off("message", onMessage);
3053
+ resolve2(msg.params.sessionId);
3054
+ }
3055
+ } catch {
3056
+ }
3057
+ };
3058
+ ws.on("message", onMessage);
3059
+ });
3060
+ await cdp.send("Target.setAutoAttach", {
3061
+ autoAttach: true,
3062
+ waitForDebuggerOnStart: false,
3063
+ flatten: true
3064
+ });
3065
+ sessionId = await attachPromise;
3066
+ } else {
3067
+ const { targetId } = await cdp.send(
3068
+ "Target.createTarget",
3069
+ { url: "about:blank" }
3070
+ );
3071
+ const attach = await cdp.send(
3072
+ "Target.attachToTarget",
3073
+ { targetId, flatten: true }
3074
+ );
3075
+ sessionId = attach.sessionId;
3076
+ }
3029
3077
  await cdp.send("Page.enable", {}, sessionId);
3030
3078
  await cdp.send(
3031
3079
  "Emulation.setDeviceMetricsOverride",
@@ -3205,7 +3253,7 @@ async function captureToolScreenshot(inputs, options = {}) {
3205
3253
  const theme = options.theme ?? "light";
3206
3254
  const timeoutMs = options.timeoutMs ?? 3e4;
3207
3255
  const delayMs = options.delayMs ?? 0;
3208
- const chromePath = resolveChromePath();
3256
+ const chromePath = options.cdpUrl ? void 0 : resolveChromePath();
3209
3257
  const view = extractViewName(inputs.resourceUri);
3210
3258
  const devOptions = {
3211
3259
  width: String(width),
@@ -3241,6 +3289,7 @@ async function captureToolScreenshot(inputs, options = {}) {
3241
3289
  timeoutMs,
3242
3290
  outputPath,
3243
3291
  chromePath,
3292
+ cdpUrl: options.cdpUrl,
3244
3293
  delayMs: Number.isFinite(delayMs) && delayMs > 0 ? delayMs : 0,
3245
3294
  bundle
3246
3295
  });
@@ -3501,7 +3550,8 @@ async function screenshotCommand(options, argsList) {
3501
3550
  delayMs,
3502
3551
  timeoutMs: navTimeout,
3503
3552
  inspector: options.inspector,
3504
- quiet: options.quiet
3553
+ quiet: options.quiet,
3554
+ cdpUrl: options.cdpUrl
3505
3555
  }
3506
3556
  );
3507
3557
  console.log(
@@ -3547,7 +3597,10 @@ function createScreenshotCommand() {
3547
3597
  "--delay <ms>",
3548
3598
  "Extra wait after readiness, to let chart animations / async layouts settle.",
3549
3599
  "0"
3550
- ).option("--timeout <ms>", "Navigation + readiness timeout in ms.", "30000").option("--quiet", "Suppress dev-server output.").action(async (args, opts) => {
3600
+ ).option("--timeout <ms>", "Navigation + readiness timeout in ms.", "30000").option(
3601
+ "--cdp-url <url>",
3602
+ "Connect to an existing CDP WebSocket (ws:// or wss://) instead of spawning local Chrome. Useful for hosted browsers like Notte."
3603
+ ).option("--quiet", "Suppress dev-server output.").action(async (args, opts) => {
3551
3604
  await screenshotCommand(opts, args);
3552
3605
  });
3553
3606
  }