Codex MCP Setup: Connect Tools and Live Context
Connect OpenAI Codex to MCP servers through the CLI, desktop app, IDE, or config.toml — with practical scoping, OAuth, and tool-approval guidance.
Codex uses Model Context Protocol servers to reach live documentation, developer tools, and external systems. Local clients support STDIO and Streamable HTTP servers and share config.toml. Add only the servers a workflow needs, keep secrets in environment variables or OAuth, constrain exposed tools, and require approval for writes or sensitive side effects.
Steps at a glance
- Choose the scope. Decide whether the server belongs in user configuration for every project or in a trusted project's .codex/config.toml for repository-specific use.
- Add the server. Configure a local STDIO command or a remote Streamable HTTP URL through codex mcp add, the desktop or IDE settings, or config.toml.
- Configure authentication safely. Use environment-variable references for bearer tokens or run codex mcp login for OAuth; do not commit credential values.
- Limit tools and approvals. Allow only the tools the workflow needs and require prompts for writes or sensitive side effects.
- Restart and verify. Restart the relevant Codex client, inspect the server with /mcp or codex mcp list, and test one read-only call before enabling actions.
Key takeaways
- Use MCP when Codex needs live external data or controlled actions; use AGENTS.md for rules and skills for reusable procedure.
- Codex supports local STDIO servers and remote Streamable HTTP servers, including bearer-token and OAuth authentication.
- The desktop app, CLI, and IDE extension share MCP configuration on the same Codex host.
- Scope servers to a trusted project when the integration is repository-specific; use user configuration only for tools needed across projects.
- Prefer allowlists and prompt-on-write approvals over exposing a server's entire action surface automatically.
Model Context Protocol gives Codex a standard way to use live tools and data outside the repository. An MCP server can expose search, issue trackers, design files, browser controls, observability data, databases, or internal APIs as typed tools the agent can select during a task.
MCP is the integration layer, not the instruction layer. Use AGENTS.md to tell Codex how a repository works, and a skill to teach a repeatable procedure. Use MCP when that procedure needs information that changes or an action in another system.
Choose the transport
Codex supports two MCP server types for local clients:
- STDIO — Codex starts a local process and communicates through standard input and output. This is common for developer tools installed with npm, Python, or a local binary.
- Streamable HTTP — Codex connects to a stable remote URL. This suits hosted and team services and can use bearer tokens or OAuth.
The ChatGPT desktop app, Codex CLI, and Codex IDE extension share MCP configuration on the same host. Hosted ChatGPT Work uses plugins for remote MCP-backed tools rather than reading the local machine's config file.
Add a local server from the CLI
The fastest path for a local STDIO server is codex mcp add:
codex mcp add context7 -- npx -y @upstash/context7-mcp
codex mcp listThe name comes before --; everything after it is the command Codex launches. Pass environment values with --env when the server needs them, but avoid leaving secrets in shell history. Prefer forwarding a pre-existing environment variable or using the authentication mechanism supported by the server.
In the interactive terminal UI, /mcp shows active servers. The desktop app and IDE extension provide an MCP servers settings screen where you can add either transport, authenticate, enable or disable servers, and restart the client.
Configure with config.toml
User-level configuration lives at ~/.codex/config.toml. A trusted repository can carry project-specific configuration in .codex/config.toml; use that when the server exists only to support this codebase.
Local STDIO server:
[mcp_servers.docs]
command = "npx"
args = ["-y", "@example/docs-mcp"]
env_vars = ["DOCS_TOKEN"]
startup_timeout_sec = 20
tool_timeout_sec = 45Remote Streamable HTTP server:
[mcp_servers.issues]
url = "https://mcp.example.com/api"
bearer_token_env_var = "ISSUES_MCP_TOKEN"
enabled_tools = ["search_issues", "get_issue", "add_comment"]
default_tools_approval_mode = "writes"env_vars forwards named variables to a local process. bearer_token_env_var tells Codex which environment variable contains the remote token; the credential value stays outside the configuration file.
For OAuth-capable servers, add the server and run:
codex mcp login issuesTreat the tool list as a permission surface
Connecting a server is not only a context decision. Every exposed tool expands what the agent can attempt. A read-only search tool and a “delete production deployment” tool should not share the same friction.
Codex configuration can narrow and govern that surface:
enabled_toolscreates an allowlist.disabled_toolsremoves tools after the allowlist is applied.default_tools_approval_modesets the server-wide behavior.- Per-tool approval settings can make a sensitive action stricter than the rest.
A safe default is to expose the small set of read operations the workflow needs, prompt for writes, and require explicit approval for destructive or externally visible actions. Do not rely only on a tool description to enforce security; the MCP server itself must validate authorization and arguments.
Verify in layers
When a server does not appear or a call fails, check the stack from the bottom up:
- Process or URL — can the local command start, or can the host reach the remote endpoint?
- Authentication — is the expected environment variable present, or has OAuth login completed?
- Configuration scope — is the project trusted, and did this client load the intended user or project config?
- Server initialization — does
/mcporcodex mcp listshow it as enabled? - Tool policy — is the requested tool allowed and does its approval mode permit the call?
- Workflow routing — does the prompt or skill make clear when Codex should use the tool?
Test one harmless read operation before enabling writes. That separates transport and auth problems from side-effect policy, and it gives you a known-good baseline.
WARNING
Tool output is still external input. Documentation pages, issue bodies, and web content can contain instructions aimed at the model. Keep permissions scoped and ask Codex to treat retrieved content as data, not authority over the task.
A good integration boundary
Start with one integration that removes a repeated manual loop: current library docs, a design source, issue context, or error traces. Pair it with a focused skill only if the organization needs a consistent multi-step method around those tools. Add more servers after you can explain the data, actions, credentials, and approval policy of the ones already installed.
Official reference: Model Context Protocol in Codex.
Frequently asked questions
- What is MCP in Codex?
- Model Context Protocol is the standard Codex uses to connect to external tools and context. An MCP server can expose functions, resources, prompts, and server-level instructions so Codex can search documentation, inspect designs, read issues, or perform controlled actions.
- How do I add an MCP server to Codex?
- For a local STDIO server, run codex mcp add <name> -- <command>. You can also add STDIO or Streamable HTTP servers from the desktop app or IDE settings, or define them directly under mcp_servers in config.toml.
- Where is Codex MCP configuration stored?
- User-level configuration lives in ~/.codex/config.toml. Trusted repositories can add project-scoped settings in .codex/config.toml. The desktop app, CLI, and IDE extension on the same host share these configuration layers.
- Is it safe to connect Codex to an MCP server?
- Treat an MCP server like any integration with data and permissions: verify who operates it, limit credentials and exposed tools, require approval for writes or side effects, and avoid putting secrets directly in checked-in configuration.
Related
- MCP (Model Context Protocol)MCP is the open standard for connecting AI models to external tools and data: write one server, and any MCP client — Claude Code, IDEs, agents — can use it.
- Adding MCP Servers to Claude Code: Local, Remote, and Project-ScopedThe complete claude mcp add reference — stdio vs HTTP transports, local/project/user scopes, .mcp.json with env expansion, OAuth via /mcp, and the gotchas.
- Building an MCP ServerAn accurate introduction to the Model Context Protocol: server anatomy, transports, and connecting a tool to Claude Code.
- Codex Skills: Build Reusable Workflows with SKILL.mdCreate, install, and test Codex skills with SKILL.md — including trigger descriptions, repo and user paths, progressive disclosure, and distribution.
- AGENTS.md for Codex: Project Instructions That Actually WorkWrite an effective AGENTS.md for OpenAI Codex — what belongs in it, how nested overrides work, and how to verify the instructions Codex loaded.
- OpenAI Codex: A Practical Guide for DevelopersLearn how OpenAI Codex works across the terminal, IDE, desktop app, and cloud — then set up a safe, repeatable workflow for real repositories.
- MCP Server ScaffolderScaffold a new Model Context Protocol (MCP) server from a description — pick the SDK and transport, generate a typed first tool with a strict schema, and wire up MCP Inspector testing and the client-registration command. Use when starting a new MCP server and you want a correct, runnable skeleton instead of copying a README.
- Codex config.toml: Settings, Precedence, and Safe DefaultsConfigure OpenAI Codex with config.toml — user and project scopes, precedence, sandbox and approvals, MCP, subagents, profiles, and safe defaults.
- Codex Troubleshooting: A Layer-by-Layer Recovery GuideTroubleshoot OpenAI Codex when files, commands, configuration, worktrees, MCP, or app features misbehave — with a fast isolation and recovery sequence.
- Codex CLIOpenAI's open-source terminal coding agent with sandboxed execution and two-layer approval controls.