@mcp-use/cli 3.2.0-canary.10 → 3.2.0-canary.12

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
@@ -2866,7 +2866,7 @@ async function captureScreenshot(opts) {
2866
2866
  {
2867
2867
  width: opts.width,
2868
2868
  height: opts.height,
2869
- deviceScaleFactor: 1,
2869
+ deviceScaleFactor: opts.deviceScaleFactor ?? 1,
2870
2870
  mobile: false
2871
2871
  },
2872
2872
  sessionId
@@ -3101,7 +3101,8 @@ async function captureToolScreenshot(inputs, options = {}) {
3101
3101
  chromePath,
3102
3102
  cdpUrl: options.cdpUrl,
3103
3103
  delayMs: Number.isFinite(delayMs) && delayMs > 0 ? delayMs : 0,
3104
- bundle
3104
+ bundle,
3105
+ deviceScaleFactor: options.deviceScaleFactor
3105
3106
  });
3106
3107
  return { outputPath, width, height, view };
3107
3108
  } finally {
@@ -3244,10 +3245,24 @@ function parseDimension(raw, name) {
3244
3245
  }
3245
3246
  return n;
3246
3247
  }
3248
+ function parseDeviceScaleFactor(raw) {
3249
+ const n = parseFloat(raw);
3250
+ if (!Number.isFinite(n) || n <= 0) {
3251
+ throw new Error(
3252
+ `--device-scale-factor must be a positive number (got "${raw}")`
3253
+ );
3254
+ }
3255
+ if (n > 4) {
3256
+ throw new Error(
3257
+ `--device-scale-factor must be <= 4 to avoid excessive pixel counts (got "${raw}")`
3258
+ );
3259
+ }
3260
+ return n;
3261
+ }
3247
3262
  var AD_HOC_SESSION_NAME = "__screenshot_ad_hoc__";
