Register MCP server in opencode.json. Safety: creates a `.bak` backup before writing and restores it on any error. Uses strict JSON parsing so an existing file with invalid syntax is never silently replaced with an empty object.
(config_path: &Path, tracedecay_bin: &str)
| 203 | /// error. Uses strict JSON parsing so an existing file with invalid syntax |
| 204 | /// is never silently replaced with an empty object. |
| 205 | fn install_mcp_server(config_path: &Path, tracedecay_bin: &str) -> Result<()> { |
| 206 | let backup = backup_config_file(config_path)?; |
| 207 | let mut config = match load_json_file_strict(config_path) { |
| 208 | Ok(v) => v, |
| 209 | Err(e) => { |
| 210 | if let Some(ref b) = backup { |
| 211 | eprintln!(" Backup preserved at: {}", b.display()); |
| 212 | } |
| 213 | return Err(e); |
| 214 | } |
| 215 | }; |
| 216 | |
| 217 | config["mcp"]["tracedecay"] = json!({ |
| 218 | "type": "local", |
| 219 | "command": [tracedecay_bin, "serve"] |
| 220 | }); |
| 221 | |
| 222 | safe_write_json_file(config_path, &config, backup.as_deref())?; |
| 223 | eprintln!( |
| 224 | "\x1b[32m✔\x1b[0m Added tracedecay MCP server to {}", |
| 225 | config_path.display() |
| 226 | ); |
| 227 | Ok(()) |
| 228 | } |
| 229 | |
| 230 | /// Install-or-refresh prompt rules in AGENTS.md. |
| 231 | fn install_prompt_rules(prompt_path: &Path) -> Result<()> { |
no test coverage detected