Connect Codex for Yourself
Add your Dtwo gateway to Codex just for yourself.
On this page
Overview
This guide adds your Dtwo gateway to Codex just for you. The Codex app, CLI, and IDE extension share the same MCP configuration, so adding the gateway once covers all three on that computer.
Set up Codex
Select how your gateway signs people in.
Step 1: Add the gateway to Codex
If your admin gave you a gateway name and a gateway URL, use them as your <GatewayName> and <GatewayURL>.
-
Add the gateway to
~/.codex/config.toml. Create the file if it doesn’t exist yet.[mcp_servers.<GatewayName>] url = "<GatewayURL>"Replace the placeholders:
<GatewayName>: the server name. If your organization approves only the gateway, use the exact name your admin gave you. Codex blocks a server with any other name.<GatewayURL>: your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start withhttps://.
-
Sign in with your Dtwo account. In the Codex app, open Settings → MCP servers and select Authenticate next to your gateway. From a terminal, run
codex mcp login <GatewayName>instead.
Step 2: Verify the connection
- Start a new task in Codex and run
/mcp. Your gateway is listed with its tools. - Ask Codex which tools it has through your gateway. It should list the tools from the MCP servers behind your gateway.
Step 1: Get Codex's client ID from Microsoft Entra ID
If your admin gave you a client ID, a gateway name, a gateway URL, and a callback port, use them as your <ClientId>, <GatewayName>, <GatewayURL>, and <CallbackPort> and skip to Step 2.
If you’ve already registered Codex as an app in Microsoft Entra ID, go to App registrations, open the Codex app, and copy the Application (client) ID from its Overview page. This is your <ClientId>.
If you haven’t registered Codex in Microsoft Entra ID yet, follow Register Codex in Microsoft Entra ID, then come back here.
Step 2: Add the gateway to Codex
-
Add the gateway to
~/.codex/config.toml. Create the file if it doesn’t exist yet.[mcp_servers.<GatewayName>] url = "<GatewayURL>" [mcp_servers.<GatewayName>.oauth] client_id = "<ClientId>" callback_port = <CallbackPort> callback_url = "http://127.0.0.1:<CallbackPort>/callback"Replace the placeholders:
<GatewayName>: the server name. If your organization approves only the gateway, use the exact name your admin gave you. Codex blocks a server with any other name.<GatewayURL>: your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start withhttps://.<ClientId>: the client ID you copied when you registered the client in your identity provider.<CallbackPort>: the port in the redirect URI registered for Codex in your identity provider. If it was registered following these docs, it’s33419.callback_portandcallback_urlmust match that redirect URI exactly.
-
Sign in. In the Codex app, open Settings → MCP servers and select Authenticate next to your gateway. From a terminal, run
codex mcp login <GatewayName>instead.
Step 3: Verify the connection
- Start a new task in Codex and run
/mcp. Your gateway is listed with its tools. - Ask Codex which tools it has through your gateway. It should list the tools from the MCP servers behind your gateway.
Step 1: Get Codex's client ID from Okta
If your admin gave you a client ID, a gateway name, a gateway URL, and a callback port, use them as your <ClientId>, <GatewayName>, <GatewayURL>, and <CallbackPort> and skip to Step 2.
If you’ve already registered Codex as an app in Okta, go to Applications and Resources → Applications, open the Codex app integration, and copy the Client ID from its General tab. This is your <ClientId>.
If you haven’t registered Codex in Okta yet, follow Register Codex in Okta, then come back here.
Step 2: Add the gateway to Codex
-
Add the gateway to
~/.codex/config.toml. Create the file if it doesn’t exist yet.[mcp_servers.<GatewayName>] url = "<GatewayURL>" [mcp_servers.<GatewayName>.oauth] client_id = "<ClientId>" callback_port = <CallbackPort> callback_url = "http://127.0.0.1:<CallbackPort>/callback"Replace the placeholders:
<GatewayName>: the server name. If your organization approves only the gateway, use the exact name your admin gave you. Codex blocks a server with any other name.<GatewayURL>: your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start withhttps://.<ClientId>: the client ID you copied when you registered the client in your identity provider.<CallbackPort>: the port in the redirect URI registered for Codex in your identity provider. If it was registered following these docs, it’s33419.callback_portandcallback_urlmust match that redirect URI exactly.
-
Sign in. In the Codex app, open Settings → MCP servers and select Authenticate next to your gateway. From a terminal, run
codex mcp login <GatewayName>instead.
Step 3: Verify the connection
- Start a new task in Codex and run
/mcp. Your gateway is listed with its tools. - Ask Codex which tools it has through your gateway. It should list the tools from the MCP servers behind your gateway.