anfra docsAlpha
Set up local developmentSet up your coding agent

OpenAI Codex

Set up OpenAI Codex to build with anfra, and connect it to anfra's MCP server

Codex can build your whole anfra project: connect your warehouse, write models and datasets, query them and build data apps. It needs two things from anfra: the anfra plugin, which teaches it how, and optionally the MCP server, which lets it query a published project on anfra BI Cloud or a running anfra serve.

Set up

Step 1: Install the CLI

The plugin drives the anfra binary, so install it first:

curl -fsSL https://anfra.ai/install.sh | bash

Open a new terminal afterwards so anfra is on your PATH. On Windows, install it inside WSL2, and run Codex there too. See Install the CLI for Windows and the installer options.

Step 2: Install the anfra plugin

anfra agent setup --agent codex

This adds holistics/anfra-skills as a plugin marketplace in Codex and installs the anfra plugin from it, for your user, so it works in every project. Without --agent, it sets up every coding agent it finds on your machine. Run it again to update to the latest version.

Restart Codex to load the plugin. It brings:

  • Skills to set up a project, write AML, write, check and run AQL queries, build data apps, and convert a Looker project.
  • Hooks that validate AML files as Codex edits them, and tell Codex at the start of a session when a newer anfra release is out.

The plugin's aql-writer agent is for Claude Code only.

Run in an anfra project, the command also writes an anfra block into the project's AGENTS.md, which tells Codex to use the skills there.

Step 3: Check the installation

anfra agent setup check

It changes nothing. It reports the plugin installed in Codex and its version, and whether it is behind the latest release.

Use the skills

Codex picks the right skill for most requests on its own. To be sure, name the skill in your prompt.

Example prompt

Use the anfra-build-data-app skill. Build a revenue overview with a monthly trend and revenue by region. Clicking a region should filter the trend.

To start a new project, open an empty folder in Codex and ask it to use the anfra-setup-repo skill.

Connect to the MCP server

The skills work with the project on disk, through the anfra CLI. Add the MCP server when you want Codex to query data it can't reach that way, such as your organization's published project on anfra BI Cloud. Run it yourself, or connect to anfra BI Cloud, which hosts it for your organization. To compare, see Where your MCP server runs.

anfra BI Cloud

codex mcp add anfra --url https://us.anfra.ai/mcp

Codex opens your browser to sign in. If it doesn't, or the sign-in expires, run codex mcp login anfra. When you approve the connection, you pick one organization, and Codex acts as you there, with your role.

The command saves the server in ~/.codex/config.toml, so it is available in every project. You can also add it there by hand:

~/.codex/config.toml
[mcp_servers.anfra]
url = "https://us.anfra.ai/mcp"

If sign-in fails with a callback error, your admin may have limited where clients can return after sign-in. Ask them to allow http://localhost:*/* under Settings → Organization → MCP → Allowed callbacks. See MCP access.

Your machine or server

To query the project on your machine, run anfra serve and add the address it prints:

codex mcp add anfra --url http://127.0.0.1:7878/mcp

It needs no sign-in. For a self-hosted server behind your own authentication, put the token in an environment variable and name it with --bearer-token-env-var. Codex sends it as Authorization: Bearer <token>:

export ANFRA_MCP_TOKEN=<token>
codex mcp add anfra --url https://data.example.com/mcp --bearer-token-env-var ANFRA_MCP_TOKEN

If you self-host with the anfra-hosting image, see Coding agents with MCP for the header to send.

Check the connection

Run codex mcp list in your terminal, or /mcp in Codex, to see anfra and its tools. Then ask a question about your data.

Example prompt

Using the anfra MCP server, list the datasets I can query, then show last month's revenue by region.

See Tools for what the server offers.

On this page