Set up MCP
Register an AI Gateway MCP endpoint in Codex CLI and check the first tool call.
This page connects one MCP server to Codex CLI and calls the first tool. If you only use models, you can skip this page. For server authentication, toolsets, and other client setup, see the detailed guides below.
Before you start
Section titled “Before you start”- Finish Get a Gateway Key.
- The server you want to use must show Connected in MCP Catalog. For OAuth or per-user API key servers, connect it to your account first in Connect MCP servers.
- To bundle several servers into one, Create MCP toolsets first.
- Install Codex CLI.
1. Copy the endpoint
Section titled “1. Copy the endpoint”In MCP Catalog, select Client setup in the server or toolset row, then select Copy endpoint.


Select 1 Client setup to open the dialog in the second image. Check the Gateway endpoint, then select 1 Copy endpoint. You will use the copied address for url in the next step.
2. Register it in Codex
Section titled “2. Register it in Codex”Add the content below to ~/.codex/config.toml. Keep the existing settings and merge so that entries with the same name are not duplicated. github-123e4567 is an example name, so you can change it.
[mcp_servers.github-123e4567]url = "<copied Gateway endpoint>"bearer_token_env_var = "AI_GATEWAY_API_KEY"bearer_token_env_var takes the name of the environment variable, not the key value.
3. Call the first tool
Section titled “3. Call the first tool”If you have not set the key yet, run this first in the terminal where you run Codex.
export AI_GATEWAY_API_KEY='<your Gateway Key>'If Codex was running, quit it and start it again. Check the server and tool list with /mcp, then ask Codex to use the tool. When a response comes back, the connection is done.
For server authentication, toolsets, and Claude Code or Cursor setup, see Connect MCP servers, MCP toolsets, and Connect MCP clients. If you get an error, see MCP troubleshooting.