Connector guide7-minute read10 MCP tools7 languages

How to Connect ClickHouse to Gemini via MCP

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

HCBy HelpCode teamUpdated 7 min read Open-source on GitHub

No credit card · 7-day trial · Self-host alternative available

ClickHouse

ClickHouse

Read-only SQL on a ClickHouse server or ClickHouse Cloud service over the HTTP interface: databases, tables, columns, CREATE statements, table sizes, running and recent queries, and any SELECT with readonly=1.

tools

10

Region

INTL

Category

Databases

Authentication

Basic Auth

Required env vars

CLICKHOUSE_URLCLICKHOUSE_USERCLICKHOUSE_PASSWORD
Install in one click on Cloud

7-day free trial · No credit card

  • 7-day free trial
    No credit card required
  • GDPR & SOC 2 ready
    EU data residency, audit logs
  • Open-source on GitHub
    Open source · AGPL-3.0
  • Works with ChatGPT, Claude, Gemini
    Any MCP-compatible client

Skip the install. Get this working in under 2 minutes.

Start a free trial on cloud.anythingmcp.com, add the ClickHouse in one click, then point your AI client (Claude, ChatGPT, Copilot or Cursor) at the generated MCP endpoint. No Docker, no git clone, zero engineering experience required.

Start free trial

Summary

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Try asking

Example prompts for ClickHouse

Click any prompt to copy it. Paste into Claude, ChatGPT, Cursor, Gemini, Copilot or OpenClaw to run it against this connector.

ClickHouse · live via MCP
Share
Opus 4.7

Claude is AI and can make mistakes. Please double-check responses.

💡 No install? Use cloud.anythingmcp.com directly. Sign in, click Connectors → ClickHouse, paste your credentials, mint an MCP API key and you're done. No Docker, no git clone, no local server.

ClickHouse + Gemini

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Prerequisites

See the full setup instructions baked into the connector (visible in the in-app store when you select the connector). The required environment variables for this connector are:

CLICKHOUSE_URL, CLICKHOUSE_USER, CLICKHOUSE_PASSWORD

Step 1 — Get credentials

Setting up takes about 3 minutes. You need the HTTPS address of a ClickHouse server or ClickHouse Cloud service and a user that may read.

  1. Put the address of the HTTP interface, with its port, into CLICKHOUSE_URL. On ClickHouse Cloud open the service, click Connect, choose HTTPS and copy the host, e.g. https://abc123xyz.europe-west4.gcp.clickhouse.cloud:8443. Self-hosted: https://your-host:8443, or http://your-host:8123 on a private network. Scheme, host and port only, no path.
  2. Create a dedicated user that may only read, for example CREATE USER mcp_reader IDENTIFIED BY '...'; GRANT SELECT ON analytics.* TO mcp_reader;. For clickhouse_table_sizes, clickhouse_running_queries and clickhouse_recent_queries also grant GRANT SELECT ON system.parts, system.processes, system.query_log TO mcp_reader. On ClickHouse Cloud the built-in user is default.
  3. Do not give that user a settings profile with readonly = 2: the connector sets readonly=1 on each request and ClickHouse rejects that change under readonly = 2. readonly = 0 or 1 both work.
  4. Put the user name into CLICKHOUSE_USER and its password into CLICKHOUSE_PASSWORD. They are sent as HTTP Basic auth.
  5. ClickHouse Cloud only: the service's IP access list must allow the address AnythingMCP calls from.
  6. Install the connector and run clickhouse_server_info: it shows version, uptime, server time zone, the signed-in user, its default database and its effective readonly level.

What it reads: the databases the user can see with engine and comment, the tables and views of one database (engine, total rows and bytes, readable size, comment), the columns of a table with type, default expression and whether they belong to the partition, sorting or primary key, the CREATE statement of a table or view (engine, ORDER BY, PARTITION BY, TTL, settings, or the SELECT behind a view), and columns found by name across databases with clickhouse_search_columns. For operations: storage per table from the active parts, the queries running now and the finished or failed queries from the query log. clickhouse_query runs one statement of type SELECT, WITH, SHOW, DESCRIBE, EXPLAIN or EXISTS.

What it writes: nothing. Every request carries the setting readonly=1, so ClickHouse refuses INSERT, ALTER, CREATE, DROP and SET whatever the user's grants. Because there are no write tools, no tool is switched off at install.

How the AI queries: it explores with clickhouse_list_databases, clickhouse_list_tables, clickhouse_describe_table and clickhouse_show_create_table, then filters on the sorting key and partition columns, aggregates in SQL (count(), sum(), uniq(), quantile(0.95)(x), toStartOfDay(ts)) and always ends with LIMIT. Before a query that may scan a large table it can run EXPLAIN or EXPLAIN ESTIMATE. A query is one statement without a FORMAT clause and without a trailing semicolon; database sets the default database for unqualified table names.

Data formats: the JSON format returns meta (column names and types), data (rows), rows (row count) and statistics (elapsed seconds, rows and bytes read). clickhouse_query can also answer in JSONCompact (rows as arrays, smaller), CSVWithNames or TabSeparatedWithNames. 64-bit integers (UInt64, Int64) arrive as strings, so "12345678901" is a number. DateTime values are YYYY-MM-DD hh:mm:ss in the server time zone from clickhouse_server_info unless the column type names another. Sizes from formatReadableSize are binary units (KiB, MiB, GiB).

