@mcp-use/cli 3.1.0-canary.4 → 3.1.0-canary.5

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
@@ -1508,6 +1508,28 @@ var McpUseAPI = class _McpUseAPI {
1508
1508
  }
1509
1509
  };
1510
1510
 
1511
+ // src/utils/errors.ts
1512
+ function handleCommandError(error, context) {
1513
+ if (error instanceof ApiUnauthorizedError) {
1514
+ console.error(
1515
+ source_default.red("\n\u2717 Your session has expired or your API key is invalid.")
1516
+ );
1517
+ console.error(
1518
+ source_default.gray(
1519
+ `Run ${source_default.white("npx mcp-use login")} to re-authenticate.
1520
+ `
1521
+ )
1522
+ );
1523
+ process.exit(1);
1524
+ }
1525
+ console.error(
1526
+ source_default.red.bold(`
1527
+ \u2717 ${context}:`),
1528
+ source_default.red(error instanceof Error ? error.message : "Unknown error")
1529
+ );
1530
+ process.exit(1);
1531
+ }
1532
+
1511
1533
  // src/commands/auth.ts
1512
1534
  var DEVICE_CLIENT_ID = "mcp-use-cli";
1513
1535
  var DEVICE_POLL_TIMEOUT = 18e5;
@@ -1636,14 +1658,32 @@ async function loginCommand(options) {
1636
1658
  return;
1637
1659
  }
1638
1660
  if (await isLoggedIn()) {
1661
+ let needsReauth = false;
1662
+ try {
1663
+ await (await McpUseAPI.create()).testAuth();
1664
+ } catch (e) {
1665
+ if (e instanceof ApiUnauthorizedError) {
1666
+ needsReauth = true;
1667
+ }
1668
+ }
1669
+ if (!needsReauth) {
1670
+ if (!options?.silent) {
1671
+ console.log(
1672
+ source_default.yellow(
1673
+ "You are already logged in. Run 'npx mcp-use logout' first if you want to login with a different account."
1674
+ )
1675
+ );
1676
+ }
1677
+ return;
1678
+ }
1639
1679
  if (!options?.silent) {
1640
1680
  console.log(
1641
1681
  source_default.yellow(
1642
- "You are already logged in. Run 'npx mcp-use logout' first if you want to login with a different account."
1682
+ "\u26A0\uFE0F Stored credentials are invalid or expired. Re-authenticating..."
1643
1683
  )
1644
1684
  );
1645
1685
  }
1646
- return;
1686
+ await deleteConfig();
1647
1687
  }
1648
1688
  console.log(source_default.cyan.bold("Logging in to mcp-use cloud...\n"));
1649
1689
  const authBaseUrl = await getAuthBaseUrl();
@@ -1810,21 +1850,7 @@ async function whoamiCommand() {
1810
1850
  }
1811
1851
  }
1812
1852
  } catch (error) {
1813
- if (error?.status === 401) {
1814
- console.error(
1815
- source_default.red("\nYour session has expired or your API key is invalid.")
1816
- );
1817
- console.log(
1818
- source_default.gray(`Run ${source_default.white("mcp-use login")} to re-authenticate.
1819
- `)
1820
- );
1821
- } else {
1822
- console.error(
1823
- source_default.red.bold("\n\u2717 Failed to get user info:"),
1824
- source_default.red(error instanceof Error ? error.message : "Unknown error")
1825
- );
1826
- }
1827
- process.exit(1);
1853
+ handleCommandError(error, "Failed to get user info");
1828
1854
  }
1829
1855
  }
1830
1856
 
@@ -4293,11 +4319,7 @@ async function listDeploymentsCommand() {
4293
4319
  }
4294
4320
  console.log();
4295
4321
  } catch (error) {
4296
- console.error(
4297
- source_default.red.bold("\n\u2717 Failed to list deployments:"),
4298
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4299
- );
4300
- process.exit(1);
4322
+ handleCommandError(error, "Failed to list deployments");
4301
4323
  }
4302
4324
  }
4303
4325
  async function getDeploymentCommand(deploymentId) {
@@ -4359,11 +4381,7 @@ async function getDeploymentCommand(deploymentId) {
4359
4381
  }
4360
4382
  console.log();
4361
4383
  } catch (error) {
4362
- console.error(
4363
- source_default.red.bold("\n\u2717 Failed to get deployment:"),
4364
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4365
- );
4366
- process.exit(1);
4384
+ handleCommandError(error, "Failed to get deployment");
4367
4385
  }
