11import React from "react" ;
22import { Command } from "commander" ;
33import { render } from "ink" ;
4+ import chalk from "chalk" ;
45import { MCPList } from "../components/mcp/mcp-list.js" ;
56import { 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" ;
88import { TRANSPORT_TYPES } from "../mcp/constants.js" ;
99import { 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
1314export 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" )
0 commit comments