Connect Codex for Yourself

Add your Dtwo gateway to Codex just for yourself.

On this page
  1. Overview
  2. Set up Codex

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

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

Step 2: Verify the connection

  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.

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

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

Step 3: Verify the connection

  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.

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

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

Step 3: Verify the connection

  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.

Having trouble?

Email us and we'll help you get set up.

Email support
Updated
Get in touch

Tell us what you need to govern.

A few lines is plenty — what you're deploying, and what you need control over. We read every one.

↑↓ to navigate ↵ to open