Codex 0.158 报 unknown configuration field `mcp_servers.*.type`:Codex 投影不应写入 `type`
Author: tingfeng347Created Sep 28, 2026Updated Sep 28, 2026
Self Checks / 自检
- I have read the FAQ section in README.
- I have searched for existing issues, including closed ones.
CC Switch Version / 版本号
3.20.4 (3.20.4)
Operating System / 操作系统
Arch Linux(macOS/Windows 同样受影响)
Related App / 涉及应用
Codex
Steps to Reproduce / 重现步骤
- 用 cc-switch 管理至少一个 MCP(例如 blender / context7)。
- 让 cc-switch 同步一次 MCP,或切换一次 Codex provider,使
~/.codex/config.toml被重写。 - 启动 Codex 0.158+(CLI 或 Desktop),提示:
Codex is ignoring 6 unrecognized configuration settings. Check for typos or deprecated settings.
user (/home/user/.codex/config.toml): mcp_servers.blender.type is ignored.
... and 3 more ignored settings.- 严格校验可直接复现同一问题:
$ codex app-server --strict-config < /dev/null
Error: /home/user/.codex/config.toml:138:1: unknown configuration field `mcp_servers.context7.type`Root Cause / 根因
Codex 的 [mcp_servers.*] 没有 type 字段,传输方式由 command(stdio)或 url(streamable HTTP)推断。cc-switch 的 Codex 投影 src-tauri/src/mcp/codex.rs::json_server_to_toml_table 无条件执行 t["type"] = typ,把 Claude 习惯的 type = "stdio"|"http" 一并写进 Codex 配置:
[mcp_servers.context7]
type = "stdio" # ← Codex 不认这个键
command = "context7-mcp"Codex 0.158 起新增严格配置校验,会把无法识别的键当作未知配置字段告警(此前只是静默忽略);由于每次 sync_all_enabled / 切换 provider 都会重写,告警会反复出现。type 被忽略不影响功能(codex mcp list 的 transport 仍正确),但会污染 Codex 启动输出。
Expected Behavior / 期望行为
cc-switch 写 Codex 投影时不输出 type;DB 里的统一 server_config 仍保留 type 供各客户端共享。
Actual Behavior / 实际行为
每次都把 type = "stdio"/"http" 写进 [mcp_servers.*],触发 Codex 0.158+ 的未知字段告警。
Additional Context / 补充信息
- 手动删除
type行后codex app-server --strict-config通过、codex mcp list的 transport 仍正确。 - 相关:#7613(同样是 config.toml 被写入
type = "stdio"引发的问题)。 - 修复 PR:https://github.com/farion1231/cc-switch/pull/7735
兼容性说明(为什么删除 type 是安全的)
type从来不是 Codex[mcp_servers.*]的合法键(官方 config reference 与 codex-rs 的RawMcpServerConfig均无该字段);传输方式一直由command(stdio)/url(streamable HTTP)推断。- 旧版 Codex 会静默忽略该未知键(所以此前“一直能用”),删除它对旧版无影响。
- Grok Build 复用同一转换器,且
json_server_to_grokbuild_toml_table本来就remove("type"),行为不变。 - 唯一依赖该键的是 cc-switch 自身的
import_from_codex:它此前缺type就按 stdio 处理且不看url,导致 url-only 的 Codex 配置被validate_server_spec(stdio 缺 command)拒掉并跳过。本次 PR 一并修正为按url推断http(与import_from_grokbuild的toml_server_to_json一致),并补充单元 + 集成测试。
Source: farion1231/cc-switch