Getting StartedΒ·
beginner
Β·5 min readΒ·Jul 10, 2026

How to Configure MCP Servers in OpenAI Codex CLI (2026 Guide)

Step-by-step config.toml guide and CLI commands for connecting MCP servers to OpenAI Codex CLI.

OpenAI CodexCodex MCPMCPConfigurationconfig.tomlSetup
Interactive Tool
1-Click Export

Generate & Validate Multi-Client MCP Config

One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.

Open in Generator

Configure MCP Servers in Codex

Connecting your OpenAI Codex CLI to external tools is done via the Model Context Protocol (MCP). This guide will walk you through setting up your config.toml file to integrate various MCP servers step-by-step.

Prerequisites

  • β–ΈOpenAI Codex CLI installed (v2.0.0 or higher)
  • β–ΈNode.js or Python (depending on the MCP servers you want to run)

Locating Your Configuration File

The Codex CLI reads its configuration from a config.toml file. Depending on your operating system, you can find or create this file in the following locations:

  • β–ΈWindows: %APPDATA%\Codex\config.toml
  • β–ΈmacOS: ~/Library/Application Support/Codex/config.toml
  • β–ΈLinux: ~/.config/codex/config.toml

Adding Your First MCP Server

Open the config.toml file in your favorite text editor. MCP servers are defined under the [mcpServers] table. Each server needs a unique name, a command to execute, and optional arguments or environment variables.

Here is an example of adding the official Filesystem MCP server, which allows Codex to read and write files in a specific directory:

toml
[mcpServers.filesystem]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "C:/Users/richa/github"]

Breaking Down the Configuration

  1. β–Έ[mcpServers.filesystem]: This declares a new server named filesystem.
  2. β–Έcommand: The executable to run. We use npx to fetch and run the server dynamically.
  3. β–Έargs: The arguments passed to the command. Here, we pass -y to skip the installation prompt, the package name, and the directory we want to expose to Codex.

Adding Environment Variables

Some MCP servers, like the GitHub or Database servers, require authentication tokens or connection strings. You can pass these securely using the env table.

toml
[mcpServers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]

  [mcpServers.github.env]
  GITHUB_PERSONAL_ACCESS_TOKEN = "ghp_your_token_here"

Advanced Configuration: Python Servers

If you are using an MCP server written in Python (like the SQLite server), you can configure it using the uv tool or standard python commands:

toml
[mcpServers.sqlite]
command = "uvx"
args = ["mcp-server-sqlite", "--db-path", "C:/Users/richa/github/my-database.db"]

Testing Your Configuration

Once you've saved your config.toml file, you can verify that the Codex CLI is able to connect to your configured servers by running:

bash
codex mcp list

You should see a list of your configured servers along with their status (Connected or Failed). If a server fails to connect, double-check your paths and environment variables.

Next Steps

Now that you know how to configure servers, check out our guide on the Best MCP Servers for Codex to see what you can build!

Ready to Deploy?

Build your full agent toolstack in the Visual Generator

Combine How to Configure with databases, search APIs, and memory graphs in a single configuration file.

Customize in Generator

Related Guides