@mcp-use/cli 3.5.2-canary.8 → 3.5.2-canary.9

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
@@ -4031,6 +4031,71 @@ async function describeToolCommand(name, toolName) {
4031
4031
  }
4032
4032
  await cleanupAndExit(0);
4033
4033
  }
4034
+ async function processToolScreenshot(session, toolName, args, callResult, options) {
4035
+ const toolWithMeta = session.tools.find((t) => t.name === toolName);
4036
+ const resourceUri = detectToolResourceUri(toolWithMeta);
4037
+ const wantsScreenshot = options?.screenshot === true || options?.screenshotOutput !== void 0 || options?.screenshotDeviceScaleFactor !== void 0;
4038
+ let screenshot = null;
4039
+ let screenshotError = null;
4040
+ let widgetHintUri = null;
4041
+ if (resourceUri) {
4042
+ if (wantsScreenshot) {
4043
+ console.error(
4044
+ formatInfo(`Capturing widget screenshot (${resourceUri})...`)
4045
+ );
4046
+ try {
4047
+ const screenshotOpts = {};
4048
+ if (options?.screenshotOutput) {
4049
+ screenshotOpts.output = options.screenshotOutput;
4050
+ }
4051
+ if (options?.screenshotDeviceScaleFactor) {
4052
+ screenshotOpts.deviceScaleFactor = parseDeviceScaleFactor(
4053
+ options.screenshotDeviceScaleFactor
4054
+ );
4055
+ }
4056
+ const shot = await captureToolScreenshot(
4057
+ {
4058
+ session,
4059
+ toolName,
4060
+ toolArgs: args,
4061
+ toolOutput: callResult,
4062
+ resourceUri
4063
+ },
4064
+ screenshotOpts
4065
+ );
4066
+ screenshot = {
4067
+ path: shot.outputPath,
4068
+ width: shot.width,
4069
+ height: shot.height,
4070
+ view: shot.view
4071
+ };
4072
+ } catch (err) {
4073
+ screenshotError = err?.message ?? String(err);
4074
+ }
4075
+ } else {
4076
+ widgetHintUri = resourceUri;
4077
+ }
4078
+ }
4079
+ if (screenshot) {
4080
+ console.error(
4081
+ formatSuccess(
4082
+ `Saved widget screenshot: ${screenshot.path} (${screenshot.width}\xD7${screenshot.height})`
4083
+ )
4084
+ );
4085
+ }
4086
+ if (screenshotError) {
4087
+ console.error(
4088
+ formatWarning(`Skipped widget screenshot: ${screenshotError}`)
4089
+ );
4090
+ }
4091
+ if (widgetHintUri) {
4092
+ console.error(
4093
+ formatInfo(
4094
+ `This tool renders a widget (${widgetHintUri}). Re-run with --screenshot to save a PNG of it.`
4095
+ )
4096
+ );
4097
+ }
4098
+ }
4034
4099
  async function callToolCommand(name, toolName, argsList, options) {
4035
4100
  try {
4036
4101
  const result = await getOrRestoreSession(name);
@@ -4080,74 +4145,12 @@ async function callToolCommand(name, toolName, argsList, options) {
4080
4145
  const callResult = await session.callTool(toolName, args, {
4081
4146
  timeout: options?.timeout
4082
4147
  });
4083
- const toolWithMeta = session.tools.find((t) => t.name === toolName);
4084
- const resourceUri = detectToolResourceUri(toolWithMeta);
4085
- const wantsScreenshot = options?.screenshot === true || options?.screenshotOutput !== void 0 || options?.screenshotDeviceScaleFactor !== void 0;
4086
- let screenshot = null;
4087
- let screenshotError = null;
4088
- let widgetHintUri = null;
4089
- if (resourceUri) {
4090
- if (wantsScreenshot) {
4091
- console.error(
4092
- formatInfo(`Capturing widget screenshot (${resourceUri})...`)
4093
- );
4094
- try {
4095
- const screenshotOpts = {};
4096
- if (options?.screenshotOutput) {
4097
- screenshotOpts.output = options.screenshotOutput;
4098
- }
4099
- if (options?.screenshotDeviceScaleFactor) {
4100
- screenshotOpts.deviceScaleFactor = parseDeviceScaleFactor(
4101
- options.screenshotDeviceScaleFactor
4102
- );
4103
- }
4104
- const shot = await captureToolScreenshot(
4105
- {
4106
- session,
4107
- toolName,
4108
- toolArgs: args,
4109
- toolOutput: callResult,
4110
- resourceUri
4111
- },
4112
- screenshotOpts
4113
- );
4114
- screenshot = {
4115
- path: shot.outputPath,
4116
- width: shot.width,
4117
- height: shot.height,
4118
- view: shot.view
4119
- };
4120
- } catch (err) {
4121
- screenshotError = err?.message ?? String(err);
4122
- }
4123
- } else {
4124
- widgetHintUri = resourceUri;
4125
- }
4126
- }
4148
+ await processToolScreenshot(session, toolName, args, callResult, options);
4127
4149
  if (options?.json) {
4128
4150
  console.log(formatJson(callResult));
4129
4151
  } else {
4130
4152
  console.log(formatToolCall(callResult));
4131
4153
  }
4132
- if (screenshot) {
4133
- console.error(
4134
- formatSuccess(
4135
- `Saved widget screenshot: ${screenshot.path} (${screenshot.width}\xD7${screenshot.height})`
4136
- )
4137
- );
4138
- }
4139
- if (screenshotError) {
4140
- console.error(
4141
- formatWarning(`Skipped widget screenshot: ${screenshotError}`)
4142
- );
4143
- }
4144
- if (widgetHintUri) {
4145
- console.error(
4146
- formatInfo(
4147
- `This tool renders a widget (${widgetHintUri}). Re-run with --screenshot to save a PNG of it.`
4148
- )
4149
- );
4150
- }
4151
4154
  if (callResult.isError) {
4152
4155
  await cleanupAndExit(1);
4153
4156
  }
@@ -4377,7 +4380,7 @@ async function interactiveCommand(name) {
4377
4380
  console.log(source_default.gray(" tools list - List available tools"));
4378
4381
  console.log(
4379
4382
  source_default.gray(
4380
- " tools call <name> - Call a tool (will prompt for args)"
4383
+ " tools call <name> [--screenshot] - Call a tool (will prompt for args)"
4381
4384
  )
4382
4385
  );
4383
4386
  console.log(source_default.gray(" tools describe <name> - Show tool details"));
@@ -4424,6 +4427,7 @@ async function interactiveCommand(name) {
4424
4427
  )
4425
4428
  );
4426
4429
  } else if (command === "call" && arg) {
4430
+ const wantsScreenshot = parts.includes("--screenshot");
4427
4431
  rl.question(
4428
4432
  "Arguments (JSON, or press Enter for none): ",
4429
4433
  async (argsInput) => {
@@ -4431,6 +4435,9 @@ async function interactiveCommand(name) {
4431
4435
  const args = argsInput.trim() ? JSON.parse(argsInput) : {};
4432
4436
  const result2 = await session.callTool(arg, args);
4433
4437
  console.log(formatToolCall(result2));
4438
+ await processToolScreenshot(session, arg, args, result2, {
4439
+ screenshot: wantsScreenshot
4440
+ });
4434
4441
  } catch (error) {
4435
4442
  console.error(formatError(error.message));
4436
4443
  }