LIVE|CLI v0.144.0·model GPT-5.6 Sol·verified 2026-07-09
Codex Insider
The unofficial wire for OpenAI Codex.
config.toml key

mcp_servers.<id>.env

default: unset

Published Jul 15, 2026 · Verified against the official config docs

What it does

Environment variables handed to a stdio MCP server, written as a TOML map under [mcp_servers.<id>.env]. Unset by default. Codex builds the server's environment from a short whitelist rather than passing your whole shell, so this key, plus the env_vars forwarding list, is how API keys actually reach the server. HTTP servers skip it and use bearer_token_env_var or env_http_headers instead.

Values

Key Type Default
mcp_servers.<id>.env map of string to string unset
mcp_servers.<id>.env_vars array of strings or { name, source } objects unset

env sets variables to literal values. env_vars is a whitelist: you name a variable and Codex forwards its value from the environment Codex itself is running in. String entries default to source = "local"; source = "remote" only applies to executor-backed remote stdio, per the config reference.

The official example from the MCP docs:

[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
env_vars = ["LOCAL_TOKEN"]

[mcp_servers.context7.env]
MY_ENV_VAR = "MY_ENV_VALUE"

codex mcp add <name> --env VAR=VALUE -- <command> writes the env entries for you.

When to change it

  1. The server needs an API key and you’re fine keeping it in config.toml: put it under [mcp_servers.<id>.env].
  2. The key already lives in your shell (exported in .zshrc, or dropped in by a secret manager): whitelist it with env_vars = ["MY_TOKEN"] instead of copying the plaintext into a config file.
  3. The server starts fine in your terminal but dies under Codex on Windows or behind a corporate proxy: you likely need to forward system variables yourself. See Gotchas.

Gotchas

Codex does not hand a stdio server your full environment. It builds the child’s env from a short built-in whitelist, which is why a server that runs clean from your terminal can fail inside Codex. Issue #4180 documented Windows startups where only PATH, PATHEXT, USERNAME, USERDOMAIN, USERPROFILE, TEMP, and TMP survived — that one is closed, and #29124 reports proxy and CA-cert variables getting stripped the same way.

The docs don’t say whether $VAR or ${VAR} expands inside env values; issue #7521 is an open ask to document exactly that. Until it’s answered, treat env values as literal strings and use env_vars when the value should come from your shell.

env is stdio-only. A url-based HTTP server takes bearer_token_env_var for the token and env_http_headers for headers filled from environment variables, per the config reference.

  • mcp_servers covers the parent table: command, args, url, timeouts, enabled.
  • shell_environment_policy controls the same problem for Codex’s own shell sessions, separate from MCP child processes.
  • Server failing at launch rather than missing a key? Check /errors/.

Sources