openai/codex · error · anyhow::Error

must be valid Unicode for remote MCP stdio

Error message

{label} must be valid Unicode for remote MCP stdio

What it means

Validation guard in ExecEnvPolicy's os_string_to_process_api_string: an environment variable name or value in the MCP server's configured env is not valid Unicode, so it cannot be passed through the process API used for remote stdio. The offending OsString is labeled in the message.

Solutions

  1. Fix the env_vars entry so its name and value are valid UTF-8
  2. Remove the non-Unicode variable from the MCP server configuration
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/rmcp-client/src/stdio_server_launcher.rs:662 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/acaf78800e02e6ba. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rmcp-client/src/stdio_server_launcher.rs:662

        }
        Ok(argv)
    }

    fn process_api_env(env: HashMap<OsString, OsString>) -> Result<HashMap<String, String>> {
        env.into_iter()
            .map(|(key, value)| {
                Ok((
                    Self::os_string_to_process_api_string(key, "environment variable name")?,
                    Self::os_string_to_process_api_string(value, "environment variable value")?,
                ))
            })
            .collect()
    }

    fn os_string_to_process_api_string(value: OsString, label: &str) -> Result<String> {
        value
            .into_string()
            .map_err(|_| anyhow!("{label} must be valid Unicode for remote MCP stdio"))
    }

    fn remote_env_policy(remote_env_vars: &[String]) -> ExecEnvPolicy {
        let include_only = if remote_env_vars.is_empty() {
            Vec::new()
        } else {
            // `source = "remote"` means the value is read from the executor's
            // environment, not copied from Codex. Start from `All` only so the
            // named remote variable is available to the filter below; the
            // effective child env is still limited by `include_only`.
            crate::utils::DEFAULT_ENV_VARS
                .iter()
                .map(|name| (*name).to_string())
                .chain(remote_env_vars.iter().cloned())
                .collect()
        };
        ExecEnvPolicy {
            inherit: if remote_env_vars.is_empty() {

View on GitHub (pinned to 339751715c)