Blog
guide

How to Connect ClickHouse to OpenAI Codex Using Sequel

Musthaq Ahamad
Musthaq Ahamad
How to Connect ClickHouse to OpenAI Codex Using Sequel

ClickHouse handles analytics at scale: billions of events, sub-second aggregations. The OpenAI Codex CLI brings AI coding assistance to your terminal. With Sequel's MCP server connecting them, you can ask natural language questions about your ClickHouse data from within the same terminal session where you build and debug code.

What You'll Accomplish

Once set up, you can launch Codex and ask:

  • "How many events were recorded in the last 24 hours?"
  • "What's the most common error code in the past hour?"
  • "Which user segments have the highest 7-day retention?"

Prerequisites

Step 1: Connect Your ClickHouse Database to Sequel

Sign in to sequel.sh and click Data Sources in the left sidebar.

Sequel Data Sources page

Click New Connection. On the "Choose a connector" page, select ClickHouse.

Choose a connector

Fill in the connection fields:

  • Connection Name -- a memorable label, e.g. ClickHouse Prod
  • Host -- your ClickHouse hostname, without https:// or http://
  • Port -- 8443 for ClickHouse Cloud, 8123 for self-hosted HTTP
  • Username -- e.g. default
  • Password -- your ClickHouse password
  • Database -- the database name to connect to

ClickHouse connection form

For ClickHouse Cloud, find these in your service dashboard under Connect -> HTTPS interface.

Click Connect to verify and save.

Step 2: Get Your Sequel API Key

Click Settings in the left sidebar, then select API Keys from the settings navigation.

Sequel API Keys page

Click New key, name it codex, and copy the key (starts with sql_).

Step 3: Configure Codex CLI to Use Sequel MCP

Set your API key as an environment variable -- add to ~/.zshrc or ~/.bashrc:

export SEQUEL_API_KEY="sql_your_api_key"

Reload your shell:

source ~/.zshrc

Add Sequel to ~/.codex/config.toml -- create the file if it doesn't exist:

[mcp_servers.sequel]
url = "https://api.sequel.sh/mcp"
bearer_token_env_var = "SEQUEL_API_KEY"

Save the file. The next Codex session will load the Sequel MCP server automatically.

Step 4: Query Your ClickHouse Database

codex

Then ask:

What tables are in the ClickHouse database?
How many events per event_type were tracked yesterday?
Show me the hourly breakdown of API request counts for today.

What You Can Do Now

  • Query data while coding -- ask "What do the most recent 10 rows in the events table look like?" without leaving your terminal
  • Debug analytics pipelines -- ask "Are there any event types with zero records in the past hour?" to spot ingestion gaps
  • Validate data after deployments -- ask "Are new events being tracked after the latest release?"
  • Build analytics features -- describe the metrics you need, then ask Codex to write the ClickHouse query grounded in your actual schema
  • Benchmark before optimizing -- ask "How many rows does this table have?" before writing query optimization code

Try Sequel

Meet your always-on data analyst.

An AI data analyst that connects to all your data and answers questions with reports and visualizations. Free for up to 3 seats - no credit card required.

Get started free

Frequently asked questions

Where does the OpenAI Codex CLI store MCP server configuration?

The Codex CLI reads MCP server config from "~/.codex/config.toml". Create this file if it doesn't exist. Each MCP server is defined as a [mcp_servers.name] section in TOML format.

Does the Codex CLI support ClickHouse Cloud?

Yes. Use the HTTPS host and port 8443 from your ClickHouse Cloud service settings when adding the data source in Sequel.

What ClickHouse connection details do I need?

You need the hostname (without https://), port (8443 for ClickHouse Cloud), username, password, and database name. These are entered as individual fields in Sequel's ClickHouse connector.

Why use bearer_token_env_var for the API key?

Storing the API key in an environment variable keeps it out of config files that might be committed to source control or shared with others.

Can I use this alongside other Codex MCP servers?

Yes. The Codex CLI supports multiple MCP servers in config.toml. Add each server under its own [mcp_servers.name] section.

How do I find my ClickHouse Cloud connection details?

In your ClickHouse Cloud console, go to your service, click Connect, and choose the HTTPS interface. Your host, port, username, and password are shown there.

Written by

Musthaq Ahamad
Musthaq Ahamad

Co-founder and CEO of Sequel. Previously built developer tools and data infrastructure. Passionate about making data accessible for everyone.