> ## Documentation Index
> Fetch the complete documentation index at: https://api.globalwebindex.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex CLI

## Overview

The GWI MCP server can be integrated with Codex CLI so agents can access GWI consumer insights in the CLI, the IDE extension, and the Codex surface in the ChatGPT desktop app. Those clients share `~/.codex/config.toml`.

Use this endpoint:

```text theme={null}
https://api.globalwebindex.com/v2beta/spark-api/mcp
```

Reference: [Codex MCP documentation](https://learn.chatgpt.com/docs/extend/mcp)

## Prerequisites

Before continuing with the integration, install Codex:

* [Install the Codex CLI](https://developers.openai.com/codex/cli)

For a Spark API token, export it as `SPARK_API_TOKEN` in the shell that starts Codex.

## Authentication

Choose one of the following methods:

* [**OAuth 2.0 (recommended).**](#oauth-20) Sign in with your GWI account. Codex stores the session and refreshes it.
* [**Spark API token.**](#spark-api-token) Use an environment variable for developer or automated environments.

### OAuth 2.0

1. Add the GWI MCP server:

   ```bash theme={null}
   codex mcp add gwi_spark_v2beta \
     --url https://api.globalwebindex.com/v2beta/spark-api/mcp
   ```

   ![Add the v2beta GWI Spark MCP server and start OAuth in Codex](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/oauth-start.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=b77941ed338626b8b43b5764ef0ad8ee)

   > Note: this writes the server to `~/.codex/config.toml`. You can edit that file directly. A trusted project can use `.codex/config.toml` instead.
   >
   > Codex detects OAuth on this URL and starts the sign-in flow. To sign in later, run `codex mcp login gwi_spark_v2beta`.

2. You'll be redirected to the GWI sign-in page. Use your GWI credentials to sign in. **If you don't have a GWI login, click Sign up to create one**

   ![GWI sign-in page for Codex OAuth](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/sign-in.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=01c13439399fd0926cf59c30667c9340)

3. Review the requested permissions and click **Allow**. Then return to the terminal.

   ![Allow Codex to access a GWI account](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/allow-access.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=3bc8fa37b820221bd30e1df58bb7afee)

   After you allow access, Codex confirms that you are signed in.

   ![Codex OAuth login completed successfully](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/oauth-success.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=a7210d8793a0f9110e9de5bb8bf5881e)

4. Start Codex:

   ```bash theme={null}
   codex
   ```

5. Confirm the server is connected:

   ```bash theme={null}
   > /mcp
   ```

   `gwi_spark_v2beta` should be connected.

   ![GWI Spark v2beta connected in Codex](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/connected.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=25516256198afbf176d066bdb977dcc7)

   From a shell, `codex mcp list` shows the server URL `https://api.globalwebindex.com/v2beta/spark-api/mcp` with auth `OAuth`.

   ![The OAuth-authenticated v2beta server in the Codex server list](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/oauth-server-list.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=b9c6b215b3e61cacd2fad146b62d707e)

6. Ask Codex to use GWI:

   ```text theme={null}
   Which GWI datasets can I query?
   ```

   Codex returns the GWI datasets available to your account.

The ChatGPT desktop app and the IDE extension read this same config. In the desktop app, open **Settings → MCP servers**. If the server requires sign-in, select **Authenticate**.

### Spark API token

Use this method when you have a Spark API token. Codex reads it from `SPARK_API_TOKEN` and sends `Authorization: Bearer`. The config file stores the variable name only.

1. Export your token before you start Codex. Keep the real value in the environment.

   ```bash theme={null}
   export SPARK_API_TOKEN="<your Spark API token>"
   ```

2. Add the GWI MCP server:

   ```bash theme={null}
   codex mcp add gwi_spark_v2beta \
     --url https://api.globalwebindex.com/v2beta/spark-api/mcp \
     --bearer-token-env-var SPARK_API_TOKEN
   ```

   ![Add the v2beta GWI Spark MCP server with a Spark API token](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/token-add-server.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=2feb600a7fb704598f8a8edb0402e7b8)

   > Note: this writes the server to `~/.codex/config.toml`. You can edit that file directly. A trusted project can use `.codex/config.toml` instead.
   >
   > The saved entry looks like this:

   ```toml theme={null}
   [mcp_servers.gwi_spark_v2beta]
   url = "https://api.globalwebindex.com/v2beta/spark-api/mcp"
   bearer_token_env_var = "SPARK_API_TOKEN"
   ```

3. Start Codex from the same environment:

   ```bash theme={null}
   codex
   ```

4. Confirm the server is connected:

   ```bash theme={null}
   > /mcp
   ```

   `gwi_spark_v2beta` should be connected. From a shell, `codex mcp list` shows bearer token env var `SPARK_API_TOKEN`.

   ![The token-authenticated v2beta server in the Codex server list](https://mintcdn.com/gwi-c45e8f9c/Xa6BLch5pfR9v8pV/assets/images/codex/v2beta/token-server-list.png?fit=max\&auto=format\&n=Xa6BLch5pfR9v8pV\&q=85\&s=6cb9048b101947c87644f03a06813aaf)

5. Ask Codex to use GWI:

   ```text theme={null}
   Which GWI datasets can I query?
   ```

   Codex returns the GWI datasets available to your account.

## Troubleshooting

* **Server missing or disabled:** Run `codex mcp list`. The URL should be `https://api.globalwebindex.com/v2beta/spark-api/mcp`.
* **OAuth not signed in:** Run `codex mcp login gwi_spark_v2beta` and allow access on the GWI sign-in page.
* **401 or invalid token:** Confirm `SPARK_API_TOKEN` is set in the shell that started Codex, and that the token has not expired or been revoked.
