Where the Codex MCP config lives
There are two places, with different scopes.
~/.codex/config.toml. Your user-level config. Servers here are available in every project..codex/config.tomlin a repository. A project-scoped config. Servers here apply to that project.
Project config only loads when you trust the project. OpenAI's config basics page explains: "For security, Codex loads project .codex/ layers only when you trust the project." If you mark a project as untrusted, Codex skips its project-scoped layers.
When the same setting appears in both, the closer file wins. OpenAI's precedence list puts project config files above user config, ordered from the project root down to your working directory.
Which Codex clients share it
You set up a server once. The MCP page says: "The ChatGPT desktop app, Codex CLI, and IDE extension share this configuration." It adds that once your servers are configured, you can switch among those clients without redoing setup.
ChatGPT on the web is different. OpenAI's page says ChatGPT web uses remote MCP tools through plugins, and local Codex clients connect directly to MCP servers. A server in your config.toml is for Codex on your machine, not for ChatGPT in the browser.
Add a server from the CLI
The quickest way is the codex mcp add command. OpenAI's documentation shows the pattern for a local server: the server name, any environment variables with --env, then a double dash and the command that starts the server.
For a remote server, you pass --url with the server address instead of a command.
Other commands round it out:
codex mcp listshows configured servers.codex mcp login <server-name>starts an OAuth sign-in for servers that support it.codex mcp --helplists every MCP command.
The CLI writes to config.toml for you, so you can open the file afterward to see exactly what it added.
Keys for local (STDIO) servers
A local server runs as a process Codex starts. OpenAI's page lists the keys:
command, required: the command that starts the server.args: arguments to pass to it.env: environment variables to set for the server.env_vars: environment variables to allow and forward from your environment.cwd: the working directory to start the server from.
The difference between env and env_vars matters for secrets. env writes a value into the file. env_vars names a variable Codex reads from your environment, so the value stays out of config.toml.
Keys for remote (Streamable HTTP) servers
A remote server is one you reach at an address. The keys:
url, required: the server address.bearer_token_env_var: the name of an environment variable holding a bearer token.http_headers: header names with static values.env_http_headers: header names with values read from environment variables.auth: which sign-in method to try after configured tokens and headers, withoauthas the default.
OpenAI also notes what happens with no credentials: "If no credential source resolves, Codex can connect to the server without authentication."
Example entries to adapt
These are our examples, written as the lines you'd put in config.toml. Replace the names and paths with your own.
A local docs server for every project. In ~/.codex/config.toml, add a table named [mcp_servers.docs] with command set to the command that starts your docs server, and args set to any arguments it needs.
A ticketing server that needs a token. Add [mcp_servers.tickets] with url set to the server address and bearer_token_env_var set to the name of the variable that holds your token, such as TICKETS_TOKEN. The token itself stays in your shell environment.
A project-only database server. In the repository's .codex/config.toml, add [mcp_servers.db] with its command, and use env_vars to forward the connection string from your environment. Because it's in the project file, it only loads when you trust the project.
A server you want to keep but pause. Set enabled to false in its table. OpenAI's page describes this as a way to disable a server without deleting it.
Control tools and approvals
You don't have to accept every tool a server offers. OpenAI's page lists options for each server:
enabled_tools: an allow list of tools.disabled_tools: a deny list, applied after the allow list.default_tools_approval_mode: how Codex asks before using the server's tools. The supported values areauto,prompt,writes, andapprove. OpenAI says: "Thewritesmode prompts for tools that aren't marked read-only."tools.<tool>.approval_mode: an override for one tool.
Timeouts are configurable too. startup_timeout_sec sets how long a server has to start, and tool_timeout_sec sets how long a tool call can run.
If a server is essential, set required to true, and startup fails when the server isn't ready.
When servers start
Codex doesn't always start every server at the beginning of a thread. The MCP page says: "By default, Codex can wait until the first tool call to start an optional stdio server if it already has a usable tool list for that server." Without a cached tool list, Codex starts the server when the thread starts.
If you'd rather have servers start with every thread, OpenAI documents a feature setting, features.mcp_lazy_stdio_startup, which you set to false.
What a server tells Codex about itself
An MCP server can send its own guidance when it connects. OpenAI's page says: "Codex reads the MCP instructions field returned during initialization and uses it as server-wide guidance alongside the server's tools."
That's useful to know when a server behaves in a way you didn't configure. Some of its behavior may come from instructions the server's maintainer wrote, not from your config.toml. If you maintain a server yourself, OpenAI suggests using that field for workflows, constraints, and rate limits that apply across all its tools.
Moving your servers to another machine
Because MCP servers live in a plain text file, setting up a second machine is mostly a copy. Bring over the [mcp_servers.<server-name>] tables you need, then set the same environment variables on the new machine, since values named in env_vars and bearer_token_env_var aren't stored in the file.
OAuth servers may need you to sign in again with codex mcp login, and any local command a server uses has to exist on the new machine too. Project-scoped servers come along with the repository, but they still load only after you trust the project there.
OAuth sign-in
Some remote servers use OAuth. For those, run codex mcp login <server-name>. If your terminal has no browser, the documentation describes a --no-browser option: open the printed link in a browser, sign in, and paste the full redirect address back into the terminal.
If the server needs a pre-registered client, you pass its client ID when adding the server, and for a confidential client, its secret. OpenAI warns about where that ends up: "Codex saves the secret as mcp_servers.example.oauth.client_secret in config.toml. Keep that file private and out of version control."
You can also set scopes for a server to choose which OAuth scopes Codex requests.
Check that it loaded
After you add or edit a server, check it from the client you use:
- CLI:
codex mcp listshows configured servers. - Terminal UI: OpenAI's page says to use
/mcpto see your active MCP servers.
If a project server doesn't appear, check whether you've trusted the project. If a server appears but a tool doesn't, check enabled_tools and disabled_tools. If startup fails, check the command path and startup_timeout_sec.
For the rest of the file, see our guide to Codex config.toml examples.
What people try first
Editing the project file in an untrusted project. Codex skips project .codex/ layers until you trust the project.
Putting tokens directly in the file. Use bearer_token_env_var or env_vars to keep them in your environment.
Committing config.toml with an OAuth secret. OpenAI says to keep that file private and out of version control.
Expecting the server in ChatGPT on the web. Web uses plugins; config.toml is for local Codex clients.
Deleting a server to stop it. Set enabled to false instead.
Allowing every tool by default. Use default_tools_approval_mode and tool lists to narrow what runs without asking.
The Fix: Set up MCP servers in Codex cleanly
Step 1: Decide the scope
Personal servers go in ~/.codex/config.toml. Servers for one repository go in its .codex/config.toml.
Step 2: Add the server
Use codex mcp add, then open config.toml to review the table it wrote.
Step 3: Keep secrets out and narrow tools
Move tokens to environment variables, and set an approval mode and tool lists.
Step 4: Write down why each server is there
Note what each server is for and which tools you allowed, in your own words, outside the config file.
Setting this up in MemoryLake
config.toml tells Codex how to reach a server. The reasons behind your setup, such as why one tool needs approval or which server holds the source of truth for tickets, are context that other assistants could use too, and they don't belong in a config file.
MemoryLake is a memory layer for that kind of context, kept in one place you maintain and available to the assistants you connect, such as ChatGPT, Claude Code, and Codex.
You write the entries yourself, in your own words. Nothing is read out of, written to, or deleted from your config.toml files, your MCP servers, your Codex sign-ins, your Codex chats, or any vendor's store. Codex's MCP support works the way OpenAI describes it.
Step 1: Create an API key
Sign in and generate a key from the dashboard. Keep it somewhere private.