4368
4386
  }
4369
4387
  async function restartDeploymentCommand(deploymentId, options) {
@@ -4434,11 +4452,7 @@ async function restartDeploymentCommand(deploymentId, options) {
4434
4452
  }
4435
4453
  console.log();
4436
4454
  } catch (error) {
4437
- console.error(
4438
- source_default.red.bold("\n\u2717 Failed to restart deployment:"),
4439
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4440
- );
4441
- process.exit(1);
4455
+ handleCommandError(error, "Failed to restart deployment");
4442
4456
  }
4443
4457
  }
4444
4458
  async function deleteDeploymentCommand(deploymentId, options) {
@@ -4481,11 +4495,7 @@ async function deleteDeploymentCommand(deploymentId, options) {
4481
4495
  `)
4482
4496
  );
4483
4497
  } catch (error) {
4484
- console.error(
4485
- source_default.red.bold("\n\u2717 Failed to delete deployment:"),
4486
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4487
- );
4488
- process.exit(1);
4498
+ handleCommandError(error, "Failed to delete deployment");
4489
4499
  }
4490
4500
  }
4491
4501
  async function logsCommand(deploymentId, options) {
@@ -4574,11 +4584,7 @@ async function logsCommand(deploymentId, options) {
4574
4584
  }
4575
4585
  console.log();
4576
4586
  } catch (error) {
4577
- console.error(
4578
- source_default.red.bold("\n\u2717 Failed to get logs:"),
4579
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4580
- );
4581
- process.exit(1);
4587
+ handleCommandError(error, "Failed to get logs");
4582
4588
  }
4583
4589
  }
4584
4590
  async function stopDeploymentCommand(deploymentId) {
@@ -4598,11 +4604,7 @@ async function stopDeploymentCommand(deploymentId) {
4598
4604
  \u2713 Deployment stopped
4599
4605
  `));
4600
4606
  } catch (error) {
4601
- console.error(
4602
- source_default.red.bold("\n\u2717 Failed to stop deployment:"),
4603
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4604
- );
4605
- process.exit(1);
4607
+ handleCommandError(error, "Failed to stop deployment");
4606
4608
  }
4607
4609
  }
4608
4610
  async function startDeploymentCommand(deploymentId) {
@@ -4622,11 +4624,7 @@ async function startDeploymentCommand(deploymentId) {
4622
4624
  )
4623
4625
  );
4624
4626
  } catch (error) {
4625
- console.error(
4626
- source_default.red.bold("\n\u2717 Failed to start deployment:"),
4627
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4628
- );
4629
- process.exit(1);
4627
+ handleCommandError(error, "Failed to start deployment");
4630
4628
  }
4631
4629
  }
4632
4630
  function createDeploymentsCommand() {
@@ -4695,87 +4693,103 @@ async function requireLogin() {
4695
4693
  }
4696
4694
  }
