Short answer: Codex CLI reads its MCP servers from a TOML file. Add one [mcp_servers.<name>] table per server to ~/.codex/config.toml, or use the codex mcp add command, which writes the same entry for you.
If you already configure MCP in Claude Code, Cursor or Gemini CLI, the idea is identical; only the file format differs. Codex uses TOML, while most other clients use JSON.
Where the configuration lives
- Global:
~/.codex/config.toml - Per project:
.codex/config.tomlin the repository - The server does not appear. Restart Codex after editing the file; the configuration is read at startup.
- TOML errors. Table names such as [mcp_servers.my-remote]
must be valid TOML, and strings need quotes. - npx
not found.Install Node.js, or use a server that ships as a Python tool and run it with uvx. - Authentication fails. Confirm the environment variable is set in the same shell that launches Codex.
- Command syntax changed. Run codex mcp --help
and check the current Codex documentation, because the CLI evolves.
Add a local (stdio) server
A local server is a program Codex starts and talks to over standard input and output. This example adds Context7, which provides current library documentation:
``toml
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp@latest"]
`
The same thing from the command line:
`bash
codex mcp add context7 -- npx -y @upstash/context7-mcp@latest
`
Everything after -- is the command Codex will run.
Add a remote (HTTP) server
A remote server runs elsewhere and is reached by URL. If it needs a token, keep the token in an environment variable and reference it by name:
`toml
[mcp_servers.my-remote]
url = "https://mcp.example.com/mcp"
bearer_token_env_var = "MY_REMOTE_API_KEY"
`
`bash
codex mcp add my-remote --url https://mcp.example.com/mcp --bearer-token-env-var MY_REMOTE_API_KEY
`
Then export the variable in your shell profile:
`bash
export MY_REMOTE_API_KEY="..."
`
Do not paste the token itself into config.toml, because that file is easy to commit by accident.
Try the 99plug MCP server
99plug exposes a public MCP endpoint at https://99plug.com/api/mcp for comparing SaaS tools and looking up setup commands:
`toml
[mcp_servers.99plug]
url = "https://99plug.com/api/mcp"
`
You can also browse ready-to-copy configs for other tools on our [plugins page](/plugins).
A sensible starter set
1. Context7 for up-to-date library docs. 2. Filesystem limited to the project directory. 3. GitHub with a narrowly scoped token, if you work with pull requests.
See our [best MCP servers shortlist](/blog/best-mcp-servers) for why these three come first.
Troubleshooting
Frequently asked questions
Can Codex use the same servers as Claude Code? Yes. MCP is a shared standard, so the same server works in both; you only translate the configuration format.
JSON or TOML? Codex CLI uses TOML. Cursor and Gemini CLI use JSON. Claude Code can use either its claude mcp add command or a JSON .mcp.json` file.
Is it safe to give Codex a filesystem server? Yes, if you limit it to the project folder and review writes before approving them.
*Checked against public documentation on 2 December 2026. Confirm syntax in the official Codex docs before relying on it.*