ZhuLinsen/daily_stock_analysis · error · CodexAppServerError

unsupported_mcp_name

unsupported_mcp_name

Error message

Configured MCP name cannot be safely expressed as a transient CLI override

What it means

The MCP hardening step disables every configured MCP server by appending `-c mcp_servers.<name>.enabled=false` overrides to the argv. A server name that fails the _TOML_BARE_KEY regex (bare TOML key: [A-Za-z0-9_-]+) cannot be expressed as a dotted config key on the CLI without quoting/injection risk, so the code refuses with code 'unsupported_mcp_name'.

Source

Thrown at src/agent/codex_app_server_transport.py:1099

        tool_surface=empty_surface,
        tool_context=ToolAccessContext(),
        request_timeout=timeout,
        deadline=deadline,
        cancel_event=cancel_event,
    ) as client:
        assert client.safe_cwd is not None
        result = client.request("config/read", {"cwd": str(client.safe_cwd), "includeLayers": False})
        config = result.get("config")
        if not isinstance(config, dict):
            raise CodexAppServerError("protocol_error", "config/read did not return an effective config")
        mcp_servers = config.get("mcp_servers") or {}
        if not isinstance(mcp_servers, dict) or not all(isinstance(name, str) for name in mcp_servers):
            raise CodexAppServerError("protocol_error", "config/read returned invalid MCP configuration")

    hardened = list(command)
    for name in sorted(mcp_servers):
        if _TOML_BARE_KEY.fullmatch(name) is None:
            raise CodexAppServerError(
                "unsupported_mcp_name",
                "Configured MCP name cannot be safely expressed as a transient CLI override",
            )
        hardened.extend(["-c", f"mcp_servers.{name}.enabled=false"])
    return hardened


def build_hardened_command(
    *,
    timeout: float,
    executable: str = "codex",
    deadline: Optional[float] = None,
    cancel_event: Optional[threading.Event] = None,
) -> list[str]:
    """Build the fixed production argv with every configured MCP disabled."""
    return harden_command_against_configured_mcp(
        resolve_command(executable),
        timeout=timeout,

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Rename the MCP server in ~/.codex/config.toml to a bare key: letters, digits, underscore, hyphen only (e.g. context7_dev)
  2. If the name is intentional, disable that server manually or exclude this hardening path for that config
  3. Validate names with the same regex before launching: re.fullmatch(r'[A-Za-z0-9_-]+', name)
  4. Document the naming constraint wherever users author MCP config for this agent

Example fix

# before (~/.codex/config.toml)
[mcp_servers."my server.v2"]
command = "npx"

# after
[mcp_servers.my_server_v2]
command = "npx"
Defensive patterns

Strategy: validation

Validate before calling

import re

TOML_BARE_KEY = re.compile(r"[A-Za-z0-9_-]+")
bad = [n for n in mcp_server_names if not TOML_BARE_KEY.fullmatch(n)]
if bad:
    raise ValueError(f"rename MCP servers to bare keys: {bad}")

Type guard

def is_toml_bare_key(name: str) -> bool:
    return bool(re.fullmatch(r"[A-Za-z0-9_-]+", name))

Prevention

When it happens

Trigger: An ~/.codex/config.toml defining an MCP server whose name contains dots, spaces, quotes, unicode, or other characters outside the bare-key charset — e.g. [mcp_servers."my server.v2"] — while the hardening path tries to build the override list.

Common situations: Quoted TOML keys with special characters in server names; names copied from URLs or product names ('context7-mcp (dev)'); configs authored for a codex version that permits such names meeting a hardening path that does not.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/df41065cce9dd782. Report an issue: GitHub.