How to Use ClickHouse MCP for Analytics
Run high-performance analytical queries, manage tables, and analyze large datasets in ClickHouse directly from Claude Code.
What is the ClickHouse MCP?
ClickHouse is an open-source column-oriented OLAP database optimized for real-time analytics on massive datasets. The ClickHouse MCP connects Claude Code to your ClickHouse instance, enabling it to write and execute analytical queries, inspect table schemas, manage materialized views, and help you build efficient data pipelines — orders of magnitude faster than a traditional row-store database.
Installation
mcpizy install clickhouse
Provide your ClickHouse connection details (host, port, database, username, password) during setup. ClickHouse Cloud connections with TLS are fully supported.
Key Capabilities
- Execute analytical SQL — run aggregations, window functions, and array operations on billions of rows.
- Inspect schemas and table engines — understand MergeTree family configurations and sort keys.
- Manage materialized views — create and debug views that pre-aggregate data at insert time.
- Query system tables — inspect query logs, part metadata, and replication status.
- Profile slow queries — identify which queries are consuming the most resources.
Example Usage
Compute daily active users over the last 30 days:
SELECT
toDate(event_time) AS date,
uniqExact(user_id) AS dau
FROM events
WHERE event_time >= now() - INTERVAL 30 DAY
GROUP BY date
ORDER BY date;
Claude writes and runs this query, then suggests adding a materialized view to pre-compute it for dashboards.
Tips and Best Practices
- Use uniq() instead of
uniqExact()for approximate distinct counts on very large datasets — much faster with minimal error. - Always specify a WHERE clause on the primary key or partition key — Claude can verify your sort key before writing queries.
- Combine with DuckDB MCP for local ad-hoc analysis before loading data into ClickHouse.
- Use ClickHouse's system.query_log table to find and optimize your most expensive queries.