rulesync icon indicating copy to clipboard operation
rulesync copied to clipboard

codexcli MCP: `${VAR}` / `${VAR:-default}` from `.mcp.json` are emitted verbatim into `config.toml`

Open artgas1 opened this issue 2 months ago • 0 comments

Summary

Claude Code expands ${VAR} and ${VAR:-default} in .mcp.json, including in url and headers (docs, "Environment variable expansion in .mcp.json"). When generating for codexcli, rulesync copies those strings verbatim into .codex/config.toml. Codex does not expand them, so the servers break without any warning.

Reproduction (rulesync 21.0.0, Codex CLI 0.153.1)

.mcp.json, based on the example in the Claude Code docs:

{
  "mcpServers": {
    "api-server": {
      "type": "http",
      "url": "${API_BASE_URL:-https://api.example.com}/mcp",
      "headers": { "Authorization": "Bearer ${API_KEY}" }
    },
    "other": {
      "type": "http",
      "url": "https://mcp.example.org/mcp",
      "headers": { "X-Api-Key": "${OTHER_KEY}" }
    }
  }
}
rulesync import --targets claudecode --features mcp
rulesync generate --targets codexcli --features mcp

Generated .codex/config.toml:

[mcp_servers.api-server]
url = "${API_BASE_URL:-https://api.example.com}/mcp"

[mcp_servers.api-server.http_headers]
Authorization = "Bearer ${API_KEY}"

[mcp_servers.other]
url = "https://mcp.example.org/mcp"

[mcp_servers.other.http_headers]
X-Api-Key = "${OTHER_KEY}"

What Codex does with it

  • url: Codex 0.153.1 fails at startup with relative URL without a base. This happens even when the variable is set: I checked with url = "${PROBE_MCP_URL}" and PROBE_MCP_URL=http://127.0.0.1:9/mcp exported.
  • http_headers: the values are static, so the literal Bearer ${API_KEY} is sent. In my test, real servers configured this way answered 401/403.

rulesync printed no warnings in either case.

Suggestion

Codex has native equivalents for most of this (config reference):

  • Authorization: Bearer ${VAR} → bearer_token_env_var = "VAR"
  • a header whose whole value is ${VAR} → env_http_headers = { "X-Api-Key" = "VAR" }
  • ${VAR:-default} in url: Codex has no equivalent. Emitting the default and warning that the override is lost would keep the server working.
  • Anything else still containing ${: warn instead of emitting it silently.

artgas1 avatar Sep 26 '26 12:09 artgas1