Back to all articles
TutorialDecember 1, 2026·10 min read

How to Add an MCP Server to Codex in config.toml (2026)

You want Codex to look up tickets in your issue tracker, or read the docs for a library your team depends on. The tool you need offers an MCP server, and its instructions say to add it to Codex. You search for the Codex MCP config and find two file locations, a CLI command, and a long list of options. You'd like to know which file to edit, what goes in it, and how to check that Codex actually picked the server up.

The short answer: Codex keeps MCP servers in config.toml. OpenAI's documentation says: "By default this is ~/.codex/config.toml, but you can also scope MCP servers to a project with .codex/config.toml (trusted projects only)." Each server gets its own [mcp_servers.<server-name>] table. You can add one with codex mcp add or by editing the file, and codex mcp list or /mcp in the terminal shows what Codex loaded.

This guide covers where the config lives, which Codex clients share it, how to add a server from the CLI, the keys for local and remote servers, example entries you can adapt, how to control tools and approvals, how OAuth sign-in works, and how to check that everything loaded.

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.toml in 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 list shows configured servers.
  • codex mcp login <server-name> starts an OAuth sign-in for servers that support it.
  • codex mcp --help lists 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, with oauth as 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 are auto, prompt, writes, and approve. OpenAI says: "The writes mode 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 list shows configured servers.
  • Terminal UI: OpenAI's page says to use /mcp to 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.

The MemoryLake console showing the API keys screen, where a new key is created and copied for use in an agent
The MemoryLake console showing the API keys screen, where a new key is created and copied for use in an agent

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.

The MemoryLake workspace with the first documents uploaded, listing each file as it becomes searchable memory
The MemoryLake workspace with the first documents uploaded, listing each file as it becomes searchable memory

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.

The MemoryLake integrations screen listing the AI clients and agent frameworks that can be connected to the memory layer
The MemoryLake integrations screen listing the AI clients and agent frameworks that can be connected to the memory layer

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.

Frequently asked questions

Where is the Codex MCP config file?

In ~/.codex/config.toml by default, or .codex/config.toml in a trusted project.

How do I add an MCP server to Codex?

Run codex mcp add with a server name and either the command to start it or --url for a remote server, or edit config.toml directly.

What's the config.toml format for MCP servers?

Each server gets a [mcp_servers.<server-name>] table, with command for local servers or url for remote ones.

Why doesn't my project MCP server load?

Codex loads project .codex/ layers only when you trust the project.

Do the Codex CLI and desktop app share MCP servers?

Yes. OpenAI says the ChatGPT desktop app, Codex CLI, and IDE extension share this configuration.

How do I turn off an MCP server without deleting it?

Set enabled to false in its table.

How do I see which MCP servers are active?

Run codex mcp list, or use /mcp in the Codex terminal UI.