3248
- async function resolveSessionForScreenshot(options, headers) {
3249
- if (options.session) {
3250
- const result = await getOrRestoreSession(options.session);
3263
+ async function resolveSessionForScreenshot(options, sessionName, headers) {
3264
+ if (sessionName) {
3265
+ const result = await getOrRestoreSession(sessionName);
3251
3266
  return result?.session ?? null;
3252
3267
  }
3253
3268
  if (options.mcp) {
@@ -3269,12 +3284,12 @@ async function resolveSessionForScreenshot(options, headers) {
3269
3284
  }
3270
3285
  console.error(
3271
3286
  formatError(
3272
- "No MCP target. Pass --session <name> (a saved server) or --mcp <url> (ad-hoc)."
3287
+ "No MCP target. Pass --mcp <url> for an ad-hoc connection, or use `mcp-use client <name> screenshot` for a saved server."
3273
3288
  )
3274
3289
  );
3275
3290
  return null;
3276
3291
  }
3277
- async function screenshotCommand(options, argsList) {
3292
+ async function screenshotCommand(options, argsList, context) {
3278
3293
  let exitCode = 0;
3279
3294
  try {
3280
3295
  if (!options.tool) {
@@ -3291,7 +3306,7 @@ async function screenshotCommand(options, argsList) {
3291
3306
  if (!options.mcp) {
3292
3307
  console.error(
3293
3308
  formatError(
3294
- "--header is only supported with --mcp <url>. Saved sessions (use --session) carry their own auth from `mcp-use client connect`."
3309
+ "--header is only supported with --mcp <url>. Saved servers carry their own auth from `mcp-use client connect`."
3295
3310
  )
3296
3311
  );
3297
3312
  exitCode = 1;
@@ -3320,7 +3335,12 @@ async function screenshotCommand(options, argsList) {
3320
3335
  const height = parseDimension(options.height, "height");
3321
3336
  const navTimeout = parseInt(options.timeout, 10) || 3e4;
3322
3337
  const delayMs = options.delay ? parseInt(options.delay, 10) : 0;
3323
- const session = await resolveSessionForScreenshot(options, headers);
3338
+ const deviceScaleFactor = options.deviceScaleFactor ? parseDeviceScaleFactor(options.deviceScaleFactor) : void 0;
3339
+ const session = await resolveSessionForScreenshot(
3340
+ options,
3341
+ context.sessionName,
3342
+ headers
3343
+ );
3324
3344
  if (!session) {
3325
3345
  exitCode = 1;
3326
3346
  return;
@@ -3351,13 +3371,13 @@ async function screenshotCommand(options, argsList) {
3351
3371
  console.log("");
3352
3372
  console.log(formatInfo("Usage:"));
3353
3373
  console.log(
3354
- ` npx mcp-use screenshot --tool ${options.tool} key=value [key2=value2 ...]`
3374
+ ` npx ${context.usagePrefix} --tool ${options.tool} key=value [key2=value2 ...]`
3355
3375
  );
3356
3376
  console.log(
3357
- ` npx mcp-use screenshot --tool ${options.tool} nested:='{"a":1}' # JSON value`
3377
+ ` npx ${context.usagePrefix} --tool ${options.tool} nested:='{"a":1}' # JSON value`
3358
3378
  );
3359
3379
  console.log(
3360
- ` npx mcp-use screenshot --tool ${options.tool} '{"key":"value"}' # full JSON object`
3380
+ ` npx ${context.usagePrefix} --tool ${options.tool} '{"key":"value"}' # full JSON object`
3361
3381
  );
3362
3382
  if (tool.inputSchema) {
3363
3383
  console.log("");
@@ -3387,7 +3407,8 @@ async function screenshotCommand(options, argsList) {
3387
3407
  timeoutMs: navTimeout,
3388
3408
  inspector: options.inspector,
3389
3409
  quiet: options.quiet,
3390
- cdpUrl: options.cdpUrl
3410
+ cdpUrl: options.cdpUrl,
3411
+ deviceScaleFactor
3391
3412
  }
3392
3413
  );
3393
3414
  console.log(
@@ -3401,29 +3422,19 @@ async function screenshotCommand(options, argsList) {
3401
3422
  await cleanupAndExit(exitCode);
3402
3423
  }
3403
3424
  }
3404
- function createScreenshotCommand() {
3405
- return new Command("screenshot").description(
3406
- "Render an MCP Apps view headlessly and save a PNG by calling a tool and rendering its UI resource with the result."
3407
- ).argument(
3425
+ function withCommonScreenshotOptions(cmd) {
3426
+ return cmd.argument(
3408
3427
  "[args...]",
3409
3428
  "Tool args as key=value pairs (use key:=<json> for nested values, or pass a single JSON object)."
3410
3429
  ).option(
3411
3430
  "--tool <name>",
3412
3431
  "Tool to call. Its UI resource is rendered with the result."
3413
3432
  ).option("--width <px>", "Browser viewport width in pixels.", "800").option("--height <px>", "Browser viewport height in pixels.", "600").option(
3414
- "--inspector <url>",
3415
- "Inspector host that serves /inspector/preview/:view. When omitted, probes localhost:3000 then auto-spawns `mcp-use dev`."
3416
- ).option(
3417
- "--session <name>",
3418
- "Saved server name (from `mcp-use client connect <name> <url>`)."
3433
+ "--device-scale-factor <n>",
3434
+ "Device pixel ratio for rendering (e.g. 2 for Retina). Output PNG is (width \xD7 dsf) \xD7 (height \xD7 dsf). Must be > 0 and <= 4."
3419
3435
  ).option(
3420
- "--mcp <url>",
3421
- "Ad-hoc MCP server URL (escape hatch). Use when you don't have a saved server. No authentication unless --header is supplied."
3422
- ).option(
3423
- "-H, --header <header>",
3424
- 'HTTP header to send to the --mcp <url> server, formatted "Key: Value". Repeatable. Use to pass an Authorization bearer token or other auth headers when screenshotting an authenticated MCP server.',
3425
- collectHeader,
3426
- []
3436
+ "--inspector <url>",
3437
+ "Inspector host that serves /inspector/preview/:view. When omitted, auto-spawns `@mcp-use/inspector` on a free port."
3427
3438
  ).option(
3428
3439
  "--theme <light|dark>",
3429
3440
  "Color scheme to render the view in.",
@@ -3441,9 +3452,42 @@ function createScreenshotCommand() {
3441
3452
  ).option("--timeout <ms>", "Navigation + readiness timeout in ms.", "30000").option(
3442
3453
  "--cdp-url <url>",
3443
3454
  "Connect to an existing CDP WebSocket (ws:// or wss://) instead of spawning local Chrome. Useful for hosted browsers like Notte."
3444
- ).option("--quiet", "Suppress dev-server output.").action(async (args, opts) => {
3445
- await screenshotCommand(opts, args);
3455
+ ).option("--quiet", "Suppress dev-server output.");
3456
+ }
3457
+ function createClientScreenshotCommand() {
3458
+ const cmd = withCommonScreenshotOptions(
3459
+ new Command("screenshot").description(
3460
+ "Render an MCP Apps view headlessly and save a PNG. Connects to an MCP server inline via --mcp; for a saved server, use `mcp-use client <name> screenshot`."
3461
+ )
3462
+ ).option(
3463
+ "--mcp <url>",
3464
+ "Ad-hoc MCP server URL. Required for the top-level form. No authentication unless --header is supplied."
3465
+ ).option(
3466
+ "-H, --header <header>",
3467
+ 'HTTP header to send to the --mcp <url> server, formatted "Key: Value". Repeatable. Use to pass an Authorization bearer token or other auth headers when screenshotting an authenticated MCP server.',
3468
+ collectHeader,
3469
+ []
3470
+ );
3471
+ cmd.action(async (args, opts) => {
3472
+ await screenshotCommand(opts, args, {
3473
+ usagePrefix: "mcp-use client screenshot"
3474
+ });
3446
3475
  });
3476
+ return cmd;
3477
+ }
3478
+ function createPerClientScreenshotCommand(name) {
3479
+ const cmd = withCommonScreenshotOptions(
3480
+ new Command("screenshot").description(
3481
+ `Render an MCP Apps view headlessly using the saved server '${name}'.`
3482
+ )
3483
+ );
3484
+ cmd.action(async (args, opts) => {
3485
+ await screenshotCommand(opts, args, {
3486
+ sessionName: name,
3487
+ usagePrefix: `mcp-use client ${name} screenshot`
3488
+ });
3489
+ });
3490
+ return cmd;
3447
3491
  }
3448
3492
 
3449
3493
  // src/commands/client.ts
@@ -3451,6 +3495,7 @@ var RESERVED_CLIENT_SUBCOMMANDS = /* @__PURE__ */ new Set([
3451
3495
  "connect",
3452
3496
  "list",
3453
3497
  "remove",
3498
+ "screenshot",
3454
3499
  "help"
3455
3500
  ]);
3456
3501
  var PER_CLIENT_SCOPES = /* @__PURE__ */ new Set([
@@ -3459,7 +3504,8 @@ var PER_CLIENT_SCOPES = /* @__PURE__ */ new Set([
3459
3504
  "prompts",
3460
3505
  "auth",
3461
3506
  "disconnect",
3462
- "interactive"
3507
+ "interactive",
3508
+ "screenshot"
3463
3509
  ]);
3464
3510
  async function connectCommand(name, urlOrCommand, options) {
3465
3511
  if (!name || !urlOrCommand) {
@@ -3864,6 +3910,15 @@ async function callToolCommand(name, toolName, argsList, options) {
3864
3910
  formatInfo(`Capturing widget screenshot (${resourceUri})...`)
3865
3911
  );
3866
3912
  try {
3913
+ const screenshotOpts = {};
3914
+ if (options?.screenshotOutput) {
3915
+ screenshotOpts.output = options.screenshotOutput;
3916
+ }
3917
+ if (options?.screenshotDeviceScaleFactor) {
3918
+ screenshotOpts.deviceScaleFactor = parseDeviceScaleFactor(
3919
+ options.screenshotDeviceScaleFactor
3920
+ );
3921
+ }
3867
3922
  const shot = await captureToolScreenshot(
3868
3923
  {
3869
3924
  session,
@@ -3872,7 +3927,7 @@ async function callToolCommand(name, toolName, argsList, options) {
3872
3927
  toolOutput: callResult,
3873
3928
  resourceUri
3874
3929
  },
3875
- options?.screenshotOutput ? { output: options.screenshotOutput } : {}
3930
+ screenshotOpts
3876
3931
  );
3877
3932
  screenshot = {
3878
3933
  path: shot.outputPath,
@@ -4297,6 +4352,7 @@ function createClientCommand() {
4297
4352
  clientCommand.command("remove <name>").description(
4298
4353
  "Remove a saved server. Also clears any OAuth tokens for that URL, unless another saved server still uses it."
4299
4354
  ).action(removeClientCommand);
4355
+ clientCommand.addCommand(createClientScreenshotCommand());
4300
4356
  return clientCommand;
4301
4357
  }
4302
4358
  function createPerClientCommand(name) {
@@ -4317,6 +4373,9 @@ function createPerClientCommand(name) {
4317
4373
  ).option(
4318
4374
  "--screenshot-output <path>",
4319
4375
  "Output PNG path for the widget screenshot (defaults to ./<view>-<timestamp>.png)"
4376
+ ).option(
4377
+ "--screenshot-device-scale-factor <n>",
4378
+ "Device pixel ratio for the auto-screenshot (e.g. 2 for Retina). Defaults to 1."
4320
4379
  ).action(
4321
4380
  (tool, args, options) => callToolCommand(name, tool, args, options)
4322
4381
  );
@@ -4347,6 +4406,7 @@ function createPerClientCommand(name) {
4347
4406
  authCommand.command("refresh").description("Force-refresh the OAuth access token").action(() => authRefreshCommand(name));
4348
4407
  authCommand.command("logout").description("Remove stored OAuth tokens for this server's URL").action(() => authLogoutCommand(name));
4349
4408
  cmd.addCommand(authCommand);
4409
+ cmd.addCommand(createPerClientScreenshotCommand(name));
4350
4410
  return cmd;
4351
4411
  }
4352
4412
 
@@ -9208,7 +9268,6 @@ program.addCommand(createClientCommand());
9208
9268
  program.addCommand(createDeploymentsCommand());
9209
9269
  program.addCommand(createServersCommand());
9210
9270
  program.addCommand(createSkillsCommand());
9211
- program.addCommand(createScreenshotCommand());
9212
9271
  program.command("generate-types").description(
9213
9272
  "Generate TypeScript type definitions for tools (writes .mcp-use/tool-registry.d.ts)"
9214
9273
  ).option("-p, --path <path>", "Path to project directory", process.cwd()).option("--server <file>", "Server entry file", "index.ts").action(async (options) => {