@mcp-use/cli 3.0.1-canary.0 → 3.0.1-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.
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAsIA,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAuYD,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA0mBzE"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAuIA,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAuYD,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA2oBzE"}
package/dist/index.cjs CHANGED
@@ -1214,6 +1214,14 @@ async function getAuthBaseUrl() {
1214
1214
  }
1215
1215
 
1216
1216
  // src/utils/api.ts
1217
+ var GitHubAuthRequiredError = class extends Error {
1218
+ authorizeUrl;
1219
+ constructor(message, authorizeUrl) {
1220
+ super(message);
1221
+ this.name = "GitHubAuthRequiredError";
1222
+ this.authorizeUrl = authorizeUrl;
1223
+ }
1224
+ };
1217
1225
  var McpUseAPI = class _McpUseAPI {
1218
1226
  baseUrl;
1219
1227
  apiKey;
@@ -1262,8 +1270,19 @@ var McpUseAPI = class _McpUseAPI {
1262
1270
  throw err;
1263
1271
  }
1264
1272
  if (!response.ok) {
1265
- const error = await response.text();
1266
- throw new Error(`API request failed: ${response.status} ${error}`);
1273
+ const errorText = await response.text();
1274
+ try {
1275
+ const parsed = JSON.parse(errorText);
1276
+ if (parsed.code === "GITHUB_AUTH_REQUIRED" && parsed.authorizeUrl) {
1277
+ throw new GitHubAuthRequiredError(
1278
+ parsed.error || "GitHub authorization required",
1279
+ parsed.authorizeUrl
1280
+ );
1281
+ }
1282
+ } catch (e) {
1283
+ if (e instanceof GitHubAuthRequiredError) throw e;
1284
+ }
1285
+ throw new Error(`API request failed: ${response.status} ${errorText}`);
1267
1286
  }
1268
1287
  return response.json();
1269
1288
  } catch (error) {
@@ -1460,6 +1479,20 @@ var McpUseAPI = class _McpUseAPI {
1460
1479
  })
1461
1480
  });
1462
1481
  }
1482
+ async getGitHubOAuthUrl() {
1483
+ return this.request(
1484
+ "/github/oauth/authorize"
1485
+ );
1486
+ }
1487
+ async exchangeGitHubOAuthToken(code) {
1488
+ return this.request(
1489
+ "/github/oauth/token",
1490
+ {
1491
+ method: "POST",
1492
+ body: JSON.stringify({ code })
1493
+ }
1494
+ );
1495
+ }
1463
1496
  };
1464
1497
 
1465
1498
  // src/commands/auth.ts
@@ -3487,10 +3520,9 @@ async function deployCommand(options) {
3487
3520
  console.log(source_default.red("\u2717 No GitHub installations found."));
3488
3521
  process.exit(1);
3489
3522
  }
3490
- const defaultInstallation = installations.find((i) => i.account_type === "Organization") ?? installations[0];
3491
- const installationDbId = defaultInstallation.id;
3492
- const githubInstallationId = defaultInstallation.installation_id;
3493
3523
  console.log(source_default.green("\u2713 GitHub connected\n"));
3524
+ let installationDbId;
3525
+ let githubInstallationId;
3494
3526
  const projectDir = options.rootDir ? import_node_path5.default.resolve(cwd, options.rootDir) : cwd;
