Remove MCP server entry from Copilot CLI's ~/.copilot/mcp-config.json.
(settings_path: &Path)
| 404 | |
| 405 | /// Remove MCP server entry from Copilot CLI's ~/.copilot/mcp-config.json. |
| 406 | fn uninstall_cli_mcp_server(settings_path: &Path) { |
| 407 | if !settings_path.exists() { |
| 408 | return; |
| 409 | } |
| 410 | let Ok(contents) = std::fs::read_to_string(settings_path) else { |
| 411 | return; |
| 412 | }; |
| 413 | let Ok(mut settings) = serde_json::from_str::<serde_json::Value>(&contents) else { |
| 414 | return; |
| 415 | }; |
| 416 | let Some(servers) = settings |
| 417 | .get_mut("mcpServers") |
| 418 | .and_then(|v| v.as_object_mut()) |
| 419 | else { |
| 420 | return; |
| 421 | }; |
| 422 | let removed = servers.remove("tracedecay").is_some(); |
| 423 | if !removed { |
| 424 | eprintln!( |
| 425 | " No tracedecay MCP server in {}, skipping", |
| 426 | settings_path.display() |
| 427 | ); |
| 428 | return; |
| 429 | } |
| 430 | if servers.is_empty() { |
| 431 | settings.as_object_mut().map(|o| o.remove("mcpServers")); |
| 432 | } |
| 433 | let is_empty = settings.as_object().is_some_and(serde_json::Map::is_empty); |
| 434 | if is_empty { |
| 435 | std::fs::remove_file(settings_path).ok(); |
| 436 | eprintln!( |
| 437 | "\x1b[32m✔\x1b[0m Removed {} (was empty)", |
| 438 | settings_path.display() |
| 439 | ); |
| 440 | } else if backup_and_write_json(settings_path, &settings) { |
| 441 | eprintln!( |
| 442 | "\x1b[32m✔\x1b[0m Removed tracedecay MCP server from {}", |
| 443 | settings_path.display() |
| 444 | ); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | // --------------------------------------------------------------------------- |
| 449 | // Prompt rules helpers |
no test coverage detected