# Connect Codex for Yourself

Add your Dtwo gateway to Codex just for yourself.

## 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.

<div class="doc-tabs" data-tabs>

<div class="doc-tablist doc-tablist-cards" role="tablist" aria-label="Sign-in type">
<button type="button" role="tab" class="doc-tab" data-tab="dtwo" aria-selected="true"><img src="/favicon.svg" alt="" width="36" height="36" data-no-lightbox>Dtwo authentication</button>
<button type="button" role="tab" class="doc-tab" data-tab="entra"><img src="/logos/azure.svg" alt="" width="36" height="36" data-no-lightbox>Microsoft Entra ID</button>
<button type="button" role="tab" class="doc-tab" data-tab="okta"><img src="/logos/okta.png" alt="" width="36" height="36" data-no-lightbox>Okta</button>
</div>

<div class="doc-tabpanel" data-panel="dtwo" role="tabpanel">

<p class="doc-step">Step 1: Add the gateway to Codex</p>

If your admin gave you a gateway name and a gateway URL, use them as your `<GatewayName>` and `<GatewayURL>`.

1. Add the gateway to `~/.codex/config.toml`. Create the file if it doesn't exist yet.

   ```toml
   [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 with `https://`.

2. 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.

<p class="doc-step">Step 2: Verify the connection</p>

1. Start a new task in Codex and run `/mcp`. Your gateway is listed with its tools.
2. Ask Codex which tools it has through your gateway. It should list the tools from the MCP servers behind your gateway.

</div>

<div class="doc-tabpanel" data-panel="entra" role="tabpanel">

<p class="doc-step">Step 1: Get Codex's client ID from Microsoft Entra ID</p>

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](/docs/register-codex-entra), then come back here.

<p class="doc-step">Step 2: Add the gateway to Codex</p>

1. Add the gateway to `~/.codex/config.toml`. Create the file if it doesn't exist yet.

   ```toml
   [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 with `https://`.
   - `<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's `33419`. `callback_port` and `callback_url` must match that redirect URI exactly.

2. 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.

<p class="doc-step">Step 3: Verify the connection</p>

1. Start a new task in Codex and run `/mcp`. Your gateway is listed with its tools.
2. Ask Codex which tools it has through your gateway. It should list the tools from the MCP servers behind your gateway.

</div>

<div class="doc-tabpanel" data-panel="okta" role="tabpanel">

<p class="doc-step">Step 1: Get Codex's client ID from Okta</p>

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](/docs/register-codex-okta), then come back here.

<p class="doc-step">Step 2: Add the gateway to Codex</p>

1. Add the gateway to `~/.codex/config.toml`. Create the file if it doesn't exist yet.

   ```toml
   [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 with `https://`.
   - `<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's `33419`. `callback_port` and `callback_url` must match that redirect URI exactly.

2. 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.

<p class="doc-step">Step 3: Verify the connection</p>

1. Start a new task in Codex and run `/mcp`. Your gateway is listed with its tools.
2. Ask Codex which tools it has through your gateway. It should list the tools from the MCP servers behind your gateway.

</div>

</div>

---

Having trouble? Email [support@dtwo.ai](mailto:support@dtwo.ai).