# Connect Codex

_Connect an AI assistant · 2 min read · Updated 2026-10-28 · https://lanachat.ai/guides/ai-connect-codex/_

Codex reads its MCP servers from a configuration file, `config.toml`. You add one block for LanaChat. You need Codex installed ([guide](https://lanachat.ai/guides/ai-install-assistant/)) and your token ([guide](https://lanachat.ai/guides/ai-create-mcp-token/)).

## Where the file is

- Mac and Linux: `~/.codex/config.toml` (the hidden `.codex` folder in your home folder).
- Windows: `%USERPROFILE%\.codex\config.toml`.

If the file does not exist yet, create it. It is a plain text file.

## Add the block

Open the file in a text editor and add these lines at the end. Replace `YOUR_MCP_TOKEN` with your token.

```toml
[mcp_servers.lanachat]
url = "https://api.lanachat.ai/mcp"
http_headers = { "Authorization" = "Bearer YOUR_MCP_TOKEN" }
```

Save the file.

## Safer: keep the token out of the file

Codex can read the token from an environment variable instead. Use this block instead of the one above:

```toml
[mcp_servers.lanachat]
url = "https://api.lanachat.ai/mcp"
bearer_token_env_var = "LANACHAT_MCP_TOKEN"
```

Then set the variable before you start Codex. On a Mac or Linux:

```bash
read -s LANACHAT_MCP_TOKEN && export LANACHAT_MCP_TOKEN && codex
```

Paste the token when the cursor waits (nothing shows), press Enter, and Codex starts with the token.

## Check it is connected

1. Start Codex: `codex`.
2. Type `/mcp` and press Enter.
3. `lanachat` is in the list of active servers.

From the terminal, `codex mcp list` shows the configured servers.

> Note: After a token rotation, put the new token in the file (or the variable) and restart Codex. After changing the boxes of the token with **Edit**, restart Codex too.

Next: [test the connection](https://lanachat.ai/guides/ai-test-connection/).

## Related

- [Create your MCP token](https://lanachat.ai/guides/ai-create-mcp-token/)
- [Test the connection](https://lanachat.ai/guides/ai-test-connection/)
- [Troubleshooting the MCP: 401, 403, missing tools](https://lanachat.ai/guides/ai-troubleshooting/)
