Skip to content

Commit 6800458

Browse files
suryaiyer95claude
andcommitted
feat: add mcp remove command
Add `altimate-code mcp remove <name>` (alias `rm`) to remove an MCP server from config. Supports `--global` flag; auto-searches the other scope if the server isn't found in the specified one. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b89f8f6 commit 6800458

File tree

1 file changed

+63
-0
lines changed
  • packages/opencode/src/cli/cmd

1 file changed

+63
-0
lines changed

packages/opencode/src/cli/cmd/mcp.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const McpCommand = cmd({
5656
builder: (yargs) =>
5757
yargs
5858
.command(McpAddCommand)
59+
.command(McpRemoveCommand)
5960
.command(McpListCommand)
6061
.command(McpAuthCommand)
6162
.command(McpLogoutCommand)
@@ -398,6 +399,25 @@ async function resolveConfigPath(baseDir: string, global = false) {
398399
return candidates[0]
399400
}
400401

402+
async function removeMcpFromConfig(name: string, configPath: string) {
403+
if (!(await Filesystem.exists(configPath))) {
404+
return false
405+
}
406+
407+
const text = await Filesystem.readText(configPath)
408+
const edits = modify(text, ["mcp", name], undefined, {
409+
formattingOptions: { tabSize: 2, insertSpaces: true },
410+
})
411+
412+
if (edits.length === 0) {
413+
return false
414+
}
415+
416+
const result = applyEdits(text, edits)
417+
await Filesystem.write(configPath, result)
418+
return true
419+
}
420+
401421
async function addMcpToConfig(name: string, mcpConfig: Config.Mcp, configPath: string) {
402422
let text = "{}"
403423
if (await Filesystem.exists(configPath)) {
@@ -638,6 +658,49 @@ export const McpAddCommand = cmd({
638658
},
639659
})
640660

661+
export const McpRemoveCommand = cmd({
662+
command: "remove <name>",
663+
aliases: ["rm"],
664+
describe: "remove an MCP server",
665+
builder: (yargs) =>
666+
yargs
667+
.positional("name", {
668+
describe: "name of the MCP server to remove",
669+
type: "string",
670+
demandOption: true,
671+
})
672+
.option("global", { type: "boolean", describe: "Remove from global config", default: false }),
673+
async handler(args) {
674+
await Instance.provide({
675+
directory: process.cwd(),
676+
async fn() {
677+
const configPath = await resolveConfigPath(
678+
args.global ? Global.Path.config : Instance.worktree,
679+
args.global,
680+
)
681+
682+
const removed = await removeMcpFromConfig(args.name, configPath)
683+
if (removed) {
684+
console.log(`MCP server "${args.name}" removed from ${configPath}`)
685+
} else {
686+
// Try the other scope
687+
const otherPath = await resolveConfigPath(
688+
args.global ? Instance.worktree : Global.Path.config,
689+
!args.global,
690+
)
691+
const removedOther = await removeMcpFromConfig(args.name, otherPath)
692+
if (removedOther) {
693+
console.log(`MCP server "${args.name}" removed from ${otherPath}`)
694+
} else {
695+
console.error(`MCP server "${args.name}" not found in any config`)
696+
process.exit(1)
697+
}
698+
}
699+
},
700+
})
701+
},
702+
})
703+
641704
export const McpDebugCommand = cmd({
642705
command: "debug <name>",
643706
describe: "debug OAuth connection for an MCP server",

0 commit comments

Comments
 (0)