@mcp-use/cli 3.4.2 → 3.5.0

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
@@ -1451,6 +1451,15 @@ var McpUseAPI = class _McpUseAPI {
1451
1451
  const path12 = encodeURIComponent(idOrSlug);
1452
1452
  return this.request(`/servers/${path12}`);
1453
1453
  }
1454
+ async updateServer(idOrSlug, body) {
1455
+ return this.request(
1456
+ `/servers/${encodeURIComponent(idOrSlug)}`,
1457
+ {
1458
+ method: "PATCH",
1459
+ body: JSON.stringify(body)
1460
+ }
1461
+ );
1462
+ }
1454
1463
  async deleteServer(id) {
1455
1464
  await this.request(
1456
1465
  `/servers/${encodeURIComponent(id)}`,
@@ -1460,9 +1469,10 @@ var McpUseAPI = class _McpUseAPI {
1460
1469
  );
1461
1470
  }
1462
1471
  // ── Env Variables ────────────────────────────────────────────────
1463
- async listEnvVariables(serverId) {
1472
+ async listEnvVariables(serverId, opts) {
1473
+ const q = opts?.branch ? `?branch=${encodeURIComponent(opts.branch)}` : "";
1464
1474
  return this.request(
1465
- `/servers/${encodeURIComponent(serverId)}/env-variables`
1475
+ `/servers/${encodeURIComponent(serverId)}/env-variables${q}`
1466
1476
  );
1467
1477
  }
1468
1478
  async createEnvVariable(serverId, body) {
@@ -4882,10 +4892,13 @@ function parseEnvVar(envStr) {
4882
4892
  }
4883
4893
  return { key, value };
4884
4894
  }
4885
- async function syncEnvVarsToServer(api, serverId, envVars) {
4895
+ async function syncEnvVarsToServer(api, serverId, envVars, opts) {
4886
4896
  const entries = Object.entries(envVars);
4887
4897
  if (entries.length === 0) return { created: 0, updated: 0 };
4888
- const existing = await api.listEnvVariables(serverId);
4898
+ const existing = await api.listEnvVariables(
4899
+ serverId,
4900
+ opts?.branch ? { branch: opts.branch } : void 0
4901
+ );
4889
4902
  const byKey = new Map(existing.map((v) => [v.key, v]));
4890
4903
  const results = await Promise.all(
4891
4904
  entries.map(async ([key, value]) => {
@@ -4894,7 +4907,12 @@ async function syncEnvVarsToServer(api, serverId, envVars) {
4894
4907
  await api.updateEnvVariable(serverId, found.id, { value });
4895
4908
  return "updated";
4896
4909
  }
4897
- await api.createEnvVariable(serverId, { key, value });
4910
+ await api.createEnvVariable(serverId, {
4911
+ key,
4912
+ value,
4913
+ ...opts?.branch ? { branch: opts.branch } : {},
4914
+ ...opts?.environments ? { environments: opts.environments } : {}
4915
+ });
4898
4916
  return "created";
4899
4917
  })
4900
4918
  );
@@ -5342,7 +5360,7 @@ async function deployViaManagedUpload(api, options, ctx) {
5342
5360
  console.log();
5343
5361
  }
5344
5362
  const envVars = await buildEnvVars(options);
5345
- const branch = "main";
5363
+ const branch = options.branch || "main";
5346
5364
  const projectName = options.name || await getProjectName(projectDir);
5347
5365
  console.log(source_default.gray("Packaging project source..."));
5348
5366
  const tarball = await packProjectTarball(projectDir);
@@ -5373,7 +5391,12 @@ async function deployViaManagedUpload(api, options, ctx) {
5373
5391
  if (serverId) {
5374
5392
  console.log(source_default.gray("Uploading source and redeploying..."));
5375
5393
  if (Object.keys(envVars).length > 0) {
5376
- await syncEnvVarsToServer(api, serverId, envVars);
5394
+ await syncEnvVarsToServer(
5395
+ api,
5396
+ serverId,
5397
+ envVars,
5398
+ options.branch ? { branch: options.branch } : void 0
5399
+ );
5377
5400
  }
5378
5401
  await api.pushSourceToServer(serverId, {
5379
5402
  tarball,
@@ -5643,7 +5666,7 @@ async function deployCommand(options) {
5643
5666
  }
5644
5667
  let gitInfo = await getGitInfo(cwd);
5645
5668
  let repoFullName;
5646
- let branch = "main";
5669
+ let branch = options.branch || "main";
5647
5670
  if (!gitInfo.isGitRepo || !gitInfo.remoteUrl) {
5648
5671
  const projectName2 = options.name || await getProjectName(projectDir);
5649
5672
  console.log(source_default.yellow("\u26A0\uFE0F No GitHub remote found.\n"));
@@ -5820,7 +5843,7 @@ async function deployCommand(options) {
5820
5843
  console.log(source_default.green("\u2713 Code pushed to GitHub\n"));
5821
5844
  gitInfo = await getGitInfo(cwd);
5822
5845
  repoFullName = repoResult.fullName;
5823
- branch = gitInfo.branch || "main";
5846
+ branch = options.branch || gitInfo.branch || "main";
5824
5847
  } else if (!isGitHubUrl(gitInfo.remoteUrl)) {
5825
5848
  console.log(source_default.red("\u2717 Remote is not a GitHub repository"));
5826
5849
  console.log(source_default.yellow(` Current remote: ${gitInfo.remoteUrl}
@@ -5831,7 +5854,7 @@ async function deployCommand(options) {
5831
5854
  process.exit(1);
5832
5855
  } else {
5833
5856
  repoFullName = `${gitInfo.owner}/${gitInfo.repo}`;
5834
- branch = gitInfo.branch || "main";
5857
+ branch = options.branch || gitInfo.branch || "main";
5835
5858
  const ownerLower = gitInfo.owner.toLowerCase();
5836
5859
  const matchingInst = installations.find(
5837
5860
  (i) => i.account_login.toLowerCase() === ownerLower
@@ -5979,7 +6002,12 @@ async function deployCommand(options) {
5979
6002
  console.log(source_default.cyan(` URL: ${getMcpServerUrl(existingDep)}
5980
6003
  `));
5981
6004
  if (Object.keys(envVars).length > 0) {
5982
- const synced = await syncEnvVarsToServer(api, serverId, envVars);
6005
+ const synced = await syncEnvVarsToServer(
6006
+ api,
6007
+ serverId,
6008
+ envVars,
6009
+ options.branch ? { branch: options.branch } : void 0
6010
+ );
5983
6011
  console.log(
5984
6012
  source_default.green(
5985
6013
  `\u2713 Synced ${synced.created + synced.updated} environment variable(s)` + (synced.created || synced.updated ? source_default.gray(
@@ -6027,7 +6055,12 @@ async function deployCommand(options) {
6027
6055
  let deploymentId;
6028
6056
  if (serverId) {
6029
6057
  if (Object.keys(envVars).length > 0) {
6030
- const synced = await syncEnvVarsToServer(api, serverId, envVars);
6058
+ const synced = await syncEnvVarsToServer(
6059
+ api,
6060
+ serverId,
6061
+ envVars,
6062
+ options.branch ? { branch: options.branch } : void 0
6063
+ );
6031
6064
  console.log(
6032
6065
  source_default.green(
6033
6066
  `\u2713 Synced ${synced.created + synced.updated} environment variable(s)` + (synced.created || synced.updated ? source_default.gray(
@@ -6369,8 +6402,10 @@ async function restartDeploymentCommand(deploymentId, options) {
6369
6402
  \u{1F504} Restarting deployment: ${deployment.name}
6370
6403
  `)
6371
6404
  );
6405
+ const branch = options.branch ?? deployment.gitBranch ?? void 0;
6372
6406
  const newDep = await api.createDeployment({
6373
6407
  serverId: deployment.serverId,
6408
+ ...branch ? { branch } : {},
6374
6409
  trigger: "redeploy"
6375
6410
  });
6376
6411
  console.log(source_default.green("\u2713 Restart initiated: ") + source_default.gray(newDep.id));
@@ -6594,7 +6629,10 @@ function createDeploymentsCommand() {
6594
6629
  );
6595
6630
  deploymentsCommand.command("list").alias("ls").description("List deployments").option("--limit <n>", "Page size (default 30)").option("--skip <n>", "Offset for pagination").option("--sort <field:asc|desc>", "Sort (e.g. createdAt:desc)").action(listDeploymentsCommand);
6596
6631
  deploymentsCommand.command("get").argument("<deployment-id>", "Deployment ID").description("Get deployment details").action(getDeploymentCommand);
6597
- deploymentsCommand.command("restart").argument("<deployment-id>", "Deployment ID").option("-f, --follow", "Follow build logs").description(
6632
+ deploymentsCommand.command("restart").argument("<deployment-id>", "Deployment ID").option("-f, --follow", "Follow build logs").option(
6633
+ "--branch <name>",
6634
+ "Target branch for the redeploy (default: the deployment's branch)"
6635
+ ).description(
6598
6636
  "Restart a deployment (triggers a new deployment on the same server)"
6599
6637
  ).action(restartDeploymentCommand);
6600
6638
  deploymentsCommand.command("delete").alias("rm").argument("<deployment-id>", "Deployment ID").option("-y, --yes", "Skip confirmation prompt").description("Delete a deployment").action(deleteDeploymentCommand);
@@ -6636,12 +6674,45 @@ function envBadge(env2) {
6636
6674
  if (env2 === "preview") return source_default.yellow("prev");
6637
6675
  return source_default.blue("dev");
6638
6676
  }
6677
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6678
+ async function resolveVarId(api, server, keyOrId, branch) {
6679
+ if (UUID_RE.test(keyOrId)) return keyOrId;
6680
+ const vars = await api.listEnvVariables(
6681
+ server,
6682
+ branch ? { branch } : void 0
6683
+ );
6684
+ const matches = vars.filter((v) => v.key === keyOrId);
6685
+ const scope = branch ? `branch "${branch}"` : "production";
6686
+ if (matches.length === 0) {
6687
+ console.error(
6688
+ source_default.red(
6689
+ `\u2717 No environment variable with key "${keyOrId}" in ${scope} scope.`
6690
+ )
6691
+ );
6692
+ console.error(
6693
+ source_default.gray(
6694
+ branch ? "Check the key, or omit --branch to target production scope." : "Check the key, or pass --branch <name> if it lives on a branch."
6695
+ )
6696
+ );
6697
+ process.exit(1);
6698
+ }
6699
+ if (matches.length > 1) {
6700
+ console.error(
6701
+ source_default.red(
6702
+ `\u2717 Multiple variables match key "${keyOrId}" in ${scope} scope. Pass the variable id instead.`
6703
+ )
6704
+ );
6705
+ process.exit(1);
6706
+ }
6707
+ return matches[0].id;
6708
+ }
6639
6709
  function printEnvVar(v, showValue = false) {
6640
6710
  const envs = v.environments.map(envBadge).join(" ");
6641
6711
  const val = v.sensitive ? source_default.gray("<sensitive>") : showValue ? source_default.cyan(v.value) : source_default.gray("(hidden \u2014 use --show-values to reveal)");
6712
+ const branch = v.branch ? " " + source_default.magenta(`branch:${v.branch}`) : "";
6642
6713
  console.log(` ${source_default.white.bold(v.key.padEnd(32))} ${val}`);
6643
6714
  console.log(
6644
- ` ${source_default.gray("id:")} ${source_default.gray(v.id)} ${envs}${v.sensitive ? " " + source_default.yellow("\u{1F512} sensitive") : ""}`
6715
+ ` ${source_default.gray("id:")} ${source_default.gray(v.id)} ${envs}${branch}${v.sensitive ? " " + source_default.yellow("\u{1F512} sensitive") : ""}`
6645
6716
  );
6646
6717
  }
6647
6718
  async function requireLogin() {
@@ -6657,16 +6728,26 @@ async function listEnvCommand(options) {
6657
6728
  try {
6658
6729
  await requireLogin();
6659
6730
  const api = await McpUseAPI.create();
6660
- const vars = await api.listEnvVariables(options.server);
6731
+ const vars = await api.listEnvVariables(
6732
+ options.server,
6733
+ options.branch ? { branch: options.branch } : void 0
6734
+ );
6735
+ const scope = options.branch ? `branch "${options.branch}"` : "production";
6661
6736
  if (vars.length === 0) {
6662
6737
  console.log(
6663
- source_default.yellow("\nNo environment variables set for this server.\n")
6738
+ source_default.yellow(
6739
+ `
6740
+ No environment variables set for this server (${scope} scope).
6741
+ `
6742
+ )
6664
6743
  );
6665
6744
  return;
6666
6745
  }
6667
- console.log(source_default.cyan.bold(`
6668
- Environment Variables (${vars.length})
6669
- `));
6746
+ console.log(
6747
+ source_default.cyan.bold(`
6748
+ Environment Variables \u2014 ${scope} (${vars.length})
6749
+ `)
6750
+ );
6670
6751
  for (const v of vars) {
6671
6752
  printEnvVar(v, options.showValues);
6672
6753
  console.log();
@@ -6699,6 +6780,7 @@ async function addEnvCommand(assignment, options) {
6699
6780
  key,
6700
6781
  value,
6701
6782
  environments,
6783
+ ...options.branch ? { branch: options.branch } : {},
6702
6784
  sensitive: options.sensitive ?? false
6703
6785
  });
6704
6786
  console.log(
@@ -6712,7 +6794,7 @@ async function addEnvCommand(assignment, options) {
6712
6794
  handleCommandError(error, "Failed to add environment variable");
6713
6795
  }
6714
6796
  }
6715
- async function updateEnvCommand(varId, options) {
6797
+ async function updateEnvCommand(keyOrId, options) {
6716
6798
  try {
6717
6799
  await requireLogin();
6718
6800
  if (!options.value && !options.env && options.sensitive === void 0) {
@@ -6728,6 +6810,12 @@ async function updateEnvCommand(varId, options) {
6728
6810
  if (options.env) body.environments = parseEnvironments(options.env);
6729
6811
  if (options.sensitive !== void 0) body.sensitive = options.sensitive;
6730
6812
  const api = await McpUseAPI.create();
6813
+ const varId = await resolveVarId(
6814
+ api,
6815
+ options.server,
6816
+ keyOrId,
6817
+ options.branch
6818
+ );
6731
6819
  const updated = await api.updateEnvVariable(options.server, varId, body);
6732
6820
  console.log(
6733
6821
  source_default.green(`
@@ -6740,13 +6828,19 @@ async function updateEnvCommand(varId, options) {
6740
6828
  handleCommandError(error, "Failed to update environment variable");
6741
6829
  }
6742
6830
  }
6743
- async function removeEnvCommand(varId, options) {
6831
+ async function removeEnvCommand(keyOrId, options) {
6744
6832
  try {
6745
6833
  await requireLogin();
6746
6834
  const api = await McpUseAPI.create();
6835
+ const varId = await resolveVarId(
6836
+ api,
6837
+ options.server,
6838
+ keyOrId,
6839
+ options.branch
6840
+ );
6747
6841
  await api.deleteEnvVariable(options.server, varId);
6748
6842
  console.log(source_default.green(`
6749
- \u2713 Environment variable ${varId} removed.
6843
+ \u2713 Environment variable ${keyOrId} removed.
6750
6844
  `));
6751
6845
  } catch (error) {
6752
6846
  handleCommandError(error, "Failed to remove environment variable");
@@ -6754,19 +6848,31 @@ async function removeEnvCommand(varId, options) {
6754
6848
  }
6755
6849
  function createEnvCommand() {
6756
6850
  const envCommand = new Command4("env").description("Manage environment variables for a server").showHelpAfterError("(Run `mcp-use env --help` to see available commands)");
6757
- envCommand.command("list").alias("ls").description("List environment variables for a server").requiredOption("--server <id>", "Server UUID").option("--show-values", "Reveal non-sensitive values in output").action(listEnvCommand);
6851
+ envCommand.command("list").alias("ls").description("List environment variables for a server").requiredOption("--server <id>", "Server UUID").option(
6852
+ "--branch <name>",
6853
+ "Scope to a branch's preview env (omit for production)"
6854
+ ).option("--show-values", "Reveal non-sensitive values in output").action(listEnvCommand);
6758
6855
  envCommand.command("add").argument("<KEY=VALUE>", "Variable assignment, e.g. API_KEY=abc123").description("Add an environment variable to a server").requiredOption("--server <id>", "Server UUID").option(
6759
6856
  "--env <environments>",
6760
6857
  "Comma-separated environments: production,preview,development (default: all)"
6858
+ ).option(
6859
+ "--branch <name>",
6860
+ "Pin the variable to a branch's preview env (omit for production)"
6761
6861
  ).option(
6762
6862
  "--sensitive",
6763
6863
  "Mark the variable as sensitive (value masked in UI)"
6764
6864
  ).action(addEnvCommand);
6765
- envCommand.command("update").argument("<var-id>", "Environment variable UUID").description("Update an existing environment variable").requiredOption("--server <id>", "Server UUID").option("--value <value>", "New value").option(
6865
+ envCommand.command("update").argument("<key-or-id>", "Environment variable KEY or UUID").description("Update an existing environment variable").requiredOption("--server <id>", "Server UUID").option("--value <value>", "New value").option(
6766
6866
  "--env <environments>",
6767
6867
  "New environments (comma-separated: production,preview,development)"
6868
+ ).option(
6869
+ "--branch <name>",
6870
+ "Branch scope used to resolve a KEY (omit for production)"
6768
6871
  ).option("--sensitive", "Mark as sensitive").option("--no-sensitive", "Unmark as sensitive").action(updateEnvCommand);
6769
- envCommand.command("remove").alias("rm").argument("<var-id>", "Environment variable UUID").description("Remove an environment variable from a server").requiredOption("--server <id>", "Server UUID").action(removeEnvCommand);
6872
+ envCommand.command("remove").alias("rm").argument("<key-or-id>", "Environment variable KEY or UUID").description("Remove an environment variable from a server").requiredOption("--server <id>", "Server UUID").option(
6873
+ "--branch <name>",
6874
+ "Branch scope used to resolve a KEY (omit for production)"
6875
+ ).action(removeEnvCommand);
6770
6876
  return envCommand;
6771
6877
  }
6772
6878
 
@@ -7014,6 +7120,55 @@ async function getServerCommand(idOrSlug, options) {
7014
7120
  handleCommandError(error, "Failed to get server");
7015
7121
  }
7016
7122
  }
7123
+ async function updateServerCommand(idOrSlug, options) {
7124
+ try {
7125
+ if (!await isLoggedIn()) {
7126
+ console.log(source_default.red("\u2717 You are not logged in."));
7127
+ console.log(
7128
+ source_default.gray(
7129
+ "Run " + source_default.white("npx mcp-use login") + " to get started."
7130
+ )
7131
+ );
7132
+ process.exit(1);
7133
+ }
7134
+ const body = {};
7135
+ if (options.name !== void 0) body.name = options.name;
7136
+ if (options.description !== void 0)
7137
+ body.description = options.description;
7138
+ if (options.branch !== void 0) body.productionBranch = options.branch;
7139
+ const config = {};
7140
+ if (options.buildCommand !== void 0) {
7141
+ config.buildCommand = options.buildCommand === "" ? null : options.buildCommand;
7142
+ }
7143
+ if (options.startCommand !== void 0) {
7144
+ config.startCommand = options.startCommand === "" ? null : options.startCommand;
7145
+ }
7146
+ if (Object.keys(config).length > 0) body.config = config;
7147
+ if (Object.keys(body).length === 0) {
7148
+ console.error(
7149
+ source_default.red(
7150
+ "\u2717 Nothing to update. Provide at least one of: --branch, --name, --build-command, --start-command, --description."
7151
+ )
7152
+ );
7153
+ process.exit(1);
7154
+ }
7155
+ const api = await McpUseAPI.create();
7156
+ await applyOrgOption(api, options.org);
7157
+ if (options.org) console.log();
7158
+ const server = await api.updateServer(idOrSlug, body);
7159
+ const label = server.name || server.slug || server.id;
7160
+ console.log(source_default.green.bold(`
7161
+ \u2713 Server updated: ${label}`));
7162
+ if (server.connectedRepository) {
7163
+ console.log(
7164
+ source_default.gray(" Prod branch: ") + source_default.cyan(server.connectedRepository.productionBranch)
7165
+ );
7166
+ }
7167
+ console.log();
7168
+ } catch (error) {
7169
+ handleCommandError(error, "Failed to update server");
7170
+ }
7171
+ }
7017
7172
  async function deleteServerCommand(serverId, options) {
7018
7173
  try {
7019
7174
  if (!await isLoggedIn()) {
@@ -7073,6 +7228,16 @@ function createServersCommand() {
7073
7228
  );
7074
7229
  serversCommand.command("list").alias("ls").description("List servers for the current organization").option("--org <slug-or-id>", "Target organization (slug, id, or name)").option("--limit <n>", "Page size (default 30)").option("--skip <n>", "Offset for pagination").option("--sort <field:asc|desc>", "Sort (e.g. updatedAt:desc)").action(listServersCommand);
7075
7230
  serversCommand.command("get").argument("<id-or-slug>", "Server UUID or slug").option("--org <slug-or-id>", "Resolve org context before fetch").description("Show server details and recent deployments").action(getServerCommand);
7231
+ serversCommand.command("update").argument("<id-or-slug>", "Server UUID or slug").description("Update server configuration (branch, name, commands, \u2026)").option(
7232
+ "--branch <name>",
7233
+ "New production branch \u2014 controls which branch triggers production deploys"
7234
+ ).option("--name <name>", "Rename the server").option(
7235
+ "--build-command <cmd>",
7236
+ "Override the build command (pass an empty string to clear)"
7237
+ ).option(
7238
+ "--start-command <cmd>",
7239
+ "Override the start command (pass an empty string to clear)"
7240
+ ).option("--description <text>", "Update the server description").option("--org <slug-or-id>", "Target organization").action(updateServerCommand);
7076
7241
  serversCommand.command("delete").alias("rm").argument("<server-id>", "Server UUID (or slug if API accepts it)").option("-y, --yes", "Skip confirmation prompt").option("--org <slug-or-id>", "Target organization").description("Delete a server and all its deployments").action(deleteServerCommand);
7077
7242
  serversCommand.addCommand(createEnvCommand());
7078
7243
  return serversCommand;
@@ -9677,8 +9842,11 @@ program.command("deploy").description("Deploy MCP server from GitHub to Manufact
9677
9842
  "Force creation of new deployment instead of reusing linked deployment"
9678
9843
  ).option(
9679
9844
  "--env <key=value...>",
9680
- "Environment variables (can be used multiple times)"
9845
+ "Environment variable values as KEY=VALUE (repeatable). Note: this sets values, unlike `servers env --env` which selects environment tags."
9681
9846
  ).option("--env-file <path>", "Path to .env file with environment variables").option(
9847
+ "--branch <name>",
9848
+ "Deploy branch (default: current git branch). Also scopes --env/--env-file sync to that branch's preview env."
9849
+ ).option(
9682
9850
  "--root-dir <path>",
9683
9851
  "Root directory within repo to deploy from (for monorepos)"
9684
9852
  ).option(
@@ -9702,6 +9870,7 @@ program.command("deploy").description("Deploy MCP server from GitHub to Manufact
9702
9870
  new: options.new,
9703
9871
  env: options.env,
9704
9872
  envFile: options.envFile,
9873
+ branch: options.branch,
9705
9874
  rootDir: options.rootDir,
9706
9875
  org: options.org,
9707
9876
  yes: options.yes,