@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.
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/index.cjs +138 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +138 -62
- package/dist/index.js.map +1 -1
- package/dist/utils/api.d.ts +12 -0
- package/dist/utils/api.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1194,6 +1194,14 @@ async function getAuthBaseUrl() {
|
|
|
1194
1194
|
}
|
|
1195
1195
|
|
|
1196
1196
|
// src/utils/api.ts
|
|
1197
|
+
var GitHubAuthRequiredError = class extends Error {
|
|
1198
|
+
authorizeUrl;
|
|
1199
|
+
constructor(message, authorizeUrl) {
|
|
1200
|
+
super(message);
|
|
1201
|
+
this.name = "GitHubAuthRequiredError";
|
|
1202
|
+
this.authorizeUrl = authorizeUrl;
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1197
1205
|
var McpUseAPI = class _McpUseAPI {
|
|
1198
1206
|
baseUrl;
|
|
1199
1207
|
apiKey;
|
|
@@ -1242,8 +1250,19 @@ var McpUseAPI = class _McpUseAPI {
|
|
|
1242
1250
|
throw err;
|
|
1243
1251
|
}
|
|
1244
1252
|
if (!response.ok) {
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1253
|
+
const errorText = await response.text();
|
|
1254
|
+
try {
|
|
1255
|
+
const parsed = JSON.parse(errorText);
|
|
1256
|
+
if (parsed.code === "GITHUB_AUTH_REQUIRED" && parsed.authorizeUrl) {
|
|
1257
|
+
throw new GitHubAuthRequiredError(
|
|
1258
|
+
parsed.error || "GitHub authorization required",
|
|
1259
|
+
parsed.authorizeUrl
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
} catch (e) {
|
|
1263
|
+
if (e instanceof GitHubAuthRequiredError) throw e;
|
|
1264
|
+
}
|
|
1265
|
+
throw new Error(`API request failed: ${response.status} ${errorText}`);
|
|
1247
1266
|
}
|
|
1248
1267
|
return response.json();
|
|
1249
1268
|
} catch (error) {
|
|
@@ -1440,6 +1459,20 @@ var McpUseAPI = class _McpUseAPI {
|
|
|
1440
1459
|
})
|
|
1441
1460
|
});
|
|
1442
1461
|
}
|
|
1462
|
+
async getGitHubOAuthUrl() {
|
|
1463
|
+
return this.request(
|
|
1464
|
+
"/github/oauth/authorize"
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
async exchangeGitHubOAuthToken(code) {
|
|
1468
|
+
return this.request(
|
|
1469
|
+
"/github/oauth/token",
|
|
1470
|
+
{
|
|
1471
|
+
method: "POST",
|
|
1472
|
+
body: JSON.stringify({ code })
|
|
1473
|
+
}
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1443
1476
|
};
|
|
1444
1477
|
|
|
1445
1478
|
// src/commands/auth.ts
|
|
@@ -3467,10 +3500,9 @@ async function deployCommand(options) {
|
|
|
3467
3500
|
console.log(source_default.red("\u2717 No GitHub installations found."));
|
|
3468
3501
|
process.exit(1);
|
|
3469
3502
|
}
|
|
3470
|
-
const defaultInstallation = installations.find((i) => i.account_type === "Organization") ?? installations[0];
|
|
3471
|
-
const installationDbId = defaultInstallation.id;
|
|
3472
|
-
const githubInstallationId = defaultInstallation.installation_id;
|
|
3473
3503
|
console.log(source_default.green("\u2713 GitHub connected\n"));
|
|
3504
|
+
let installationDbId;
|
|
3505
|
+
let githubInstallationId;
|
|
3474
3506
|
const projectDir = options.rootDir ? path5.resolve(cwd, options.rootDir) : cwd;
|
|
3475
3507
|
if (options.rootDir) {
|
|
3476
3508
|
try {
|
|
@@ -3554,43 +3586,8 @@ async function deployCommand(options) {
|
|
|
3554
3586
|
}
|
|
3555
3587
|
}
|
|
3556
3588
|
const repoInstallation = installations[selectedIdx];
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
source_default.yellow(
|
|
3560
|
-
"\n\u26A0\uFE0F GitHub Apps cannot create repos on personal accounts.\n"
|
|
3561
|
-
)
|
|
3562
|
-
);
|
|
3563
|
-
console.log(
|
|
3564
|
-
source_default.white("To deploy from ") + source_default.cyan(repoInstallation.account_login) + source_default.white(", create a repository manually:\n")
|
|
3565
|
-
);
|
|
3566
|
-
console.log(
|
|
3567
|
-
source_default.cyan(" 1. ") + source_default.white("Go to ") + source_default.cyan("https://github.com/new")
|
|
3568
|
-
);
|
|
3569
|
-
console.log(
|
|
3570
|
-
source_default.cyan(" 2. ") + source_default.white("Create a repository (any name, can be private)")
|
|
3571
|
-
);
|
|
3572
|
-
console.log(source_default.cyan(" 3. ") + source_default.white("Add it as a remote:"));
|
|
3573
|
-
console.log(source_default.gray(" git init && git remote add origin <url>"));
|
|
3574
|
-
console.log(source_default.cyan(" 4. ") + source_default.white("Push your code:"));
|
|
3575
|
-
console.log(
|
|
3576
|
-
source_default.gray(
|
|
3577
|
-
" git add . && git commit -m 'Initial commit' && git push -u origin main"
|
|
3578
|
-
)
|
|
3579
|
-
);
|
|
3580
|
-
console.log(
|
|
3581
|
-
source_default.cyan(" 5. ") + source_default.white("Grant the GitHub App access to the repo:")
|
|
3582
|
-
);
|
|
3583
|
-
const appName = await api.getGitHubAppName();
|
|
3584
|
-
console.log(
|
|
3585
|
-
source_default.gray(
|
|
3586
|
-
` https://github.com/apps/${appName}/installations/new`
|
|
3587
|
-
)
|
|
3588
|
-
);
|
|
3589
|
-
console.log(
|
|
3590
|
-
source_default.cyan(" 6. ") + source_default.white("Run ") + source_default.cyan("mcp-use deploy") + source_default.white(" again\n")
|
|
3591
|
-
);
|
|
3592
|
-
process.exit(0);
|
|
3593
|
-
}
|
|
3589
|
+
installationDbId = repoInstallation.id;
|
|
3590
|
+
githubInstallationId = repoInstallation.installation_id;
|
|
3594
3591
|
const repoName = options.yes ? projectName2 : await promptText(source_default.gray("Repository name:"), projectName2);
|
|
3595
3592
|
await ensureGitignore(cwd);
|
|
3596
3593
|
console.log(
|
|
@@ -3598,19 +3595,78 @@ async function deployCommand(options) {
|
|
|
3598
3595
|
`Creating repository on ${repoInstallation.account_login}...`
|
|
3599
3596
|
)
|
|
3600
3597
|
);
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3598
|
+
let repoResult;
|
|
3599
|
+
try {
|
|
3600
|
+
repoResult = await api.createGitHubRepo({
|
|
3601
|
+
installationId: repoInstallation.installation_id,
|
|
3602
|
+
name: repoName,
|
|
3603
|
+
private: true,
|
|
3604
|
+
org: repoInstallation.account_login
|
|
3605
|
+
});
|
|
3606
|
+
} catch (err) {
|
|
3607
|
+
if (err instanceof GitHubAuthRequiredError) {
|
|
3608
|
+
console.log(
|
|
3609
|
+
source_default.yellow(
|
|
3610
|
+
`
|
|
3611
|
+
Personal accounts require a one-time GitHub authorization.
|
|
3612
|
+
`
|
|
3613
|
+
)
|
|
3614
|
+
);
|
|
3615
|
+
try {
|
|
3616
|
+
await open_default(err.authorizeUrl);
|
|
3617
|
+
console.log(
|
|
3618
|
+
source_default.gray(" Browser opened. Authorize and return here.\n")
|
|
3619
|
+
);
|
|
3620
|
+
} catch {
|
|
3621
|
+
console.log(
|
|
3622
|
+
source_default.gray(
|
|
3623
|
+
` Open this URL in your browser:
|
|
3624
|
+
${err.authorizeUrl}
|
|
3625
|
+
`
|
|
3626
|
+
)
|
|
3627
|
+
);
|
|
3628
|
+
}
|
|
3629
|
+
const readline = await import("readline");
|
|
3630
|
+
await new Promise((resolve2) => {
|
|
3631
|
+
const rl = readline.createInterface({
|
|
3632
|
+
input: process.stdin,
|
|
3633
|
+
output: process.stdout
|
|
3634
|
+
});
|
|
3635
|
+
rl.question(
|
|
3636
|
+
source_default.gray(" Press Enter after authorizing..."),
|
|
3637
|
+
() => {
|
|
3638
|
+
rl.close();
|
|
3639
|
+
resolve2();
|
|
3640
|
+
}
|
|
3641
|
+
);
|
|
3642
|
+
});
|
|
3643
|
+
console.log(source_default.gray("Retrying repository creation..."));
|
|
3644
|
+
repoResult = await api.createGitHubRepo({
|
|
3645
|
+
installationId: repoInstallation.installation_id,
|
|
3646
|
+
name: repoName,
|
|
3647
|
+
private: true,
|
|
3648
|
+
org: repoInstallation.account_login
|
|
3649
|
+
});
|
|
3650
|
+
} else {
|
|
3651
|
+
throw err;
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3607
3654
|
console.log(source_default.green(`\u2713 Created ${source_default.cyan(repoResult.fullName)}`));
|
|
3608
3655
|
if (!gitInfo.isGitRepo) {
|
|
3656
|
+
await ensureGitignore(cwd);
|
|
3609
3657
|
console.log(source_default.gray("Initializing git..."));
|
|
3610
3658
|
await gitInit(cwd, "Initial commit");
|
|
3611
3659
|
console.log(source_default.gray("Pushing to GitHub..."));
|
|
3612
3660
|
await gitAddRemoteAndPush(cwd, repoResult.cloneUrl, "main");
|
|
3613
3661
|
} else {
|
|
3662
|
+
if (await hasUncommittedChanges(cwd)) {
|
|
3663
|
+
console.log(
|
|
3664
|
+
source_default.red(
|
|
3665
|
+
"\u2717 You have uncommitted changes. Commit and push before deploying."
|
|
3666
|
+
)
|
|
3667
|
+
);
|
|
3668
|
+
process.exit(1);
|
|
3669
|
+
}
|
|
3614
3670
|
console.log(source_default.gray("Adding remote and pushing..."));
|
|
3615
3671
|
await gitAddRemoteAndPush(
|
|
3616
3672
|
cwd,
|
|
@@ -3633,22 +3689,34 @@ async function deployCommand(options) {
|
|
|
3633
3689
|
} else {
|
|
3634
3690
|
repoFullName = `${gitInfo.owner}/${gitInfo.repo}`;
|
|
3635
3691
|
branch = gitInfo.branch || "main";
|
|
3692
|
+
const ownerLower = gitInfo.owner.toLowerCase();
|
|
3693
|
+
const matchingInst = installations.find(
|
|
3694
|
+
(i) => i.account_login.toLowerCase() === ownerLower
|
|
3695
|
+
) ?? installations.find((i) => i.account_type === "Organization") ?? installations[0];
|
|
3696
|
+
installationDbId = matchingInst.id;
|
|
3697
|
+
githubInstallationId = matchingInst.installation_id;
|
|
3636
3698
|
if (gitInfo.hasUncommittedChanges) {
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3699
|
+
if (options.yes) {
|
|
3700
|
+
console.log(
|
|
3701
|
+
source_default.red(
|
|
3702
|
+
"\u2717 You have uncommitted changes. Commit and push before deploying."
|
|
3703
|
+
)
|
|
3642
3704
|
);
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3705
|
+
process.exit(1);
|
|
3706
|
+
}
|
|
3707
|
+
console.log(source_default.yellow("\u26A0\uFE0F You have uncommitted changes.\n"));
|
|
3708
|
+
const shouldCommit = await prompt(
|
|
3709
|
+
source_default.white("Commit and push changes before deploying? (Y/n): "),
|
|
3710
|
+
"y"
|
|
3711
|
+
);
|
|
3712
|
+
if (shouldCommit) {
|
|
3713
|
+
await ensureGitignore(cwd);
|
|
3714
|
+
console.log(source_default.gray("Committing and pushing..."));
|
|
3715
|
+
await gitCommitAndPush(cwd, "Deploy changes", branch);
|
|
3716
|
+
gitInfo = await getGitInfo(cwd);
|
|
3717
|
+
console.log(source_default.green("\u2713 Changes pushed\n"));
|
|
3718
|
+
} else {
|
|
3719
|
+
console.log(source_default.gray("Deploying from last pushed commit.\n"));
|
|
3652
3720
|
}
|
|
3653
3721
|
}
|
|
3654
3722
|
console.log(source_default.gray("Checking repository access..."));
|
|
@@ -3808,6 +3876,14 @@ async function deployCommand(options) {
|
|
|
3808
3876
|
}
|
|
3809
3877
|
if (!serverId) {
|
|
3810
3878
|
const orgId = await api.resolveOrganizationId();
|
|
3879
|
+
if (!installationDbId) {
|
|
3880
|
+
console.log(
|
|
3881
|
+
source_default.red(
|
|
3882
|
+
"\u2717 Could not determine GitHub installation for this repository."
|
|
3883
|
+
)
|
|
3884
|
+
);
|
|
3885
|
+
process.exit(1);
|
|
3886
|
+
}
|
|
3811
3887
|
console.log(source_default.gray("Creating server and deployment..."));
|
|
3812
3888
|
const serverResult = await api.createServer({
|
|
3813
3889
|
type: "github",
|