Remove MCP server from opencode.json.
(config_path: &Path)
| 244 | |
| 245 | /// Remove MCP server from opencode.json. |
| 246 | fn uninstall_mcp_server(config_path: &Path) { |
| 247 | if !config_path.exists() { |
| 248 | return; |
| 249 | } |
| 250 | let Ok(contents) = std::fs::read_to_string(config_path) else { |
| 251 | return; |
| 252 | }; |
| 253 | let Ok(mut config) = serde_json::from_str::<serde_json::Value>(&contents) else { |
| 254 | return; |
| 255 | }; |
| 256 | let Some(mcp) = config.get_mut("mcp").and_then(|v| v.as_object_mut()) else { |
| 257 | return; |
| 258 | }; |
| 259 | if mcp.remove("tracedecay").is_none() { |
| 260 | eprintln!( |
| 261 | " No tracedecay MCP server in {}, skipping", |
| 262 | config_path.display() |
| 263 | ); |
| 264 | return; |
| 265 | } |
| 266 | if mcp.is_empty() { |
| 267 | config.as_object_mut().map(|o| o.remove("mcp")); |
| 268 | } |
| 269 | let is_empty = config.as_object().is_some_and(serde_json::Map::is_empty); |
| 270 | if is_empty { |
| 271 | std::fs::remove_file(config_path).ok(); |
| 272 | eprintln!( |
| 273 | "\x1b[32m✔\x1b[0m Removed {} (was empty)", |
| 274 | config_path.display() |
| 275 | ); |
| 276 | } else if backup_and_write_json(config_path, &config) { |
| 277 | eprintln!( |
| 278 | "\x1b[32m✔\x1b[0m Removed tracedecay MCP server from {}", |
| 279 | config_path.display() |
| 280 | ); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /// Remove tracedecay rules from AGENTS.md. |
| 285 | fn uninstall_prompt_rules(prompt_path: &Path) { |
no test coverage detected