| 19 | |
| 20 | impl McpServerConfig { |
| 21 | pub async fn load_from_file(os: &Os, path: impl AsRef<Path>) -> eyre::Result<Self> { |
| 22 | let contents = os.fs.read(path.as_ref()).await?; |
| 23 | let value = serde_json::from_slice::<serde_json::Value>(&contents)?; |
| 24 | // We need to extract mcp_servers field from the value because we have annotated |
| 25 | // [McpServerConfig] with transparent. Transparent was added because we want to preserve |
| 26 | // the type in agent. |
| 27 | let config = value |
| 28 | .get("mcpServers") |
| 29 | .cloned() |
| 30 | .ok_or(eyre::eyre!("No mcp servers found in config"))?; |
| 31 | Ok(serde_json::from_value(config)?) |
| 32 | } |
| 33 | |
| 34 | pub async fn save_to_file(&self, os: &Os, path: impl AsRef<Path>) -> eyre::Result<()> { |
| 35 | let json = self.to_non_transparent_json_pretty()?; |