Convert McpServerConfig into a Codex CLI TOML server table
(config: &McpServerConfig)
| 1026 | |
| 1027 | /// Convert McpServerConfig into a Codex CLI TOML server table |
| 1028 | fn server_to_codex_toml(config: &McpServerConfig) -> TomlValue { |
| 1029 | let mut table = TomlTable::new(); |
| 1030 | |
| 1031 | if let Some(ref cmd) = config.command { |
| 1032 | table.insert("command".to_string(), TomlValue::String(cmd.clone())); |
| 1033 | } |
| 1034 | |
| 1035 | if !config.args.is_empty() { |
| 1036 | table.insert( |
| 1037 | "args".to_string(), |
| 1038 | TomlValue::Array(config.args.iter().cloned().map(TomlValue::String).collect()), |
| 1039 | ); |
| 1040 | } |
| 1041 | |
| 1042 | if !config.env.is_empty() { |
| 1043 | let mut env_table = TomlTable::new(); |
| 1044 | for (k, v) in &config.env { |
| 1045 | env_table.insert(k.clone(), TomlValue::String(v.clone())); |
| 1046 | } |
| 1047 | table.insert("env".to_string(), TomlValue::Table(env_table)); |
| 1048 | } |
| 1049 | |
| 1050 | if let Some(ref url) = config.url { |
| 1051 | table.insert("url".to_string(), TomlValue::String(url.clone())); |
| 1052 | } |
| 1053 | |
| 1054 | if !config.headers.is_empty() { |
| 1055 | let mut headers_table = TomlTable::new(); |
| 1056 | for (k, v) in &config.headers { |
| 1057 | headers_table.insert(k.clone(), TomlValue::String(v.clone())); |
| 1058 | } |
| 1059 | // Codex MCP schema uses `http_headers` for static headers. |
| 1060 | table.insert("http_headers".to_string(), TomlValue::Table(headers_table)); |
| 1061 | } |
| 1062 | |
| 1063 | TomlValue::Table(table) |
| 1064 | } |
| 1065 | |
| 1066 | // ============================================================================= |
| 1067 | // MCP Generator |
no test coverage detected