3495
3527
  if (options.rootDir) {
3496
3528
  try {
@@ -3574,43 +3606,8 @@ async function deployCommand(options) {
3574
3606
  }
3575
3607
  }
3576
3608
  const repoInstallation = installations[selectedIdx];
3577
- if (repoInstallation.account_type !== "Organization") {
3578
- console.log(
3579
- source_default.yellow(
3580
- "\n\u26A0\uFE0F GitHub Apps cannot create repos on personal accounts.\n"
3581
- )
3582
- );
3583
- console.log(
3584
- source_default.white("To deploy from ") + source_default.cyan(repoInstallation.account_login) + source_default.white(", create a repository manually:\n")
3585
- );
3586
- console.log(
3587
- source_default.cyan(" 1. ") + source_default.white("Go to ") + source_default.cyan("https://github.com/new")
3588
- );
3589
- console.log(
3590
- source_default.cyan(" 2. ") + source_default.white("Create a repository (any name, can be private)")
3591
- );
3592
- console.log(source_default.cyan(" 3. ") + source_default.white("Add it as a remote:"));
3593
- console.log(source_default.gray(" git init && git remote add origin <url>"));
3594
- console.log(source_default.cyan(" 4. ") + source_default.white("Push your code:"));
3595
- console.log(
3596
- source_default.gray(
3597
- " git add . && git commit -m 'Initial commit' && git push -u origin main"
3598
- )
3599
- );
3600
- console.log(
3601
- source_default.cyan(" 5. ") + source_default.white("Grant the GitHub App access to the repo:")
3602
- );
3603
- const appName = await api.getGitHubAppName();
3604
- console.log(
3605
- source_default.gray(
3606
- ` https://github.com/apps/${appName}/installations/new`
3607
- )
3608
- );
3609
- console.log(
3610
- source_default.cyan(" 6. ") + source_default.white("Run ") + source_default.cyan("mcp-use deploy") + source_default.white(" again\n")
3611
- );
3612
- process.exit(0);
3613
- }
3609
+ installationDbId = repoInstallation.id;
3610
+ githubInstallationId = repoInstallation.installation_id;
3614
3611
  const repoName = options.yes ? projectName2 : await promptText(source_default.gray("Repository name:"), projectName2);
3615
3612
  await ensureGitignore(cwd);
3616
3613
  console.log(
@@ -3618,19 +3615,78 @@ async function deployCommand(options) {
3618
3615
  `Creating repository on ${repoInstallation.account_login}...`
3619
3616
  )
3620
3617
  );
3621
- const repoResult = await api.createGitHubRepo({
3622
- installationId: repoInstallation.installation_id,
3623
- name: repoName,
3624
- private: true,
3625
- org: repoInstallation.account_login
3626
- });
3618
+ let repoResult;
3619
+ try {
3620
+ repoResult = await api.createGitHubRepo({
3621
+ installationId: repoInstallation.installation_id,
3622
+ name: repoName,
3623
+ private: true,
3624
+ org: repoInstallation.account_login
3625
+ });
3626
+ } catch (err) {
3627
+ if (err instanceof GitHubAuthRequiredError) {
3628
+ console.log(
3629
+ source_default.yellow(
3630
+ `
3631
+ Personal accounts require a one-time GitHub authorization.
3632
+ `
3633
+ )
3634
+ );
3635
+ try {
3636
+ await open_default(err.authorizeUrl);
3637
+ console.log(
3638
+ source_default.gray(" Browser opened. Authorize and return here.\n")
3639
+ );
3640
+ } catch {
3641
+ console.log(
3642
+ source_default.gray(
3643
+ ` Open this URL in your browser:
3644
+ ${err.authorizeUrl}
3645
+ `
3646
+ )
3647
+ );
3648
+ }
3649
+ const readline = await import("readline");
3650
+ await new Promise((resolve2) => {
3651
+ const rl = readline.createInterface({
3652
+ input: process.stdin,
3653
+ output: process.stdout
3654
+ });
3655
+ rl.question(
3656
+ source_default.gray(" Press Enter after authorizing..."),
3657
+ () => {
3658
+ rl.close();
3659
+ resolve2();
3660
+ }
3661
+ );
3662
+ });
3663
+ console.log(source_default.gray("Retrying repository creation..."));
3664
+ repoResult = await api.createGitHubRepo({
3665
+ installationId: repoInstallation.installation_id,
3666
+ name: repoName,
3667
+ private: true,
3668
+ org: repoInstallation.account_login
3669
+ });
3670
+ } else {
3671
+ throw err;
3672
+ }
3673
+ }
3627
3674
  console.log(source_default.green(`\u2713 Created ${source_default.cyan(repoResult.fullName)}`));
3628
3675
  if (!gitInfo.isGitRepo) {
3676
+ await ensureGitignore(cwd);
3629
3677
  console.log(source_default.gray("Initializing git..."));
3630
3678
  await gitInit(cwd, "Initial commit");
3631
3679
  console.log(source_default.gray("Pushing to GitHub..."));
3632
3680
  await gitAddRemoteAndPush(cwd, repoResult.cloneUrl, "main");
3633
3681
  } else {
3682
+ if (await hasUncommittedChanges(cwd)) {
3683
+ console.log(
3684
+ source_default.red(
3685
+ "\u2717 You have uncommitted changes. Commit and push before deploying."
3686
+ )
3687
+ );
3688
+ process.exit(1);
3689
+ }
3634
3690
  console.log(source_default.gray("Adding remote and pushing..."));
3635
3691
  await gitAddRemoteAndPush(
3636
3692
  cwd,
@@ -3653,22 +3709,34 @@ async function deployCommand(options) {
3653
3709
  } else {
3654
3710
  repoFullName = `${gitInfo.owner}/${gitInfo.repo}`;
3655
3711
  branch = gitInfo.branch || "main";
3712
+ const ownerLower = gitInfo.owner.toLowerCase();
3713
+ const matchingInst = installations.find(
3714
+ (i) => i.account_login.toLowerCase() === ownerLower
3715
+ ) ?? installations.find((i) => i.account_type === "Organization") ?? installations[0];
3716
+ installationDbId = matchingInst.id;
3717
+ githubInstallationId = matchingInst.installation_id;
3656
3718
  if (gitInfo.hasUncommittedChanges) {
3657
- console.log(source_default.yellow("\u26A0\uFE0F You have uncommitted changes.\n"));
3658
- if (!options.yes) {
3659
- const shouldCommit = await prompt(
3660
- source_default.white("Commit and push changes before deploying? (Y/n): "),
3661
- "y"
3719
+ if (options.yes) {
3720
+ console.log(
3721
+ source_default.red(
3722
+ "\u2717 You have uncommitted changes. Commit and push before deploying."
3723
+ )
3662
3724
  );
3663
- if (shouldCommit) {
3664
- await ensureGitignore(cwd);
3665
- console.log(source_default.gray("Committing and pushing..."));
3666
- await gitCommitAndPush(cwd, "Deploy changes", branch);
3667
- gitInfo = await getGitInfo(cwd);
3668
- console.log(source_default.green("\u2713 Changes pushed\n"));
3669
- } else {
3670
- console.log(source_default.gray("Deploying from last pushed commit.\n"));
3671
- }
3725
+ process.exit(1);
3726
+ }
3727
+ console.log(source_default.yellow("\u26A0\uFE0F You have uncommitted changes.\n"));
3728
+ const shouldCommit = await prompt(
3729
+ source_default.white("Commit and push changes before deploying? (Y/n): "),
3730
+ "y"
3731
+ );
3732
+ if (shouldCommit) {
3733
+ await ensureGitignore(cwd);
3734
+ console.log(source_default.gray("Committing and pushing..."));
3735
+ await gitCommitAndPush(cwd, "Deploy changes", branch);
3736
+ gitInfo = await getGitInfo(cwd);
3737
+ console.log(source_default.green("\u2713 Changes pushed\n"));
3738
+ } else {
3739
+ console.log(source_default.gray("Deploying from last pushed commit.\n"));
3672
3740
  }
3673
3741
  }
3674
3742
  console.log(source_default.gray("Checking repository access..."));
@@ -3828,6 +3896,14 @@ async function deployCommand(options) {
3828
3896
  }
3829
3897
  if (!serverId) {
3830
3898
  const orgId = await api.resolveOrganizationId();
3899
+ if (!installationDbId) {
3900
+ console.log(
3901
+ source_default.red(
3902
+ "\u2717 Could not determine GitHub installation for this repository."
3903
+ )
3904
+ );
3905
+ process.exit(1);
3906
+ }
3831
3907
  console.log(source_default.gray("Creating server and deployment..."));
3832
3908
  const serverResult = await api.createServer({
3833
3909
  type: "github",