(serverName: string, source?: "global" | "project")
| 2103 | } |
| 2104 | |
| 2105 | public async deleteServer(serverName: string, source?: "global" | "project"): Promise<void> { |
| 2106 | try { |
| 2107 | // Find the connection to determine if it's a global or project server |
| 2108 | const connection = this.findConnection(serverName, source) |
| 2109 | if (!connection) { |
| 2110 | throw new Error(`Server ${serverName}${source ? ` with source ${source}` : ""} not found`) |
| 2111 | } |
| 2112 | |
| 2113 | const serverSource = connection.server.source || "global" |
| 2114 | // Determine config file based on server source |
| 2115 | const isProjectServer = serverSource === "project" |
| 2116 | let configPath: string |
| 2117 | |
| 2118 | if (isProjectServer) { |
| 2119 | // Get project MCP config path |
| 2120 | const projectMcpPath = await this.getProjectMcpPath() |
| 2121 | if (!projectMcpPath) { |
| 2122 | throw new Error("Project MCP configuration file not found") |
| 2123 | } |
| 2124 | configPath = projectMcpPath |
| 2125 | } else { |
| 2126 | // Get global MCP settings path |
| 2127 | configPath = await this.getMcpSettingsFilePath() |
| 2128 | } |
| 2129 | |
| 2130 | // Ensure the settings file exists and is accessible |
| 2131 | try { |
| 2132 | await fs.access(configPath) |
| 2133 | } catch (error) { |
| 2134 | throw new Error("Settings file not accessible") |
| 2135 | } |
| 2136 | |
| 2137 | const content = await fs.readFile(configPath, "utf-8") |
| 2138 | const config = JSON.parse(content) |
| 2139 | |
| 2140 | // Validate the config structure |
| 2141 | if (!config || typeof config !== "object") { |
| 2142 | throw new Error("Invalid config structure") |
| 2143 | } |
| 2144 | |
| 2145 | if (!config.mcpServers || typeof config.mcpServers !== "object") { |
| 2146 | config.mcpServers = {} |
| 2147 | } |
| 2148 | |
| 2149 | // Remove the server from the settings |
| 2150 | if (config.mcpServers[serverName]) { |
| 2151 | delete config.mcpServers[serverName] |
| 2152 | |
| 2153 | // Write the entire config back |
| 2154 | const updatedConfig = { |
| 2155 | mcpServers: config.mcpServers, |
| 2156 | } |
| 2157 | |
| 2158 | await safeWriteJson(configPath, updatedConfig, { prettyPrint: true }) |
| 2159 | |
| 2160 | // Update server connections with the correct source |
| 2161 | await this.updateServerConnections(config.mcpServers, serverSource) |
| 2162 |
no test coverage detected