Paging and limits: there is no paging and no row cap besides your LIMIT and the connector's response size limit; the whole result comes back in one answer, so aggregate rather than fetch raw rows. clickhouse_search_columns returns up to 500 matches. clickhouse_recent_queries returns the last 100 queries within minutes (default 60). clickhouse_running_queries shows only the node that answers, on ClickHouse Cloud one replica of the service. A Cloud service that idles wakes on the first query, which can take up to a minute.

Common errors: the body carries Code: <n>. DB::Exception: .... Code 164 (READONLY) means the statement writes or changes a setting. 497 (ACCESS_DENIED, HTTP 403) means a missing GRANT, or on ClickHouse Cloud an IP access list that does not allow this server. 60 (UNKNOWN_TABLE) and 81 (UNKNOWN_DATABASE) mean a wrong name, 62 (SYNTAX_ERROR) bad SQL, 159 or 241 a timeout or memory limit: narrow the query. 401 or 516 (AUTHENTICATION_FAILED) means a wrong user or password. Nothing answering at the address usually means a wrong port or a path in CLICKHOUSE_URL.

The connector does not insert, update or delete data, does not create or change tables, and does not manage ClickHouse Cloud services (start, stop, scaling, backups, costs): for that install the separate ClickHouse Cloud connector.

Step 2 — Install the adapter

curl -fsSL https://raw.githubusercontent.com/HelpCode-ai/anythingmcp/main/docker-compose.quickstart.yml -o docker-compose.yml
printf 'JWT_SECRET=%s\nENCRYPTION_KEY=%s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 32)" > .env
docker compose up -d

Step 3 — Add the connector in Gemini

Your server URL: in AnythingMCP, open MCP Servers → the server this connector is on, and copy its URL (https://cloud.anythingmcp.com/mcp/…). Use it wherever this guide shows YOUR_SERVER_ID.

Gemini CLI reads MCP servers from ~/.gemini/settings.json (on Windows %USERPROFILE%\.gemini\settings.json). Add:

{
  "mcpServers": {
    "anythingmcp": {
      "httpUrl": "https://cloud.anythingmcp.com/mcp/YOUR_SERVER_ID",
      "headers": { "X-API-Key": "YOUR_MCP_API_KEY" }
    }
  }
}
  1. Create an MCP API key in AnythingMCP under MCP Servers → your server → API keys, and paste it in place of YOUR_MCP_API_KEY.
  2. Save the file and restart gemini.
  3. Run /mcp inside Gemini CLI (or gemini mcp list in your shell): anythingmcp should show as connected.
  4. Start prompting: Gemini CLI can now call the ClickHouse tools.

Available tools

ToolWhat it does
clickhouse_server_infoVersion, uptime in seconds, server time zone, the user the connector signs in as, its default database and its effective readonly level
clickhouse_queryRun one read-only SQL statement (SELECT, WITH, SHOW, DESCRIBE, EXPLAIN, EXISTS) and return the result
clickhouse_list_databasesEvery database the user can see, with its engine and comment
clickhouse_list_tablesTables and views of one database: engine (MergeTree family, View, MaterializedView, Dictionary, ...), total rows and bytes when the engine…
clickhouse_describe_tableColumns of a table in order: name, type, default kind and expression, comment, and whether the column is part of the partition, sorting or…
clickhouse_show_create_tableThe CREATE statement of a table or view: engine, ORDER BY, PARTITION BY, TTL and settings, or the SELECT behind a view
clickhouse_search_columnsFind columns by name across databases (case-insensitive LIKE), up to 500 matches: database, table, column, type and comment
clickhouse_table_sizesStorage per table of one database from the active parts: rows, part count, bytes on disk, compressed and uncompressed size, last…
clickhouse_running_queriesQueries running right now on the node that answers: query id, user, elapsed seconds, rows read, memory and the first 500 characters of the…
clickhouse_recent_queriesThe last 100 finished or failed queries of the past minutes from the query log: time, user, type (QueryFinish, ExceptionBeforeStart…

Example prompts

  • "Which databases and tables are there, and which tables take the most disk space?"
  • "How many events per day did we have in analytics.events over the last 30 days?"
  • "Where is a column like customer_id stored? Search across all databases."
  • "Show me the queries that failed in the last hour with their error code."
  • "What are the top 10 countries by revenue this month? Check the sorting key first so the query stays cheap."

FAQ

Where does Gemini CLI look for MCP servers? In ~/.gemini/settings.json for your user, or in .gemini/settings.json inside a project. gemini mcp list shows each server and whether it connects.

Next steps

Was this guide helpful?

Your ClickHouse agent is one click away.

Install the connector, paste the key, prompt Gemini. Free for 7 days, no credit card.

Related guides

Connectors

ClickHouse to MCP: Read-only SQL, Schema Exploration, Table Sizes and Query Log in any AI Agent

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Connectors

How to Connect ClickHouse to ChatGPT via MCP

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Connectors

How to Connect ClickHouse to Claude via MCP

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Connectors

How to Connect ClickHouse to Cursor via MCP

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Connectors

How to Connect ClickHouse to Meta Muse via MCP

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.

Connectors

How to Connect ClickHouse to Microsoft Copilot via MCP

Let any AI agent query a ClickHouse server or ClickHouse Cloud service in read-only mode over the HTTP interface: list databases, tables and columns, read CREATE statements, check table sizes, see running and recent queries, and run any SELECT. Every request carries readonly=1, so ClickHouse itself refuses writes.