# Codex

Codex connects to the hosted [Costfluent MCP server](/developers/mcp) at `https://mcp.costfluent.com` from a table in its `config.toml`, and you sign in or pass an API token. The Codex CLI, its IDE extension and the ChatGPT desktop app share that file. To run the server on your machine instead, `costfluent mcp install` adds a table that starts it and passes `COSTFLUENT_API_TOKEN` from Codex's environment to the server rather than holding the token.

## Before you start

- To sign in, a Costfluent account in the organization Codex should read. To pass a token, or to run the server on your machine, an API token from the **Read only** preset; see [Create a token](/developers/mcp#create-a-token).
- To run the server on your machine, `costfluent-mcp` and the [command line](/developers/cli#install), `costfluent`, on your `PATH`; both come in the same [release archive](/developers/mcp#install-the-server).

## Connect and sign in

<Stepper>

1. Run `codex mcp add costfluent --url https://mcp.costfluent.com`. It adds the server's table to `~/.codex/config.toml`.
2. Run `codex mcp login costfluent`. Costfluent opens in your browser: sign in, choose the organization Codex may read and select **Allow**. In a terminal without a browser, run it with `--no-browser`.
3. Ask Codex a question, such as "What did we spend on AWS last month, by service?".

</Stepper>

## Connect with an API token

For the write tools, pass a token instead of signing in. Write the table into `~/.codex/config.toml` with `bearer_token_env_var`, which names the variable Codex sends as the bearer token, so the file holds no token:

```toml
[mcp_servers.costfluent]
url = "https://mcp.costfluent.com"
bearer_token_env_var = "COSTFLUENT_API_TOKEN"
```

Start Codex from a shell where `COSTFLUENT_API_TOKEN` is set, and ask it a question.

## Run it on your machine

<Stepper>

1. Run `costfluent mcp install --client codex --write`. It adds the server to `~/.codex/config.toml`; with `--project` it writes `.codex/config.toml` in the current directory instead.
2. Set `COSTFLUENT_API_TOKEN` to the token in your shell, and start Codex from that shell.
3. Ask Codex a question, such as "What did we spend on AWS last month, by service?".

</Stepper>

## How it behaves

- Signed in, Codex gets the read tools alone, and never more than you may read yourself in that organization. It is listed under **Settings**, **Connected apps** in Costfluent, where **Revoke** disconnects it.
- `costfluent mcp install` keeps every other table in `config.toml`, and refuses a file that already defines a `costfluent` server unless `--force` replaces it.

## Related

- [MCP server](/developers/mcp): the token, the tools and how the server behaves
- [Command line](/developers/cli#connect-an-assistant): every client `costfluent mcp install` writes for
- [costfluent/agent-skills](https://github.com/costfluent/agent-skills): the cost skills for Codex
- [Ask good questions](/developers/mcp#ask-good-questions) and [Troubleshooting](/developers/mcp#troubleshooting): asking for the right figures, and what each error means
