Connect Claude to ClickHouse
Hi, this is Vivek, building Contextflo. I share practical notes on getting answers from your data, a couple of times a month.

ClickHouse is the go-to warehouse for teams that need fast analytics on large volumes of event data. If you are tracking product events, logs or time-series at scale it is probably already on your shortlist. Here is how to connect it to Claude so your team can query it in natural language.

Why ClickHouse is different
ClickHouse is column-oriented and built for real-time analytics. It handles billions of rows without breaking a sweat. It also has quirks that trip up LLMs:
- The SQL dialect. Similar to standard SQL but with its own functions, aggregation syntax and array handling. Claude needs to know to use
toStartOfMonth()rather thanDATE_TRUNC. - Materialized views and table engines. ClickHouse tables use different engines (MergeTree, AggregatingMergeTree and others) that change how you should query them.
- Event-heavy schemas. ClickHouse databases tend toward wide, denormalised event tables with hundreds of columns. Without context, Claude has no idea which of them matter.
That third one is the real problem, and it is worse than it sounds. A model faced with a 200-column event table and no descriptions will pick a column that looks plausible by name. On a normalised schema a wrong guess usually errors. On a wide event table it returns a number, and the number looks fine.
Option 1: direct MCP connection
ClickHouse offers an official MCP server that lets Claude connect directly. ClickHouse Cloud also provides a remote MCP endpoint at mcp.clickhouse.cloud, so there is no local server to install. You authenticate, and Claude can list databases, inspect schemas and run SELECT queries.
This works for a data engineer who knows the schema and the dialect. For everyone else the usual gaps apply:
- No context about what tables and columns mean
- Claude may generate standard SQL instead of ClickHouse dialect
- No shared metric definitions
- No access control beyond database-level permissions
Option 2: ClickHouse plus Contextflo
Contextflo connects to ClickHouse Cloud or self-hosted instances. It reads your schema, source code and docs, and generates context that includes the ClickHouse-specific parts:
- Table and column descriptions generated from your schema, source code and docs
- ClickHouse-aware SQL generation with the correct functions and syntax
- Metric definitions that handle ClickHouse aggregation patterns
- Context for wide event tables that marks which columns actually matter
Your team asks questions in Claude, Contextflo supplies the context, Claude writes ClickHouse-compatible SQL, and the query runs against your instance.
Setting it up
- Create a read-only user in ClickHouse with SELECT privileges on the databases you want to expose.
- Add the connection in Contextflo with host, port, database and credentials.
- Select tables. Choose which to include. For wide event tables, annotate which columns are most useful.
- Review context. Descriptions are generated automatically. Refine the important ones.
- Connect Claude. Install the Contextflo MCP server and start querying.
Step 3 deserves more time than it looks like it needs on a ClickHouse schema specifically. Narrowing a 200-column table down to the twenty columns people actually ask about is the single highest-value thing you can do here, and it improves accuracy more than any amount of prompt wording.
Common ClickHouse questions
What's the p95 latency for API requests over the last 24 hours, grouped by endpoint?
Show me the top 10 events by volume this week compared to last week.
What percentage of users triggered checkout_started but not checkout_completed in the last 30 days?
These are fast in ClickHouse, often under a second even across billions of rows. With the right context, Claude writes them correctly first time. Without it, the first two usually work and the third quietly does not, because a funnel question depends on knowing how your event table identifies a user and a session.
Here is a more in-depth look at Contextflo and how it works.
What is Contextflo?
Contextflo is a governed context layer between your data and the AI your team already uses. Connect your warehouse once, and your team asks questions in their own Claude or ChatGPT. The model writes and runs the SQL; Contextflo supplies the definitions, the per-user access control, and the audit that make the answers trustworthy. Your data never moves, and you do not need a data team.
How it works
Your team queries in their own Claude or ChatGPT over MCP, so you bring any agent rather than a locked-in bot, and every answer comes back with the SQL shown and access enforced per user.
FAQ
How do I connect Claude to ClickHouse? Use an MCP server as the bridge between Claude and ClickHouse. ClickHouse offers an official MCP server, and ClickHouse Cloud provides a remote MCP endpoint at mcp.clickhouse.cloud so there is no local server to install. Once connected, Claude can list databases, inspect schemas, and run SELECT queries against your instance.
Is there a ClickHouse MCP server for Claude? Yes. ClickHouse maintains an official MCP server, and ClickHouse Cloud exposes a remote MCP endpoint you can authenticate against directly. You can also connect through Contextflo's MCP server, which adds table and column context so Claude writes ClickHouse-dialect SQL correctly.
Why does Claude write the wrong SQL for ClickHouse? ClickHouse has its own dialect, so Claude may reach for standard SQL like DATE_TRUNC instead of ClickHouse functions such as toStartOfMonth. Wide, denormalised event tables make it worse, because without column descriptions the model guesses a plausible column and can return a confident but wrong number. Supplying schema context and ClickHouse-aware SQL generation fixes both.
Can non-engineers query ClickHouse with Claude? Yes. Once ClickHouse is connected through MCP with context about what the tables and columns mean, someone in product, ops, or growth can ask a question in plain language and Claude writes the ClickHouse SQL. Narrowing wide event tables down to the columns people actually ask about is the highest-value step for accuracy.
Find out if Contextflo is the right fit for you.
See how teams use Contextflo
Related posts
Keep reading

Conversational analytics: 5 ways to set it up, compared
7 min read

How to connect Claude to BigQuery? What works and what doesn't in 2026
8 min read

How to connect Claude to Postgres without giving it write access
7 min read

How to build a BI dashboard with Claude that your team can actually trust
8 min read

How to give Claude read-only access to your database (it isn't always the default)
7 min read

You connected your warehouse to Claude, now what?
5 min read

The official Postgres server for Claude is archived. Here's what to use instead.
7 min read

Why is the team missing sprint goals? How to analyze Jira data with AI
8 min read

Are my ads actually profitable? How to analyze Facebook and TikTok ads together with AI
7 min read




