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

# Connect OpenAI Codex to AiLunaPro (MCP)

> Connect the OpenAI Codex CLI and IDE extension to the AiLunaPro MCP server with codex mcp add or config.toml, using a bearer token from an environment variable.

Codex reads your MCP key from an environment variable and sends it as a bearer token. The key never appears in `config.toml`.

## Prerequisites

* MCP access for your organisation and the **owner** role.
* An MCP key from **Settings → Organization → AI client access (MCP) → Create key**.
* Codex CLI installed and signed in. Check:

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

## Set up

**1. Set the AILUNAPRO\_MCP\_KEY variable**

> [tab] Windows (PowerShell)
>
> For every new terminal (recommended):
>
> ```powershell theme={null}
> $key = Read-Host -Prompt 'Paste your AiLunaPro MCP key'
> [Environment]::SetEnvironmentVariable('AILUNAPRO_MCP_KEY', $key, 'User')
> Remove-Variable key
> ```
>
> Then open a **new** PowerShell window before the next step.

> [tab] macOS / Linux
>
> Add to `~/.zshrc` or `~/.bashrc`, then open a new terminal:
>
> ```bash theme={null}
> export AILUNAPRO_MCP_KEY="alp_mcp_YOUR_KEY"
> ```

**2. Add the server**

```bash theme={null}
codex mcp add ailunapro --url https://api.ailunapro.com/mcp --bearer-token-env-var AILUNAPRO_MCP_KEY
```

This writes the following to `~/.codex/config.toml` (Windows: `%USERPROFILE%\.codex\config.toml`). You can also add it by hand:

```toml ~/.codex/config.toml theme={null}
[mcp_servers.ailunapro]
url = "https://api.ailunapro.com/mcp"
bearer_token_env_var = "AILUNAPRO_MCP_KEY"
```

`bearer_token_env_var` holds the **name** of the variable, not the key itself.

**3. Check the connection**

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

`ailunapro` appears in the list. Then start Codex with `codex` and type `/mcp`. Expected:

```text theme={null}
ailunapro
  Status: enabled
  Auth: Bearer token
  URL: https://api.ailunapro.com/mcp
  Tools: audit_unanswered_required_count, docs_search_product, summary_draft_from_result
```

![Codex /mcp output listing the ailunapro server with bearer token auth](https://mintlify.s3.us-west-1.amazonaws.com/ailunapro-mcp/images/mcp/codex-mcp-light.png)

**4. Ask a question**

Start with a test that needs no audit:

```text theme={null}
Use the AiLunaPro docs search to tell me how to share a report with stakeholders.
```

The client runs `docs_search_product` and quotes AiLunaPro's product help about reports. If you see that answer, the connection works.

Then ask about your own audit:

```text theme={null}
Use AiLunaPro to summarise my latest audit result for my leadership team.
```

> [!NOTE]
>
> "No matching audit was found for your account" means your organisation has no completed Audit Express yet. Complete one in AiLunaPro, then ask again.

> [!NOTE]
>
> The Codex CLI, the Codex IDE extension and the ChatGPT desktop app share `config.toml`. Once AiLunaPro is configured in one, it is available in the others.

## Troubleshooting

> [accordion] /mcp shows ailunapro with an error or no tools
>
> The variable is not set in the environment Codex started from. Open a new terminal, check it, and start Codex again:
>
> ```powershell Windows theme={null}
> if ($env:AILUNAPRO_MCP_KEY) { 'set' } else { 'missing' }
> ```
>
> ```bash macOS / Linux theme={null}
> [ -n "$AILUNAPRO_MCP_KEY" ] && echo set || echo missing
> ```

> [accordion] Codex asks me to run codex mcp login
>
> AiLunaPro does not use OAuth. Check that `bearer_token_env_var` is set for `ailunapro` in `config.toml` and that the variable contains your key.

> [accordion] 401 Unauthorized
>
> The key is wrong or revoked. Create a new key, update the variable, open a new terminal and restart Codex.

More cases: [Troubleshooting](https://developers.ailunapro.com/developers/troubleshooting.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.