(
os: &Os,
agent_path: impl AsRef<Path>,
legacy_mcp_config: &mut Option<McpServerConfig>,
mcp_enabled: bool,
output: &mut impl Write,
)
| 374 | } |
| 375 | |
| 376 | pub async fn load( |
| 377 | os: &Os, |
| 378 | agent_path: impl AsRef<Path>, |
| 379 | legacy_mcp_config: &mut Option<McpServerConfig>, |
| 380 | mcp_enabled: bool, |
| 381 | output: &mut impl Write, |
| 382 | ) -> Result<Agent, AgentConfigError> { |
| 383 | let content = os.fs.read(&agent_path).await?; |
| 384 | let mut agent = serde_json::from_slice::<Agent>(&content).map_err(|e| AgentConfigError::InvalidJson { |
| 385 | error: e, |
| 386 | path: agent_path.as_ref().to_path_buf(), |
| 387 | })?; |
| 388 | |
| 389 | if mcp_enabled { |
| 390 | if agent.use_legacy_mcp_json && legacy_mcp_config.is_none() { |
| 391 | let config = load_legacy_mcp_config(os).await.unwrap_or_default(); |
| 392 | if let Some(config) = config { |
| 393 | legacy_mcp_config.replace(config); |
| 394 | } |
| 395 | } |
| 396 | agent.thaw(agent_path.as_ref(), legacy_mcp_config.as_ref(), output)?; |
| 397 | } else { |
| 398 | agent.clear_mcp_configs(); |
| 399 | // Thaw the agent with empty MCP config to finalize normalization. |
| 400 | agent.thaw(agent_path.as_ref(), None, output)?; |
| 401 | } |
| 402 | Ok(agent) |
| 403 | } |
| 404 | |
| 405 | /// Clear all MCP configurations while preserving built-in tools |
| 406 | pub fn clear_mcp_configs(&mut self) { |
nothing calls this directly
no test coverage detected