4697
4695
  async function listEnvCommand(options) {
4698
- await requireLogin();
4699
- const api = await McpUseAPI.create();
4700
- const vars = await api.listEnvVariables(options.server);
4701
- if (vars.length === 0) {
4702
- console.log(
4703
- source_default.yellow("\nNo environment variables set for this server.\n")
4704
- );
4705
- return;
4706
- }
4707
- console.log(source_default.cyan.bold(`
4696
+ try {
4697
+ await requireLogin();
4698
+ const api = await McpUseAPI.create();
4699
+ const vars = await api.listEnvVariables(options.server);
4700
+ if (vars.length === 0) {
4701
+ console.log(
4702
+ source_default.yellow("\nNo environment variables set for this server.\n")
4703
+ );
4704
+ return;
4705
+ }
4706
+ console.log(source_default.cyan.bold(`
4708
4707
  Environment Variables (${vars.length})
4709
4708
  `));
4710
- for (const v of vars) {
4711
- printEnvVar(v, options.showValues);
4712
- console.log();
4709
+ for (const v of vars) {
4710
+ printEnvVar(v, options.showValues);
4711
+ console.log();
4712
+ }
4713
+ } catch (error) {
4714
+ handleCommandError(error, "Failed to list environment variables");
4713
4715
  }
4714
4716
  }
4715
4717
  async function addEnvCommand(assignment, options) {
4716
- await requireLogin();
4717
- const eqIdx = assignment.indexOf("=");
4718
- if (eqIdx === -1) {
4719
- console.error(
4720
- source_default.red(
4721
- "\u2717 Expected KEY=VALUE format, e.g. mcp-use servers env add API_KEY=abc123"
4722
- )
4723
- );
4724
- process.exit(1);
4725
- }
4726
- const key = assignment.substring(0, eqIdx).trim();
4727
- const value = assignment.substring(eqIdx + 1);
4728
- if (!key) {
4729
- console.error(source_default.red("\u2717 Key must not be empty."));
4730
- process.exit(1);
4731
- }
4732
- const environments = options.env ? parseEnvironments(options.env) : ALL_ENVS;
4733
- const api = await McpUseAPI.create();
4734
- const created = await api.createEnvVariable(options.server, {
4735
- key,
4736
- value,
4737
- environments,
4738
- sensitive: options.sensitive ?? false
4739
- });
4740
- console.log(
4741
- source_default.green(`
4718
+ try {
4719
+ await requireLogin();
4720
+ const eqIdx = assignment.indexOf("=");
4721
+ if (eqIdx === -1) {
4722
+ console.error(
4723
+ source_default.red(
4724
+ "\u2717 Expected KEY=VALUE format, e.g. mcp-use servers env add API_KEY=abc123"
4725
+ )
4726
+ );
4727
+ process.exit(1);
4728
+ }
4729
+ const key = assignment.substring(0, eqIdx).trim();
4730
+ const value = assignment.substring(eqIdx + 1);
4731
+ if (!key) {
4732
+ console.error(source_default.red("\u2717 Key must not be empty."));
4733
+ process.exit(1);
4734
+ }
4735
+ const environments = options.env ? parseEnvironments(options.env) : ALL_ENVS;
4736
+ const api = await McpUseAPI.create();
4737
+ const created = await api.createEnvVariable(options.server, {
4738
+ key,
4739
+ value,
4740
+ environments,
4741
+ sensitive: options.sensitive ?? false
4742
+ });
4743
+ console.log(
4744
+ source_default.green(`
4742
4745
  \u2713 Environment variable "${created.key}" added.
4743
4746
  `)
4744
- );
4745
- printEnvVar(created, true);
4746
- console.log();
4747
- }
4748
- async function updateEnvCommand(varId, options) {
4749
- await requireLogin();
4750
- if (!options.value && !options.env && options.sensitive === void 0) {
4751
- console.error(
4752
- source_default.red(
4753
- "\u2717 Nothing to update. Provide at least one of --value, --env, --sensitive."
4754
- )
4755
4747
  );
4756
- process.exit(1);
4748
+ printEnvVar(created, true);
4749
+ console.log();
4750
+ } catch (error) {
4751
+ handleCommandError(error, "Failed to add environment variable");
4757
4752
  }
4758
- const body = {};
4759
- if (options.value !== void 0) body.value = options.value;
4760
- if (options.env) body.environments = parseEnvironments(options.env);
4761
- if (options.sensitive !== void 0) body.sensitive = options.sensitive;
4762
- const api = await McpUseAPI.create();
4763
- const updated = await api.updateEnvVariable(options.server, varId, body);
4764
- console.log(
4765
- source_default.green(`
4753
+ }
4754
+ async function updateEnvCommand(varId, options) {
4755
+ try {
4756
+ await requireLogin();
4757
+ if (!options.value && !options.env && options.sensitive === void 0) {
4758
+ console.error(
4759
+ source_default.red(
4760
+ "\u2717 Nothing to update. Provide at least one of --value, --env, --sensitive."
4761
+ )
4762
+ );
4763
+ process.exit(1);
4764
+ }
4765
+ const body = {};
4766
+ if (options.value !== void 0) body.value = options.value;
4767
+ if (options.env) body.environments = parseEnvironments(options.env);
4768
+ if (options.sensitive !== void 0) body.sensitive = options.sensitive;
4769
+ const api = await McpUseAPI.create();
4770
+ const updated = await api.updateEnvVariable(options.server, varId, body);
4771
+ console.log(
4772
+ source_default.green(`
4766
4773
  \u2713 Environment variable "${updated.key}" updated.
4767
4774
  `)
4768
- );
4769
- printEnvVar(updated, !!options.value);
4770
- console.log();
4775
+ );
4776
+ printEnvVar(updated, !!options.value);
4777
+ console.log();
4778
+ } catch (error) {
4779
+ handleCommandError(error, "Failed to update environment variable");
4780
+ }
4771
4781
  }
4772
4782
  async function removeEnvCommand(varId, options) {
4773
- await requireLogin();
4774
- const api = await McpUseAPI.create();
4775
- await api.deleteEnvVariable(options.server, varId);
4776
- console.log(source_default.green(`
4783
+ try {
4784
+ await requireLogin();
4785
+ const api = await McpUseAPI.create();
4786
+ await api.deleteEnvVariable(options.server, varId);
4787
+ console.log(source_default.green(`
4777
4788
  \u2713 Environment variable ${varId} removed.
4778
4789
  `));
4790
+ } catch (error) {
4791
+ handleCommandError(error, "Failed to remove environment variable");
4792
+ }
4779
4793
  }
4780
4794
  function createEnvCommand() {
4781
4795
  const envCommand = new Command3("env").description(
@@ -4905,11 +4919,7 @@ async function listServersCommand(options) {
4905
4919
  }
4906
4920
  console.log();
4907
4921
  } catch (error) {
4908
- console.error(
4909
- source_default.red.bold("\n\u2717 Failed to list servers:"),
4910
- source_default.red(error instanceof Error ? error.message : "Unknown error")
4911
- );
4912
- process.exit(1);
4922
+ handleCommandError(error, "Failed to list servers");
4913
4923
  }
4914
4924
  }
4915
4925
  async function getServerCommand(idOrSlug, options) {
@@ -5009,11 +5019,7 @@ async function getServerCommand(idOrSlug, options) {
5009
5019
  }
5010
5020
  console.log();
5011
5021
  } catch (error) {
5012
- console.error(
5013
- source_default.red.bold("\n\u2717 Failed to get server:"),
5014
- source_default.red(error instanceof Error ? error.message : "Unknown error")
5015
- );
5016
- process.exit(1);
5022
+ handleCommandError(error, "Failed to get server");
5017
5023
  }
5018
5024
  }
5019
5025
  async function deleteServerCommand(serverId, options) {
@@ -5066,11 +5072,7 @@ async function deleteServerCommand(serverId, options) {
5066
5072
  )
5067
5073
  );
5068
5074
  } catch (error) {
5069
- console.error(
5070
- source_default.red.bold("\n\u2717 Failed to delete server:"),
5071
- source_default.red(error instanceof Error ? error.message : "Unknown error")
5072
- );
5073
- process.exit(1);
5075
+ handleCommandError(error, "Failed to delete server");
5074
5076
  }
5075
5077
  }
5076
5078
  function createServersCommand() {
@@ -5122,11 +5124,7 @@ async function orgListCommand() {
5122
5124
  );
5123
5125
  }
5124
5126
  } catch (error) {
5125
- console.error(
5126
- source_default.red.bold("\n\u2717 Failed to list organizations:"),
5127
- source_default.red(error instanceof Error ? error.message : "Unknown error")
5128
- );
5129
- process.exit(1);
5127
+ handleCommandError(error, "Failed to list organizations");
5130
5128
  }
5131
5129
  }
