* Helper method to update a specific tool list (alwaysAllow or disabledTools) * in the appropriate settings file. * @param serverName The name of the server to update * @param source Whether to update the global or project config * @param toolName The name of the tool to add or remove * @p
( serverName: string, source: "global" | "project", toolName: string, listName: "alwaysAllow" | "disabledTools", addTool: boolean, )
| 2298 | * @param addTool Whether to add (true) or remove (false) the tool from the list |
| 2299 | */ |
| 2300 | private async updateServerToolList( |
| 2301 | serverName: string, |
| 2302 | source: "global" | "project", |
| 2303 | toolName: string, |
| 2304 | listName: "alwaysAllow" | "disabledTools", |
| 2305 | addTool: boolean, |
| 2306 | ): Promise<void> { |
| 2307 | // Find the connection with matching name and source |
| 2308 | const connection = this.findConnection(serverName, source) |
| 2309 | |
| 2310 | if (!connection) { |
| 2311 | throw new Error(`Server ${serverName} with source ${source} not found`) |
| 2312 | } |
| 2313 | |
| 2314 | // Determine the correct config path based on the source |
| 2315 | let configPath: string |
| 2316 | if (source === "project") { |
| 2317 | // Get project MCP config path |
| 2318 | const projectMcpPath = await this.getProjectMcpPath() |
| 2319 | if (!projectMcpPath) { |
| 2320 | throw new Error("Project MCP configuration file not found") |
| 2321 | } |
| 2322 | configPath = projectMcpPath |
| 2323 | } else { |
| 2324 | // Get global MCP settings path |
| 2325 | configPath = await this.getMcpSettingsFilePath() |
| 2326 | } |
| 2327 | |
| 2328 | // Normalize path for cross-platform compatibility |
| 2329 | // Use a consistent path format for both reading and writing |
| 2330 | const normalizedPath = process.platform === "win32" ? configPath.replace(/\\/g, "/") : configPath |
| 2331 | |
| 2332 | // Read the appropriate config file |
| 2333 | const content = await fs.readFile(normalizedPath, "utf-8") |
| 2334 | const config = JSON.parse(content) |
| 2335 | |
| 2336 | if (!config.mcpServers) { |
| 2337 | config.mcpServers = {} |
| 2338 | } |
| 2339 | |
| 2340 | if (!config.mcpServers[serverName]) { |
| 2341 | config.mcpServers[serverName] = { |
| 2342 | type: "stdio", |
| 2343 | command: "node", |
| 2344 | args: [], // Default to an empty array; can be set later if needed |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | if (!config.mcpServers[serverName][listName]) { |
| 2349 | config.mcpServers[serverName][listName] = [] |
| 2350 | } |
| 2351 | |
| 2352 | const targetList = config.mcpServers[serverName][listName] |
| 2353 | const toolIndex = targetList.indexOf(toolName) |
| 2354 | |
| 2355 | if (addTool && toolIndex === -1) { |
| 2356 | targetList.push(toolName) |
| 2357 | } else if (!addTool && toolIndex !== -1) { |
no test coverage detected