@mcp-use/cli 3.1.0-canary.1 → 3.1.0-canary.2

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
@@ -1569,6 +1569,14 @@ async function pollForDeviceToken(authBaseUrl, deviceCode, intervalSeconds) {
1569
1569
  }
1570
1570
  throw new Error("Login timed out. Please try again.");
1571
1571
  }
1572
+ function resolveOrgFromOption(orgs, identifier) {
1573
+ const needle = identifier.trim();
1574
+ if (!needle) return null;
1575
+ const lower = needle.toLowerCase();
1576
+ return orgs.find(
1577
+ (o) => o.slug === needle || o.id === needle || o.name.toLowerCase() === lower
1578
+ ) ?? null;
1579
+ }
1572
1580
  async function promptOrgSelection(orgs, defaultOrgId) {
1573
1581
  if (orgs.length === 0) return null;
1574
1582
  if (orgs.length === 1) {
@@ -1615,8 +1623,8 @@ async function loginCommand(options) {
1615
1623
  console.log(source_default.green.bold("\u2713 API key saved."));
1616
1624
  try {
1617
1625
  const api2 = await McpUseAPI.create();
1618
- const authInfo = await api2.testAuth();
1619
- console.log(source_default.gray(` Authenticated as ${authInfo.email}`));
1626
+ const authInfo2 = await api2.testAuth();
1627
+ console.log(source_default.gray(` Authenticated as ${authInfo2.email}`));
1620
1628
  } catch {
1621
1629
  console.log(
1622
1630
  source_default.gray(
@@ -1668,9 +1676,19 @@ async function loginCommand(options) {
1668
1676
  const keyResp = await api.createApiKeyWithAccessToken(accessToken, "CLI");
1669
1677
  await writeConfig({ apiKey: keyResp.key });
1670
1678
  console.log(source_default.green.bold("\n\u2713 Successfully logged in!"));
1679
+ let authInfo = null;
1671
1680
  try {
1672
1681
  const freshApi = await McpUseAPI.create();
1673
- const authInfo = await freshApi.testAuth();
1682
+ authInfo = await freshApi.testAuth();
1683
+ } catch {
1684
+ console.log(
1685
+ source_default.gray(
1686
+ `
1687
+ Your API key has been saved to ${source_default.white("~/.mcp-use/config.json")}`
1688
+ )
1689
+ );
1690
+ }
1691
+ if (authInfo) {
1674
1692
  console.log(source_default.cyan.bold("\nCurrent user:\n"));
1675
1693
  console.log(source_default.white(" Email: ") + source_default.cyan(authInfo.email));
1676
1694
  console.log(source_default.white(" User ID: ") + source_default.gray(authInfo.user_id));
@@ -1682,8 +1700,19 @@ async function loginCommand(options) {
1682
1700
  const orgs = authInfo.orgs ?? [];
1683
1701
  if (orgs.length > 0) {
1684
1702
  let selectedOrg = null;
1685
- if (orgs.length === 1) {
1703
+ if (options?.org) {
1704
+ selectedOrg = resolveOrgFromOption(orgs, options.org);
1705
+ if (!selectedOrg) {
1706
+ throw new Error(
1707
+ `Organization "${options.org}" not found. Run 'npx mcp-use org list' after logging in to see available organizations.`
1708
+ );
1709
+ }
1710
+ } else if (orgs.length === 1) {
1686
1711
  selectedOrg = orgs[0];
1712
+ } else if (!process.stdin.isTTY) {
1713
+ throw new Error(
1714
+ "Multiple organizations available and no TTY for interactive selection. Re-run with --org <slug|id|name> to pick one non-interactively."
1715
+ );
1687
1716
  } else {
1688
1717
  selectedOrg = await promptOrgSelection(orgs, authInfo.default_org_id);
1689
1718
  }
@@ -1701,13 +1730,6 @@ async function loginCommand(options) {
1701
1730
  );
1702
1731
  }
1703
1732
  }
1704
- } catch {
1705
- console.log(
1706
- source_default.gray(
1707
- `
1708
- Your API key has been saved to ${source_default.white("~/.mcp-use/config.json")}`
1709
- )
1710
- );
1711
1733
  }
1712
1734
  console.log(
1713
1735
  source_default.gray(
@@ -3555,9 +3577,7 @@ async function deployCommand(options) {
3555
3577
  let resolvedOrgId;
3556
3578
  if (options.org) {
3557
3579
  const authInfo = await api.testAuth();
3558
- const match = (authInfo.orgs ?? []).find(
3559
- (o) => o.slug === options.org || o.id === options.org || o.name.toLowerCase() === options.org.toLowerCase()
3560
- );
3580
+ const match = resolveOrgFromOption(authInfo.orgs ?? [], options.org);
3561
3581
  if (match) {
3562
3582
  api.setOrgId(match.id);
3563
3583
  resolvedOrgId = match.id;
@@ -4781,9 +4801,7 @@ function pickStr(obj, key) {
4781
4801
  async function applyOrgOption(api, org) {
4782
4802
  if (!org) return;
4783
4803
  const authInfo = await api.testAuth();
4784
- const match = (authInfo.orgs ?? []).find(
4785
- (o) => o.slug === org || o.id === org || o.name.toLowerCase() === org.toLowerCase()
4786
- );
4804
+ const match = resolveOrgFromOption(authInfo.orgs ?? [], org);
4787
4805
  if (!match) {
4788
4806
  console.error(
4789
4807
  source_default.red(
@@ -7202,9 +7220,9 @@ Looked for:
7202
7220
  program.command("login").description("Login to mcp-use cloud").option(
7203
7221
  "--api-key <key>",
7204
7222
  "Login with an API key directly (non-interactive, for CI/CD)"
7205
- ).action(async (opts) => {
7223
+ ).option("--org <slug|id|name>", "Select an organization non-interactively").action(async (opts) => {
7206
7224
  try {
7207
- await loginCommand({ apiKey: opts.apiKey });
7225
+ await loginCommand({ apiKey: opts.apiKey, org: opts.org });
7208
7226
  process.exit(0);
7209
7227
  } catch (error) {
7210
7228
  console.error(