AI assistants
ClickHouse MCP server

ClickHouse MCP server

Connect Claude, ChatGPT or Claude Code to ClickHouse over MCP (Model Context Protocol), without putting a password on anyone's laptop. The assistant reads the tables, writes SQL and runs it, and Thunderduck checks every query before it reaches ClickHouse.

The problem: an assistant with a ClickHouse password

The usual way to give an assistant ClickHouse is a local MCP server started with a host, user and password. It works on day one, and it leaves you with three problems once the cluster is a real one:

  • The password lives in a config file on every machine that uses it, usually for a user with more rights than the assistant needs.
  • Nothing stops an expensive query. ClickHouse is fast, which makes it easy for an assistant exploring an events table to scan billions of rows, or pull them all back to filter them itself.
  • The assistant only sees names and types. duration could be seconds or milliseconds, and type = 4 means nothing without the application code, so plausible SQL returns wrong numbers.

How Thunderduck solves it

Thunderduck runs a hosted MCP server in front of ClickHouse, at https://mcp.thunderduck.ai/mcp.

  • No password on any laptop. The ClickHouse password goes to a secrets manager when you add the service. People sign in to the assistant with their own Thunderduck account (OAuth), and the assistant never sees the password.
  • Read-only, always. ClickHouse catalogs cannot write. INSERT, ALTER, DROP and the like are refused before the request leaves Thunderduck, whatever the user's token allows.
  • The aggregation runs in ClickHouse. Queries go to ClickHouse through clickhouse_query, with the filtering and grouping inside the call, so only the small result comes back. Thunderduck never transfers a whole table to filter it.
  • Columns come with meanings. Thunderduck infers a description and a unit for each column and lets your team correct them. The assistant reads them before it writes SQL. See Column meanings.
  • One server for every database. The same connection reaches your PostgreSQL, MySQL, BigQuery and S3 data, and one query can join a ClickHouse result with any of them.

Set it up

1. Create a read-only user

Run this in ClickHouse. Change the database name and the password:

CREATE USER thunderduck_ro IDENTIFIED BY '…' SETTINGS readonly = 1;
GRANT SELECT ON analytics.* TO thunderduck_ro;

2. Add the service as a catalog

In the console, Catalogs → Create catalog → ClickHouse. Give it a short lowercase name such as events, then enter:

FieldValue
HostBare hostname: no https://, no port, no path
HTTP port8443 with TLS (the default), 8123 without
DatabaseThe database the user can read, default if you leave it empty
User, passwordThe user from step 1

Only the catalog's database is listed for the assistant, not every database on the server. All fields are on the ClickHouse page.

3. Connect your assistant

Claude (claude.ai and Claude Desktop): Settings → Connectors → Add custom connector, paste the URL below, and sign in.

https://mcp.thunderduck.ai/mcp

Claude Code:

claude mcp add --transport http thunderduck https://mcp.thunderduck.ai/mcp \
  --client-id thunderduck-mcp-cli --callback-port 33418

ChatGPT: add a connector with the same URL.

More on each client in Connecting Claude & ChatGPT.

4. Ask a question

Which products got the most page views in the last 30 days, and what are their names?

The assistant calls get_catalog_context('events') to read the tables and column meanings, checks the price with estimate_query_cost, then runs something like:

SELECT p.name, c.views
FROM   clickhouse_query('events',
         'SELECT product_id, count(*) AS views
            FROM analytics.page_views
           WHERE day >= today() - 30
        GROUP BY product_id') AS c
JOIN   shop.public.products AS p ON p.id = c.product_id
ORDER  BY c.views DESC
LIMIT  20;

ClickHouse tables are not addressed as catalog.schema.table. The inner SQL is ClickHouse's own dialect and runs entirely in ClickHouse; the join with the Postgres products table happens in Thunderduck. If the assistant writes events.analytics.page_views instead, the refusal names the clickhouse_query form to use.

What the assistant can do

List tables and columns in the catalog's databaseYes
Read column meaningsYes
Run SELECT through clickhouse_queryYes, within the cost limits
Export a large result to Parquet or CSVOnly with the export scope
INSERT, ALTER, DROPNo: ClickHouse catalogs are read-only

The full list is on the Tools page.

Good to know

  • Aggregate inside the call. Whatever the inner query returns has to fit in the query's memory, so a SELECT * over billions of rows fails.
  • ClickHouse errors arrive as HTTP statuses. A SQL error inside clickhouse_query shows up as, for example, HTTP 404 Not Found rather than ClickHouse's own message. Run the inner statement in ClickHouse directly to see the real error.
  • An idle ClickHouse Cloud service takes tens of seconds to wake. The first query while it wakes can fail; run it again.

Compared with a local open-source server

Open-source ClickHouse MCP servers run on your own machine with a host, user and password. For a local ClickHouse, or a quick look at a dev cluster, that is the simpler choice: no account, nothing hosted, and ClickHouse's full SQL with nothing in between.

Thunderduck fits when the cluster is shared or in production: when more than one person will connect, when the password should not sit in config files, or when the questions join ClickHouse with your other databases.

Related