Skip to content

Commit 1254622

Browse files
committed
feat: add mcp remove command support
1 parent dfe0256 commit 1254622

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

src/commands/mcp.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from "react";
22
import { Command } from "commander";
33
import { render } from "ink";
4+
import chalk from "chalk";
45
import { MCPList } from "../components/mcp/mcp-list.js";
56
import { MCPTest } from "../components/mcp/mcp-test.js";
6-
import { getConfigManager, getDefaultConfigPath } from "../config/manager.js";
7-
import type { MCPServerConfig, TransportType } from "../mcp/types.js";
7+
import { getDefaultConfigPath } from "../config/manager.js";
88
import { TRANSPORT_TYPES } from "../mcp/constants.js";
99
import { parseKeyValue } from "../mcp/utils.js";
10-
import { loadMCPConfig } from "../mcp/config.js";
11-
import chalk from "chalk";
10+
import { addMCPServer, removeMCPServer } from "../mcp/config.js";
11+
import { getMCPClientManager } from "../mcp/manager.js";
12+
import type { MCPServerConfig, TransportType } from "../mcp/types.js";
1213

1314
export function createMCPCommand(): Command {
1415
const mcp = new Command("mcp");
@@ -38,9 +39,6 @@ export function createMCPCommand(): Command {
3839
.option("--timeout <ms>", "Operation timeout in ms", (v) => parseInt(v, 10))
3940
.option("--enabled", "Add server as enabled", true)
4041
.action(async function (this: Command, name: string, opts: any) {
41-
const { servers } = loadMCPConfig();
42-
const configManager = getConfigManager();
43-
4442
let config: MCPServerConfig;
4543
switch (opts.transport as TransportType) {
4644
case TRANSPORT_TYPES.STDIO:
@@ -74,11 +72,7 @@ export function createMCPCommand(): Command {
7472
default:
7573
throw new Error(`Unknown transport type: ${opts.transport}`);
7674
}
77-
78-
const existing = (servers as Record<string, any>) || {};
79-
const updated = { ...existing, [name]: config };
80-
configManager.saveProjectSettings({ mcpServers: updated });
81-
75+
await addMCPServer(name, config);
8276
const path = getDefaultConfigPath();
8377
console.log(chalk.green(`✓ Added MCP server: ${name} to ${path}`));
8478
});
@@ -96,6 +90,17 @@ export function createMCPCommand(): Command {
9690
await waitUntilExit();
9791
});
9892

93+
mcp
94+
.command("remove <name>")
95+
.description("Remove an MCP server")
96+
.action(async (name: string) => {
97+
const mcpClientManager = getMCPClientManager();
98+
await mcpClientManager.removeClient(name);
99+
100+
await removeMCPServer(name);
101+
console.log(chalk.green(`✓ Removed MCP server: ${name}`));
102+
});
103+
99104
mcp
100105
.command("test <name>")
101106
.description("Test connection to an MCP server")

src/mcp/config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ export function loadMCPConfig(): MCPConfig {
1212
const servers = settings.mcpServers || {};
1313
return { servers };
1414
}
15+
16+
export function addMCPServer(name: string, config: MCPServerConfig): void {
17+
const configManager = getConfigManager();
18+
const { servers } = loadMCPConfig();
19+
20+
const updated = { ...servers, [name]: config };
21+
configManager.saveProjectSettings({ mcpServers: updated });
22+
}
23+
24+
export function removeMCPServer(name: string): void {
25+
const configManager = getConfigManager();
26+
const { servers } = loadMCPConfig();
27+
28+
if (servers) {
29+
delete servers[name];
30+
configManager.saveProjectSettings({ mcpServers: servers });
31+
}
32+
}

0 commit comments

Comments
 (0)