# Connect OpenAI Codex CLI to FineProxy MCP

Add the FineProxy MCP server to the OpenAI Codex CLI with codex mcp add or config.toml, sending the API key from an environment variable as a bearer token.

- Canonical: https://fineproxy.org/developers/docs/mcp/clients/codex/

This page shows how to connect the [OpenAI Codex CLI](https://developers.openai.com/codex/mcp) to the FineProxy MCP server. Codex connects directly over Streamable HTTP and sends your API key as a bearer token that it reads from an environment variable.

## Requirements

- Codex CLI with MCP support, `codex` on your `PATH`.
- A FineProxy API key (starts with `fb_`). Create one in [Settings → API keys](https://fineproxy.org/account_new/settings#api-keys). Start with read-only [scopes](/developers/docs/authentication/#scopes).

## Set up

### Where the config lives

| Scope | Path |
| --- | --- |
| User | `~/.codex/config.toml` |
| Project | `.codex/config.toml` (only in trusted projects) |

`~` is your home folder.

### Option 1: add the server with the CLI

1. Put your key in an environment variable:

   ```bash
   export FINEPROXY_API_KEY="fb_your_api_key"
   ```

2. Add the server:

   ```bash
   codex mcp add fineproxy --url https://fineproxy.org/account_new/api/v1/mcp \
     --bearer-token-env-var FINEPROXY_API_KEY
   ```

### Option 2: edit config.toml

Add this table to `~/.codex/config.toml`:

```toml
[mcp_servers.fineproxy]
url = "https://fineproxy.org/account_new/api/v1/mcp"
bearer_token_env_var = "FINEPROXY_API_KEY"
```

Codex reads the variable when it starts and sends `Authorization: Bearer <value>` with every request.

## Keep your key out of the config

- `bearer_token_env_var` stores only the **name** of the variable. The key itself stays in your environment, so `config.toml` holds no secret.
- `env_http_headers` maps header names to environment variable names in the same way, for servers that need other headers. For FineProxy, `bearer_token_env_var` is all you need.
- Avoid `http_headers` with a literal key: it writes the secret into `config.toml`.

> **Warning:** A project-level `.codex/config.toml` is easy to commit. Keep only variable names in it, never a literal `fb_...` key.

## Verify the connection

Check that the server is configured:

```bash
codex mcp list
codex mcp get fineproxy --json
```

Then start `codex`, type `/mcp` to see the active servers and their tools, and ask:

```text
What is my FineProxy balance?
```

Codex calls the `wallet_balance` tool and answers with your balance, for example `"balance_cents": 5000` — money values are integer cents, so that is $50.00.

## Tips

- **Approve tool calls.** Review each FineProxy tool call before Codex runs it, especially order, renewal and cancellation tools, and don't switch to an approval mode that runs money-moving tools unattended.
- **Use a read-only key first.** For exploring, a key with `customer:read`, `wallet:read`, `services:read` and `catalog:read` is enough. Without `wallet:spend`, the agent can't run tools that debit your wallet.
- **Add `wallet:spend` only for purchases.** Create a separate key with `wallet:spend` when you want Codex to buy or renew. Purchase tools carry a price guard and an idempotency key: a wrong total is rejected without a charge, and a retry with the same key never charges twice.
- Some tools take a while to answer (`list_countries` can take about 10 seconds). If a call times out, raise `tool_timeout_sec` for the server (the default is 60 seconds).
- Read [MCP safety](/developers/docs/mcp/safety/) and the [scopes reference](/developers/docs/authentication/#scopes) before you give an agent spending rights.

## Troubleshooting

| Symptom | Cause and fix |
| --- | --- |
| `401` | `FINEPROXY_API_KEY` isn't set in the shell that starts `codex`. Export it there and restart Codex. |
| Codex asks you to sign in with OAuth | The bearer token isn't configured. `codex mcp login` is for OAuth servers; FineProxy MCP accepts API keys only — use `bearer_token_env_var`. |
| The project config is ignored | `.codex/config.toml` is read only in trusted projects. Trust the project or use `~/.codex/config.toml`. |
| `429 Too Many Requests` | Too many sessions connecting at once. Wait a moment and start Codex again. |

For server-side errors and tool failures, see [MCP troubleshooting](/developers/docs/mcp/troubleshooting/).
