Skip to content

Commit 444b06e

Browse files
suryaiyer95claude
andcommitted
feat: add non-interactive mode to mcp add command
Add CLI flags (`--name`, `--type`, `--url`, `--command`, `--header`, `--no-oauth`, `--global`) to `mcp add` for scripted usage. When `--name` and `--type` are provided, the command skips all interactive prompts and writes the MCP config directly. This enables copy-paste onboarding commands from the Altimate web UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 339f2c0 commit 444b06e

File tree

1 file changed

+60
-1
lines changed
  • packages/altimate-code/src/cli/cmd

1 file changed

+60
-1
lines changed

packages/altimate-code/src/cli/cmd/mcp.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,69 @@ async function addMcpToConfig(name: string, mcpConfig: Config.Mcp, configPath: s
418418
export const McpAddCommand = cmd({
419419
command: "add",
420420
describe: "add an MCP server",
421-
async handler() {
421+
builder: (yargs) =>
422+
yargs
423+
.option("name", { type: "string", describe: "MCP server name" })
424+
.option("type", { type: "string", describe: "Server type", choices: ["local", "remote"] })
425+
.option("url", { type: "string", describe: "Server URL (for remote type)" })
426+
.option("command", { type: "string", describe: "Command to run (for local type)" })
427+
.option("header", { type: "array", string: true, describe: "HTTP headers as key=value (repeatable)" })
428+
.option("no-oauth", { type: "boolean", describe: "Disable OAuth" })
429+
.option("global", { type: "boolean", describe: "Add to global config", default: false }),
430+
async handler(args) {
422431
await Instance.provide({
423432
directory: process.cwd(),
424433
async fn() {
434+
// Non-interactive mode: all required args provided via flags
435+
if (args.name && args.type) {
436+
const configPath = await resolveConfigPath(
437+
args.global ? Global.Path.config : Instance.worktree,
438+
args.global,
439+
)
440+
441+
let mcpConfig: Config.Mcp
442+
443+
if (args.type === "local") {
444+
if (!args.command) {
445+
console.error("--command is required for local type")
446+
process.exit(1)
447+
}
448+
mcpConfig = {
449+
type: "local",
450+
command: args.command.split(" "),
451+
}
452+
} else {
453+
if (!args.url) {
454+
console.error("--url is required for remote type")
455+
process.exit(1)
456+
}
457+
458+
const headers: Record<string, string> = {}
459+
if (args.header) {
460+
for (const h of args.header) {
461+
const eq = h.indexOf("=")
462+
if (eq === -1) {
463+
console.error(`Invalid header format: ${h} (expected key=value)`)
464+
process.exit(1)
465+
}
466+
headers[h.substring(0, eq)] = h.substring(eq + 1)
467+
}
468+
}
469+
470+
mcpConfig = {
471+
type: "remote",
472+
url: args.url,
473+
...(args["no-oauth"] ? { oauth: false as const } : {}),
474+
...(Object.keys(headers).length > 0 ? { headers } : {}),
475+
}
476+
}
477+
478+
await addMcpToConfig(args.name, mcpConfig, configPath)
479+
console.log(`MCP server "${args.name}" added to ${configPath}`)
480+
return
481+
}
482+
483+
// Interactive mode: existing behavior
425484
UI.empty()
426485
prompts.intro("Add MCP server")
427486

0 commit comments

Comments
 (0)