# Connecting Codex

> Connect Codex to ZopNight's MCP server via Streamable HTTP transport to query your cloud infrastructure from within the Codex environment.

Source: https://zop.dev/developer-docs/integrations/mcp-server/codex

---

Connect **Codex** to ZopNight's MCP server to query your cloud infrastructure from within the Codex environment.

**Info**

Make sure you have completed the [prerequisites](https://zop.dev/docs/integrations/mcp-server/overview) — enable MCP for your organisation and create a Personal Access Token.

## Setup

1. Open **Codex**
2. Go to **Settings**
3. Click **MCP Servers**
4. Click **Add Server**
5. Select **Streamable HTTP** (not STDIO)
6. Fill in the fields below
7. Click **Save**

## Configuration

| Field | Value |
|---|---|
| **Name** | `zopnight` |
| **Transport** | Streamable HTTP |
| **URL** | `MCP_SERVER_URL` |

The settings dialog documented by OpenAI asks only for a name, a transport and the URL. If it offers no field for a custom header, use the `config.toml` route below, which is the documented way to supply the token.

### Note

- Replace `MCP_SERVER_URL` with the Server URL shown on your Organisation Settings page, or on the Developer Settings page where you create your token. Copying it from the app means you always get the right host for your environment.
- Replace `MCP_PAT` with your own personal access token (it starts `zn_pat_`). Paste it plainly, with no angle brackets around it.

**Info**

Make sure to select **Streamable HTTP**, not STDIO. The ZopNight MCP server uses standard HTTP transport — it does not support STDIO or WebSocket connections.

## Configure via config.toml

Codex also reads MCP servers from `~/.codex/config.toml`, or a project-scoped `.codex/config.toml`, shared by the CLI, the IDE extension and the desktop app. Unlike most clients, Codex takes the **name of an environment variable** holding your token rather than the token itself:

```toml
[mcp_servers.zopnight]
url = "MCP_SERVER_URL"
bearer_token_env_var = "ZOP_MCP_TOKEN"
```

Export the token in your shell before starting Codex — `export ZOP_MCP_TOKEN=zn_pat_…` — and Codex sends it as `Authorization: Bearer …`. This is the documented way to supply the token: the settings UI exposes only name, transport and URL. Codex also accepts an `http_headers` table for other static headers, and `env_http_headers` to read their values from the environment.

The CLI does the same thing in one line:

```bash
codex mcp add zopnight --url MCP_SERVER_URL --bearer-token-env-var ZOP_MCP_TOKEN
```

A project-scoped `.codex/config.toml` loads only in a project you have marked as trusted, which is a common reason a server appears to be ignored.

## Verify Connection

Once configured, ask Codex:

```text
List my organisations
```

If configured correctly, it will call the `list_organisations` tool and show your organisations.
