From 01d8bb53acbf6833af131ca64154c7fd5660a46a Mon Sep 17 00:00:00 2001 From: Bill ZHANG <36790218+Lutra-Fs@users.noreply.github.com> Date: Sat, 22 Nov 2025 23:46:30 +1100 Subject: [PATCH] fix(codex): use http_headers instead of headers in MCP config (#276) Codex CLI expects the field name to be `http_headers` (not `headers`) in the MCP server configuration TOML format. Changes: - Update import_from_codex() to read from both `http_headers` (correct) and `headers` (legacy) with priority to `http_headers` - Update json_server_to_toml_table() to write `http_headers` instead of `headers` - Update core_fields lists to use `http_headers` for HTTP/SSE types This follows the same pattern as the recent Gemini fix and ensures backward compatibility while generating correct Codex-compatible configs. --- src-tauri/src/mcp.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/mcp.rs b/src-tauri/src/mcp.rs index 8940ebc..30289d4 100644 --- a/src-tauri/src/mcp.rs +++ b/src-tauri/src/mcp.rs @@ -449,7 +449,7 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result // 核心字段(需要手动处理的字段) let core_fields = match typ { "stdio" => vec!["type", "command", "args", "env", "cwd"], - "http" | "sse" => vec!["type", "url", "headers"], + "http" | "sse" => vec!["type", "url", "http_headers"], _ => vec!["type"], }; @@ -490,7 +490,13 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result if let Some(url) = entry_tbl.get("url").and_then(|v| v.as_str()) { spec.insert("url".into(), json!(url)); } - if let Some(headers_tbl) = entry_tbl.get("headers").and_then(|v| v.as_table()) { + // Read from http_headers (correct Codex format) or headers (legacy) with priority to http_headers + let headers_tbl = entry_tbl + .get("http_headers") + .and_then(|v| v.as_table()) + .or_else(|| entry_tbl.get("headers").and_then(|v| v.as_table())); + + if let Some(headers_tbl) = headers_tbl { let mut headers_json = serde_json::Map::new(); for (k, v) in headers_tbl.iter() { if let Some(sv) = v.as_str() { @@ -910,7 +916,7 @@ fn json_server_to_toml_table(spec: &Value) -> Result // 定义核心字段(已在下方处理,跳过通用转换) let core_fields = match typ { "stdio" => vec!["type", "command", "args", "env", "cwd"], - "http" | "sse" => vec!["type", "url", "headers"], + "http" | "sse" => vec!["type", "url", "http_headers"], _ => vec!["type"], }; @@ -988,7 +994,7 @@ fn json_server_to_toml_table(spec: &Value) -> Result } } if !h_tbl.is_empty() { - t["headers"] = Item::Table(h_tbl); + t["http_headers"] = Item::Table(h_tbl); } } }