> The index of all pages is at https://docs.afffast.com/llms.txt.

# Codex CLI

Add the MCP server to Codex in config.toml, and check that it works.

Codex reads its MCP servers from `~/.codex/config.toml`. The file stores the name of the environment variable that holds the key. It does not store the key.

## Install

1. Make a test key in the dashboard. A test key starts with `sk_test_`.
2. Put the key in an environment variable:

   ```bash
   export AFFFAST_API_KEY="sk_test_..."
   ```

3. Add the server to `~/.codex/config.toml`:

   ```toml
   [mcp_servers.afffast]
   url = "https://api.afffast.com/mcp"
   bearer_token_env_var = "AFFFAST_API_KEY"
   ```

   Codex sends the value of `AFFFAST_API_KEY` in the header `Authorization: Bearer ...`.

You can also add the server with a command:

```bash
codex mcp add afffast --url https://api.afffast.com/mcp
```

This command does not set the key. Add the line `bearer_token_env_var = "AFFFAST_API_KEY"` to the new table in `config.toml`.

To use the server in one project only, put the same table in `.codex/config.toml` of the project. Codex reads this file only for a trusted project.

## Check that it works

- Run `codex mcp list`. The list must show `afffast`.
- Start `codex`. Type `/mcp`. The server must show its tools.

## Example prompts

- "Use the afffast tools to show the revenue by network for last month."
- "Find the conversions with the status declined this week. Group them by program."
- "List my sites and the number of clicks that each site got in the last 7 days."

## Troubleshooting

- **The server does not connect.** Make sure that `AFFFAST_API_KEY` is set in the shell that started `codex`. A variable that you set in another terminal does not apply.
- **A 401 error.** The key is wrong or revoked. Make a new key.
- **The tools are missing.** The key decides the tools. A read-only key has no write tools.
- **The project config is ignored.** Codex reads `.codex/config.toml` only in a trusted project.
- **You see a login prompt.** `codex mcp login` is for OAuth. This server uses an API key and has no OAuth. Use `bearer_token_env_var`.

## Security

- Never paste a key into a chat. Use the environment variable.
- Start with a test key. A test key reads and writes test data only.
- Use a read-only key if the tool must only read.
- Never put the key in `config.toml`. Use `bearer_token_env_var`.
