# How to add an MCP server to Codex

Level 3: Connect AI to your tools · 6 min · Updated 19 November 2026 · Path: Connect MCP servers to your assistant

By the end you'll add local and remote MCP servers to Codex once and use them in the CLI, the IDE extension and the ChatGPT desktop app.

You use Codex in the terminal in the morning and in your editor in the afternoon. The nice surprise: as of 19 November 2026, OpenAI's docs say the ChatGPT desktop app, the Codex CLI and the IDE extension share one MCP configuration. Add an [MCP](https://ai-powered.com/academy/glossary/mcp) server once and it's there in all three.

*Diagram: Adding a server, step by step.* Pick a server you trust, add it to your app (a URL or a command), sign in or restart, then try a small task and approve the first tool call.

## Add a server from the terminal

A local server, with everything after `--` being the command that starts it:

```shell
codex mcp add context7 -- npx -y @upstash/context7-mcp
```

Keys go in with `--env VAR=VALUE`, once per key. A remote server that speaks Streamable HTTP:

```shell
codex mcp add example --url https://mcp.example.com
```

If the server uses OAuth, sign in with `codex mcp login <server-name>`. On a machine without a browser, add `--no-browser`, open the printed URL elsewhere and paste the full redirect URL back into the terminal.

## Or edit config.toml

Codex keeps servers in `~/.codex/config.toml`, one `[mcp_servers.<name>]` table each. A project can have its own `.codex/config.toml`, but only for projects you've marked as trusted.

```toml
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]

[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"
```

Note `bearer_token_env_var`: the token itself stays in an environment variable, not in the file.

## In the IDE extension

Open the gear menu, select **MCP servers**, then **Add server**. Enter a name, choose **STDIO** or **Streamable HTTP**, give the command or URL, save, and select **Restart extension**.

## Check that it worked

Run `codex mcp list` in a shell, or type `/mcp` in the Codex interface (or in the ChatGPT desktop app's composer) to see your servers.

**Try it**

Add Context7 with the first command, start `codex` in a project and ask it to look up the current docs for a library the project uses. Watch for the [tool call](https://ai-powered.com/academy/glossary/tool-call) before it answers.

## Servers developers use

MCP servers for developer tools from the directory:

- [GitHub](https://ai-powered.com/mcp/github-2): Official MCP server connecting AI assistants to GitHub repos, issues and workflows
- [fastmcp](https://ai-powered.com/mcp/fastmcp): Python framework for building MCP servers, clients and interactive apps
- [Codebase Memory](https://ai-powered.com/mcp/codebase-memory): Local MCP server that builds a code knowledge graph for AI coding agents
- [XERJ](https://ai-powered.com/mcp/xerj): Local search engine for AI agents with cited answers over your code and docs
- [REA](https://ai-powered.com/mcp/rea): CLI and MCP server that lets coding agents reverse engineer apps and binaries

## Key takeaways

- `codex mcp add <name> -- <command>` for local servers; `--url` for remote ones.
- One config in `~/.codex/config.toml`, shared by the CLI, the IDE extension and the ChatGPT desktop app.
- Keep tokens in environment variables with `bearer_token_env_var`.

## What to try next

- Check a server before you add it: [Is this MCP server safe?](https://ai-powered.com/academy/connect-mcp-servers/is-this-mcp-server-safe)
- Give Codex your project's rules too: [context engineering](https://ai-powered.com/academy/code-with-ai-agents/context-engineering).

## Sources

Official documentation, checked on 19 November 2026:

- [Model Context Protocol in Codex (OpenAI docs)](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)

Next lesson: [How to add an MCP server to Gemini CLI](https://ai-powered.com/academy/connect-mcp-servers/gemini-cli)