5132
5130
  async function orgSwitchCommand() {
@@ -5171,11 +5169,7 @@ async function orgSwitchCommand() {
5171
5169
  source_default.green.bold("\n\u2713 Switched to ") + source_default.cyan.bold(selected.name) + slug
5172
5170
  );
5173
5171
  } catch (error) {
5174
- console.error(
5175
- source_default.red.bold("\n\u2717 Failed to switch organization:"),
5176
- source_default.red(error instanceof Error ? error.message : "Unknown error")
5177
- );
5178
- process.exit(1);
5172
+ handleCommandError(error, "Failed to switch organization");
5179
5173
  }
5180
5174
  }
5181
5175
  async function orgCurrentCommand() {
@@ -5195,11 +5189,7 @@ async function orgCurrentCommand() {
5195
5189
  source_default.cyan.bold("\u{1F3E2} Active organization: ") + source_default.white(config.orgName || config.orgId) + slug
5196
5190
  );
5197
5191
  } catch (error) {
5198
- console.error(
5199
- source_default.red.bold("\n\u2717 Failed to get organization:"),
5200
- source_default.red(error instanceof Error ? error.message : "Unknown error")
5201
- );
5202
- process.exit(1);
5192
+ handleCommandError(error, "Failed to get organization");
5203
5193
  }
5204
5194
  }
5205
5195