AI Code With · A Practical Codex Tutorial
The first time you open Codex's MCP configuration, a lot of people feel the same thing: I just wanted Codex to use one more tool, so why is there suddenly so much going on?
MCP Server, STDIO, Streamable HTTP, OAuth, config.toml, tool permissions, environment variables... If you try to understand all of it up front, you will most likely end up with a messier setup the more you configure.
I recommend a different approach: don't aim for a "complete" configuration. Get a minimal working loop running first.
For the first pass, do just three things: Codex can see one MCP Server; Codex can successfully call one read-only tool; and you know how to turn it off or back it out.
Once that chain works, everything that comes later, such as OAuth, write permissions, multiple Servers, and complex authentication, is really just added complexity on top of this foundation.
First, a plain-language explanation: what is MCP actually for?
MCP stands for Model Context Protocol. The name sounds technical, but if you're just using Codex, you can think of it this way: MCP is a way for Codex to connect to external tools.
Codex itself is good at reading code, editing files, running commands, and analyzing projects, but real-world work goes well beyond that. You might want Codex to look up the latest developer docs, read an internal knowledge base, query a database, drive a browser, access GitHub or a project management system, or even call your company's own APIs.
That's where an MCP Server comes in: it exposes those capabilities to Codex.
Codex
↓
MCP
↓
External tools / data / services
An important boundary: MCP determines which tools Codex can use, not which large model Codex uses.
Step 1: Tell STDIO and Streamable HTTP apart
Codex MCP currently supports two main kinds of Server: STDIO and Streamable HTTP. You don't need to dig into protocol details at the start. Just remember it like this: STDIO = Codex launches a program on your machine; Streamable HTTP = Codex connects to a remote address.
STDIO: for MCP Servers that run locally
For example, a Server that runs as a Node.js package:
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
The meaning is simple: when Codex needs this tool, it starts the local process npx -y @upstash/context7-mcp.
Streamable HTTP: for remote services
For example:
[mcp_servers.example]
url = "https://example.com/mcp"
Here Codex doesn't start a local program. It accesses this URL instead. As a rough rule of thumb, local documentation tools are usually STDIO, while internal company services or hosted SaaS MCP endpoints are usually Streamable HTTP.
Neither approach is more advanced than the other. What matters is where your MCP Server actually runs.
Step 2: Don't hand-edit too much config the first time. Run a minimal example
If this is your first attempt at MCP, I actually suggest adding the Server through the CLI. Using Context7 as an example:
codex mcp add context7 -- npx -y @upstash/context7-mcp
Once that finishes, your first move shouldn't be putting Codex to work right away. Check this first:
codex mcp list
If you're already inside the Codex TUI, you can also enter:
/mcp
to see the currently active MCP Servers.
Don't celebrate yet: showing up in the list doesn't mean it actually works
Say you run codex mcp list and see context7, so you assume it's set up. All you've really proven is one thing: Codex has read the configuration.
You haven't yet proven that the Server process can actually start, that it really exposes tools, that Codex has permission to call them, or that a tool call returns a result correctly.
Appearing in the list only means the configuration was loaded. It doesn't mean the Server is working.
Step 3: Actually call a tool once
For the first verification, deliberately pick a read-only tool with no side effects, such as searching developer docs, looking up a piece of public information, reading a page, or fetching some read-only state.
Don't have MCP delete files, modify a database, send messages, file tickets, or touch production systems the first time it connects.
The reason is simple: if you let a Server read, write, and delete from the very first step, then when something goes wrong you face three questions at once: is it connected, does it have permission, and did it actually change data? Troubleshooting gets much harder.
Prove you can read safely first, then consider allowing writes.
Where does the MCP configuration actually live?
By default, Codex reads MCP configuration from the following location:
~/.codex/config.toml
Trusted projects can also use project-level configuration:
your-project/.codex/config.toml
What is global configuration good for?
Tools you use every day, such as a documentation lookup MCP, a browser MCP, or a general knowledge base MCP, don't need to be configured again in every project. Putting them in ~/.codex/config.toml is the natural choice.
What is project-level configuration good for?
For example, say a company CRM project has an MCP that reads that project's test data. It only makes sense for this project, so it can go in project/.codex/config.toml. That way, when you switch to another project, you don't carry along a pile of unrelated tools.
What should you watch for when the CLI, desktop app, and IDE share MCP configuration?
The Codex CLI, desktop app, and IDE extension on the same machine may share one set of MCP configuration. That means if you add a Server in the CLI, the desktop app may see it right after a restart.
This also explains why you sometimes change the configuration in the terminal and then see the desktop app change after a restart.
After changing the configuration, restart the relevant client and verify again. Don't rely on a feeling that it should have picked it up.
Step 4: For remote MCP, handle HTTP and authentication next
If your Server isn't on your machine but at a remote URL, the configuration will look more like this:
[mcp_servers.example]
url = "https://mcp.example.com"
Remote MCP can also involve OAuth, Bearer Tokens, HTTP headers, tool approval, and timeouts. But don't cram everything in on the first pass. Confirm the URL first, then confirm the server is reachable, then handle authentication, and handle tool permissions last.
How do you handle OAuth?
If the MCP server supports OAuth, you can run:
codex mcp login <server-name>
to start the login flow. That's far more reliable than copying an Access Token yourself and stuffing it into a config file.
In particular, don't write a real Access Token directly into a config file and commit it to Git. A safer approach is to have the config reference an environment variable. Conceptually, like this:
[mcp_servers.example]
url = "https://mcp.example.com"
bearer_token_env_var = "MY_MCP_TOKEN"
This way the config file only knows where to look for the token, rather than storing the token itself.
Step 5: Don't open up all permissions
Once MCP is in long-term use, permissions matter more than whether it can connect, because the risk varies enormously between MCP tools.
For example, "search internal docs" and "modify the production database" are clearly not the same risk level. For your first setup, I'd recommend relatively loose rules for reads, confirmation for writes, and strict approval for deletes or other high-risk operations.
A real-world example: why a browser MCP shouldn't be fully allowed from the start
Say you hook up a browser MCP to Codex, and the original goal is just to look up a few web pages. But that server may also offer tools for opening pages, reading pages, filling in forms, clicking buttons, uploading files, and submitting content.
"Open a page" and "submit a form" are clearly not the same risk level. If you set every tool to auto-approve, a single misjudgment by Codex could turn "check what fields are on the release page" into "submit the content while you're at it."
What you actually need to judge for MCP permissions isn't "do I trust Codex," but "if this tool fails, what's the worst that can happen?"
"MCP works" and "the model works" are two separate systems
Many people, as soon as they configure MCP, mix OpenAI API, Claude API, Kimi, Provider, API Key, and MCP all together. When something breaks, they have no idea which layer is at fault.
A clearer structure looks like this:
Codex
/ \
/ \
MCP tool layer Model Provider layer
↓ ↓
External tools/data Model API
MCP answers "which external tools can Codex call?" The Provider answers "where do Codex's model requests go?"
So where does AI Code With fit in?
Configuring MCP doesn't require you to use AI Code With. If you're just doing Codex → Context7 MCP → look up docs, that has nothing to do with AI Code With.
But there are two scenarios where it becomes relevant.
Scenario 1: You already use AI Code With as Codex's model Provider
In this case, the MCP config still handles tools, while AI Code With handles the model API entry point for Codex. The two systems can coexist, but don't treat them as one thing.
For example, if Context7 can't connect, check MCP first. If Codex returns a 401 and the error URL points to AI Code With, check the Provider, Key, and Base URL. Separating the two layers makes debugging much clearer.
Scenario 2: Your MCP server itself needs to call an LLM
Say you wrote your own MCP server that takes a long document, calls a model to classify it, and returns the result to Codex. Now the MCP server has its own model API dependency internally.
Codex
↓
MCP Server
↓
External model API
If the server needs to use several different models, you can use AI Code With as one unified model entry point, rather than maintaining a separate set of Provider accounts and Keys for each server.
But this still doesn't mean installing MCP requires installing AI Code With. It means that when the model layer is already complicated, you solve the model layer's problems then.
Step 6: Useful MCP debugging works layer by layer
1. The server isn't in the list at all
Run this first:
codex mcp list
If the server doesn't show up at all, first check whether the config is written correctly, whether you edited the wrong config.toml, whether the project-level config is in a trusted project, whether there's a syntax problem in the config, and whether the client needs a restart.
2. The STDIO server is in the list, but fails to start
Suppose the config is:
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
The most practical approach isn't to keep guessing at Codex. Run this directly in a regular terminal first:
npx -y @upstash/context7-mcp
If that command won't run on its own, whether it's command not found, a failed package install, a broken Node environment, or a network download failure, then Codex can't start it either.
3. The HTTP server loads, but access fails
Check the URL, network, proxy, DNS, and service status first. Confirm the server itself is reachable before you jump to swapping out OAuth.
4. The server connects, but OAuth throws an error
Then check whether you ran codex mcp login, plus the Client ID, Callback URL, authorization server config, and OAuth scope. If this is your first time configuring this, you don't need to understand every term right away. Working through the actual error message is enough.
5. The server is fine, but tools can't be called
Check whether the server actually provides that tool, whether the tool is disabled, the current approval policy, the required environment variables, and the tool's own external dependencies.
6. The MCP tool runs, but the model returns an error
Then stop fiddling with MCP and start checking the Model, Provider, API Key, Base URL, and your quota or API status.
Step 7: On your first setup, test a rollback the same day
Many tutorials teach you how to install, but few teach you how to undo. Once it's in your development environment, being able to back it out matters as much as being able to install it.
Step 1: Record the original state
codex mcp list
Write down the current server list, or even take a screenshot. This is your baseline.
Step 2: Add just one test server
codex mcp add context7 -- npx -y @upstash/context7-mcp
Don't install three more while you're at it.
Step 3: Confirm it shows up
codex mcp list
Step 4: Call a read-only tool
This only proves that the Codex → MCP → Tool path works.
Step 5: If OAuth is involved, verify login separately
codex mcp login <server-name>
Step 6: Then test disabling or removing
If your current config supports enabled, you can start with:
[mcp_servers.example]
url = "https://example.com/mcp"
enabled = false
Disable a server, then run codex mcp list again to check whether your environment is back to the expected state. If you need to remove a server entirely, run codex mcp --help first and confirm which removal command your current version provides, rather than copying an outdated tutorial from a few months ago.
Why do I put so much emphasis on rollback?
Here's a realistic scenario. Today you add Browser MCP to test browser capabilities. A couple of days later you add Docs MCP, Git MCP, and Database MCP. Then Codex suddenly starts failing at launch with MCP startup interrupted.
If you've never tested how to stop a single server, the fix is likely to be deleting the entire configuration in one go.
But if you knew from the start that Server A works, Server B is the new one, and things recover once B is turned off, you can isolate the problem in two minutes.
That's where the minimal loop really pays off.
A complete first-time setup flow should look like this
Confirm Codex runs normally
↓
Pick a simple STDIO server
↓
codex mcp add
↓
codex mcp list
↓
/mcp
↓
Call a read-only tool
↓
Check permissions
↓
Disable / roll back
↓
Check list again
Once that works, gradually add remote HTTP, Bearer Token, OAuth, write-capable tools, project-level MCP, and multiple MCP Servers, not the other way around.
The 7 most common beginner mistakes
| Symptom | What to check first |
| Server not in the list | config.toml, config scope, syntax |
| Server is in the list but fails to start | Whether the STDIO command itself can run |
| Can't connect to HTTP MCP | URL, network, service status |
| OAuth fails | Login flow, Client / Callback |
| Tools appear but can't execute | Tool permissions, environment variables, approvals |
| Codex model requests return 401 | Provider / Key / Base URL; don't blame MCP first |
| Environment gets messy after adding MCP | Turn off the new server, return to baseline, and debug one at a time |
When does it make sense to make your MCP setup more complex?
If all you want right now is for Codex to look up a document, a simple connection is enough. There's no need to jump straight to OAuth, 10 servers, automatic write permissions, multi-environment configs, complex headers, and remote MCP just to look "professional."
The right time to add complexity is when a real need shows up:
• Need company SaaS data? Then add OAuth.
• An MCP only fits one project? Then use the project-level .codex/config.toml.
• A server has risky write operations? Then refine tool approvals.
• The MCP Server itself needs to call multiple models? Then consider separate model Provider management.
• Multiple clients need the same MCP? Then use a shared configuration mechanism instead of maintaining duplicates.
Complexity should be pushed in by requirements, not added because "it's officially supported, so I'll configure everything."
Finally: what you really need to learn about configuring Codex MCP is layering
The most common mistake the first time you use MCP isn't a TOML typo. It's treating everything as one problem. You can actually break it into seven layers:
1. Has Codex loaded the MCP Server?
2. Can the MCP Server start or connect?
3. Did authentication pass?
4. Are the tools exposed?
5. Does Codex have permission to call them?
6. Is the tool's output correct?
7. If a model API is also involved, is the Provider working?
Check layer by layer and you won't get stuck in that state of "Is MCP broken, or Codex, or OAuth, or the API Key?"
The goals worth hitting the first time are still just three: visible, callable, and reversible.
If you're also configuring models for Codex
If your next step isn't adding MCP tools but getting Codex to use different models, handle that separately. AI Code With provides a standalone Codex setup and a unified model API entry point. That belongs to the Provider / model layer, not the MCP layer.
MCP
→ manages tools
AI Code With / other Providers
→ manage the model API
That way, whether a tool call fails or the model returns 401, you'll know which side to check first.
If you were already planning to connect Codex through AI Code With, start with the corresponding Codex configuration docs, then come back to set up MCP. There's no need to put both into the same configuration.
Related reading
• Codex MCP Server shows in the list but doesn't work: how to troubleshoot
• The complete guide to Codex config.toml
• How to set Codex permissions and approvals
• How to switch Codex Providers
• Complete setup for connecting Codex to AI Code With
• Troubleshooting Codex 401 Unauthorized
References
OpenAI Codex MCP: https://developers.openai.com/codex/mcp
AI Code With Codex CLI docs: https://docs.aicodewith.ai/zh/docs/codex-cli
AI Code With website: https://aicodewith.ai/zh