Step 2: Upload your first memories
Start with what you wrote in Step 4 of the fix: what each server is for and why. One topic per entry.

Step 3: Connect your AI & agents
Connect ChatGPT, Claude Code, Codex, and the other assistants you use, so the same context is there in each.

What this changes in practice
The first difference is easier review. When someone asks why a server is configured a certain way, the answer is written down.
The second is reach. The reasoning is available in other assistants, not only in Codex.
The third is safer changes. Knowing why a tool needs approval makes it less likely someone removes that setting by accident.
Best practices for Codex MCP config
Use the user file for personal servers. They follow you across projects.
Use the project file for shared servers. Remember that it loads only in trusted projects.
Keep secrets in environment variables. Use env_vars and bearer_token_env_var.
Narrow tools and set approvals. Start with prompt or writes.
Disable instead of deleting. Set enabled to false.
Check with codex mcp list or /mcp. Confirm what loaded before you rely on it.
Conclusion
Codex stores MCP servers in config.toml: ~/.codex/config.toml for every project, and .codex/config.toml for one repository, which loads only when you trust the project. The ChatGPT desktop app, Codex CLI, and IDE extension share this configuration, while ChatGPT on the web uses plugins instead.
Each server gets an [mcp_servers.<server-name>] table, with command for local servers and url for remote ones. You can add servers with codex mcp add, narrow their tools, set approval modes, keep secrets in environment variables, and check what loaded with codex mcp list or /mcp. Writing down why each server is there keeps that reasoning available wherever you work.