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

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
@@ -3227,6 +3227,31 @@ function resolveChromePath() {
3227
3227
  }
3228
3228
 
3229
3229
  // src/commands/screenshot.ts
3230
+ function parseHeaderArg(raw) {
3231
+ const idx = raw.indexOf(":");
3232
+ if (idx === -1) {
3233
+ throw new Error(
3234
+ `Invalid --header value "${raw}". Expected "Key: Value" (e.g. "Authorization: Bearer xyz").`
3235
+ );
3236
+ }
3237
+ const key = raw.slice(0, idx).trim();
3238
+ const value = raw.slice(idx + 1).trim();
3239
+ if (!key) {
3240
+ throw new Error(`Invalid --header value "${raw}". Header name is empty.`);
3241
+ }
3242
+ return [key, value];
3243
+ }
3244
+ function parseHeaderArgs(args) {
3245
+ const headers = {};
3246
+ for (const raw of args) {
3247
+ const [key, value] = parseHeaderArg(raw);
3248
+ headers[key] = value;
3249
+ }
3250
+ return headers;
3251
+ }
3252
+ function collectHeader(value, previous = []) {
3253
+ return previous.concat([value]);
3254
+ }
3230
3255
  function detectToolResourceUri(tool) {
3231
3256
  if (!tool) return null;
3232
3257
  const meta = tool._meta;
@@ -3422,7 +3447,7 @@ function parseDimension(raw, name) {
3422
3447
  return n;
3423
3448
  }
3424
3449
  var AD_HOC_SESSION_NAME = "__screenshot_ad_hoc__";
3425
- async function resolveSessionForScreenshot(options) {
3450
+ async function resolveSessionForScreenshot(options, headers) {
3426
3451
  if (options.session) {
3427
3452
  const result2 = await getOrRestoreSession(options.session);
3428
3453
  return result2?.session ?? null;
@@ -3431,6 +3456,7 @@ async function resolveSessionForScreenshot(options) {
3431
3456
  const client = new MCPClient2();
3432
3457
  client.addServer(AD_HOC_SESSION_NAME, {
3433
3458
  url: options.mcp,
3459
+ ...headers ? { headers } : {},
3434
3460
  clientInfo: getCliClientInfo()
3435
3461
  });
3436
3462
  try {
@@ -3458,6 +3484,27 @@ async function screenshotCommand(options, argsList) {
3458
3484
  exitCode = 1;
3459
3485
  return;
3460
3486
  }
3487
+ let headers;
3488
+ if (options.header && options.header.length > 0) {
3489
+ if (!options.mcp) {
3490
+ console.error(
3491
+ formatError(
3492
+ "--header is only supported with --mcp <url>. Saved sessions (use --session) carry their own auth from `mcp-use client connect`."
3493
+ )
3494
+ );
3495
+ exitCode = 1;
3496
+ return;
3497
+ }
3498
+ try {
3499
+ headers = parseHeaderArgs(options.header);
3500
+ } catch (err) {
3501
+ console.error(
3502
+ formatError(err instanceof Error ? err.message : String(err))
3503
+ );
3504
+ exitCode = 1;
3505
+ return;
3506
+ }
3507
+ }
3461
3508
  try {
3462
3509
  resolveChromePath();
3463
3510
  } catch (err) {
@@ -3471,7 +3518,7 @@ async function screenshotCommand(options, argsList) {
3471
3518
  const height = parseDimension(options.height, "height");
3472
3519
  const navTimeout = parseInt(options.timeout, 10) || 3e4;
3473
3520
  const delayMs = options.delay ? parseInt(options.delay, 10) : 0;
3474
- const session = await resolveSessionForScreenshot(options);
3521
+ const session = await resolveSessionForScreenshot(options, headers);
3475
3522
  if (!session) {
3476
3523
  exitCode = 1;
3477
3524
  return;
@@ -3569,7 +3616,12 @@ function createScreenshotCommand() {
3569
3616
  "Saved session name (from `mcp-use client connect`). Defaults to the active session."
3570
3617
  ).option(
3571
3618
  "--mcp <url>",
3572
- "Ad-hoc MCP server URL (escape hatch). Used only when no --session and no active saved session. No authentication."
3619
+ "Ad-hoc MCP server URL (escape hatch). Used only when no --session and no active saved session. No authentication unless --header is supplied."
3620
+ ).option(
3621
+ "-H, --header <header>",
3622
+ '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.',
3623
+ collectHeader,
3624
+ []
3573
3625
  ).option(
3574
3626
  "--theme <light|dark>",
3575
3627
  "Color scheme to render the view in.",