Add a local MCP server to Codex

mcp & extensions

// what it does

codex mcp add registers a stdio MCP server. Everything after the -- separator is the command Codex launches to talk to the server; pass server environment variables with --env before the --. The command writes a [mcp_servers.NAME] block into ~/.codex/config.toml.

// shell

$ codex mcp add context7 -- npx -y @upstash/context7-mcp
$ codex mcp add myserver --env API_TOKEN=abc123 -- npx my-mcp-server

// gotcha

The -- separator matters: flags after it belong to the server command, flags before it (like --env) belong to codex. Omit it and codex tries to parse the server's own arguments as its own.

// resources