How to Add an MCP Server to Codex (CLI and config.toml)
Add an MCP server to Codex with one command. Sign in to remote servers, edit config.toml by hand, use it in the IDE extension, and fix common errors.
Blog · November 23, 2026

TL;DR: One command adds an MCP server to Codex: codex mcp add <name> --url <url> for a remote server, or codex mcp add <name> -- <command> for a local one. If the server needs a sign-in, run codex mcp login <name>. Codex saves it in ~/.codex/config.toml, and the CLI and IDE extension both use it. Below: the steps, the config file, the IDE extension, and seven fixes.
To add a remote MCP server to Codex, run codex mcp add <name> --url <url>. If the server uses OAuth, Codex starts the sign-in right away. If you skip it, run codex mcp login <name> later. Run codex mcp list to check that the server is there and logged in.
codex mcp add rankvisit --url https://rankvisit.com/mcp
codex mcp login rankvisit
That is the whole setup for most servers. We checked every command on 2026-11-23 with Codex CLI 0.171.0 against the official Codex MCP docs. New to MCP? Read what an MCP server is first.
How to add an MCP server to Codex
A remote server lives on the internet and has a URL. Codex calls this a streamable HTTP server. We use Rankvisit as the example, because it is our own server. Swap in the name and URL of the server you want.
1. Run codex mcp add with –url
Open a terminal and run:
codex mcp add rankvisit --url https://rankvisit.com/mcp
rankvisit is the name you pick. It can use letters, numbers and the signs -, _, :, @, / and ., but no spaces. The URL must be the server’s MCP endpoint, not its home page. Codex confirms the add and checks for a sign-in:
Added global MCP server 'rankvisit'.
Detected OAuth support. Starting OAuth flow…
Authorize `rankvisit` by opening this URL in your browser:
https://rankvisit.com/api/auth/oauth2/authorize?response_type=code&client_id=...
“Global” means the server is saved in your home folder, so it works in every project.
2. Sign in with codex mcp login
If your browser opens, log in and allow access. Codex catches the answer and saves the login. If the browser does not open, Codex says so (“Browser launch failed; please copy the URL above manually”). Copy the URL into your browser yourself.
Closed the window or want to sign in later? Run:
codex mcp login rankvisit
On a server over SSH, add --no-browser. Codex then prints the URL and lets you paste the callback URL back in.
3. Check it with codex mcp list
Run codex mcp list. Here is the real output for our server before signing in:
Name Url Bearer Token Env Var Status Auth
rankvisit https://rankvisit.com/mcp - enabled Not logged in
After you sign in, the Auth column no longer says Not logged in. Add --json if you want the list as JSON, for example in a script.
4. Start Codex and ask
Start codex and type /mcp to see your active servers. Then ask a question that needs the server, and Codex calls its tools.
Rankvisit also has a shortcut for agents. Tell Codex “Read https://rankvisit.com/INSTALL.md and connect Rankvisit.” and it runs the steps for you. Both ways are on the Rankvisit docs page.
Add a local (stdio) MCP server
A local server runs as a program on your computer. You add it with two dashes. Codex’s own options go before --, and the command that starts the server goes after it. This example is from OpenAI’s docs:
codex mcp add context7 -- npx -y @upstash/context7-mcp
If the server needs a key or setting, add --env KEY=value before the dashes. You can repeat it:
codex mcp add context7 --env MY_KEY=abc -- npx -y @upstash/context7-mcp
--env only works with local servers. For a remote server that needs a token, use --bearer-token-env-var with the name of an environment variable that holds the token. Codex then reads the token from that variable and does not save it in the file.
Codex MCP config: edit config.toml by hand
codex mcp add writes the config for you. Still, it helps to know the file, for example to copy your setup to a new laptop. Codex keeps MCP servers in ~/.codex/config.toml. Each server is a table named [mcp_servers.<name>].
Here is the real file after the two commands above:
[mcp_servers.rankvisit]
url = "https://rankvisit.com/mcp"
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
[mcp_servers.context7.env]
MY_KEY = "abc"
A remote server needs url. A local server needs command, and most also use args. These optional keys come up most often. All of them are in OpenAI’s config reference:
| Key | For | What it does |
|---|---|---|
env |
local | Environment variables for the server |
cwd |
local | Folder the server starts in |
bearer_token_env_var |
remote | Env var that holds a bearer token |
http_headers |
remote | Extra headers to send |
startup_timeout_sec |
both | How long Codex waits for the server to start (default 10) |
tool_timeout_sec |
both | How long one tool call may take (default 60) |
enabled |
both | Set to false to turn a server off without deleting it |
enabled_tools, disabled_tools |
both | Allow or block single tools by name |
A project can also have its own .codex/config.toml in the repo. The docs say Codex loads it only for trusted projects.
To change a single value for one run, you can pass it with -c, for example codex -c mcp_servers.rankvisit.enabled=false. The value is parsed as TOML.
Use MCP servers in the Codex IDE extension
The IDE extension uses the same config. OpenAI’s docs say the Codex CLI, the IDE extension and the ChatGPT desktop app share it. So a server you add in the terminal shows up in your editor too.
To add or check a server in the extension:
- Open the gear menu in the Codex panel and select MCP servers.
- Select Add server, then pick STDIO or Streamable HTTP.
- Enter a name and the command or URL, and save.
- Select Restart extension so it loads the new server.
The list shows which servers are on and which still need a sign-in. Select Authenticate to log in to a server from there.
List, check and remove servers
Four commands cover almost everything:
codex mcp list # all servers, status and login
codex mcp get rankvisit # details for one server
codex mcp logout rankvisit # delete the saved login
codex mcp remove rankvisit # delete the server
Here is the real output of codex mcp get for our server:
rankvisit
enabled: true
transport: streamable_http
url: https://rankvisit.com/mcp
bearer_token_env_var: -
http_headers: -
env_http_headers: -
http_headers_helper: -
remove: codex mcp remove rankvisit
codex mcp remove deletes the table from config.toml and confirms with Removed global MCP server 'rankvisit'. If you only want to pause a server, set enabled = false instead.
Example: ask Codex about your Search Console data
Once a server is connected, you just ask. With a Search Console server like Rankvisit, you can check your clicks and queries while you work on the site’s code. Two prompts that work well:
- “For example.com in Google Search Console, show the top 20 queries from the last 28 days with clicks, impressions and position.”
- “Compare clicks for example.com/blog in the last 28 days with the 28 days before. Which 5 pages lost the most?”
Keep the question narrow: name the site, the time period, and a page, a folder or a number of queries. The assistant then loads fewer rows and answers faster.
The Google Search Console MCP page shows what Rankvisit can answer. For more prompts and a real answer, see how to connect Google Search Console to Claude. The questions work the same way in Codex.
When an MCP server does not work in Codex
Run codex mcp list first. The Status and Auth columns show most problems. Here are the common causes, with real errors from our tests:
- You left out
--url. Then Codex saves the URL as a program to run. The list shows it underCommand, and Auth saysUnsupported. Runcodex mcp remove <name>and add it again with--url. - You have not signed in yet. Auth says
Not logged in. Runcodex mcp login <name>. If no browser opens, copy the URL Codex prints, or use--no-browser. - The name has a space. Codex stops with
Error: invalid server name 'my server'. Use a dash or an underscore instead. - You used
--envwith a remote server. Codex saysError: command is required, because--envis only for local servers. Use--bearer-token-env-varfor a remote token. - The TOML has a typo. A value without quotes breaks the whole file. Codex stops with
string values must be quotedand shows the line and column. Put quotes around the URL and run the command again. - The server is slow to start. Codex waits 10 seconds by default. Raise
startup_timeout_secfor that server, ortool_timeout_secif single tool calls time out. - The extension does not show your change. Select Restart extension after you edit the config. In the terminal, quit Codex and start a new session.
If a remote server keeps failing, check the server’s docs for the exact MCP endpoint. It often ends in /mcp, and the home page URL will not work.
Note: Codex as an MCP server
Some guides cover the other direction: running Codex itself as an MCP server, so a different app can use it. That is a different setup. This page is only about Codex using other servers. For the other direction, check the Codex docs and the Codex repo on GitHub.
Next step
Pick one server you would use every day and add it with codex mcp add. If that is your Search Console data, the command is at the top of this page, and the first 10 questions are free. Want the same server in other tools? See how to add it to Claude Code or to ChatGPT.
FAQ
How do I connect Codex to an MCP server?
For a remote server, run codex mcp add, a name, and --url with the server's MCP endpoint, for example codex mcp add rankvisit --url https://rankvisit.com/mcp. For a local server, put the start command after two dashes, for example codex mcp add context7 -- npx -y @upstash/context7-mcp. Then run codex mcp list to check it.
Where is the Codex MCP config file?
Codex saves MCP servers in ~/.codex/config.toml, in a table called [mcp_servers.<name>]. A project can also have its own .codex/config.toml, but Codex only loads it when you trust the project.
Does the Codex IDE extension use the same MCP servers as the CLI?
Yes. OpenAI's docs say the Codex CLI, the IDE extension and the ChatGPT desktop app share the same config. A server you add with codex mcp add shows up in the extension too. Restart the extension after a change.
How do I remove an MCP server from Codex?
Run codex mcp remove followed by the server name, for example codex mcp remove rankvisit. Codex deletes the server's table from config.toml and prints a short confirmation. You can also set enabled = false in config.toml to turn a server off without deleting it.
Can Codex use remote MCP servers with OAuth?
Yes. When you add a remote server with --url, Codex checks if it supports OAuth and starts the sign-in right away. If you skip it, run codex mcp login with the server name later. Add --no-browser on a machine without a browser.