ClickHouse MCP Server for AI Assistants
Connect ClickHouse to your AI assistants with an MCP server to enable fast, scalable queries and real-time data access for smarter, responsive AI apps.
npx -y @ClickHouse/mcp-clickhouseOverview
This MCP (Model Context Protocol) server connects ClickHouse — and an embedded chDB ClickHouse engine — to AI assistants and other MCP-capable clients. It exposes a small set of deterministic, focused RPC-style tools that let LLMs and assistant apps run fast, read-optimized SQL, discover schema metadata, and pull fresh records in real time without building custom ETL layers.
By deploying this server you can enable your assistant to answer questions with up-to-date analytics, run ad-hoc queries, and inspect tables and databases securely. The implementation is optimized for ClickHouse’s high-throughput, low-latency reads and supports querying external data via chDB’s embedded engine for use cases where you want to query files or remote sources directly.
Features
- Execute read-optimized SQL on ClickHouse via an MCP tool.
- Inspect cluster objects: list databases and paginated table metadata.
- Optional support for chDB (embedded ClickHouse) to query local files, URLs, or external databases without ETL.
- Health check endpoint for HTTP/SSE transports that reports ClickHouse connectivity and version.
- Authentication for HTTP/SSE transports (token-based) with a development mode to disable auth locally.
- Configurable timeouts, TLS verification, and role-based connection options.
Installation / Configuration
Install the package from PyPI (or run via your preferred Python toolchain):
Typical environment variables used to configure a ClickHouse connection:
# optional role
# enable TLS
# verify server certs
To enable chDB (embedded engine):
# optional: disable remote ClickHouse
Authentication (HTTP/SSE transports):
# generate a secure token (example)
# development: disable auth only for local testing
Claude Desktop / local MCP client snippet (example JSON):
Available Tools
run_query
- Purpose: Execute SQL against ClickHouse.
- Input: { “query”: “
” } - Notes: Server runs read-only by default. Writes are blocked unless explicitly allowed via configuration.
list_databases
- Purpose: Return available database names.
- Input: none
list_tables
- Purpose: Paginated listing of tables and optional column metadata.
- Inputs:
- database (string, required)
- like / not_like (string, optional) — filter by table name
- page_token (string, optional) — token for next page
- page_size (int, default 50)
- include_detailed_columns (bool, default true)
- Response shape:
- tables: array of table objects (name, create_table_query, columns if requested)
- next_page_token: string | null
- total_tables: int
run_chdb_select_query
- Purpose: Run SELECT-style SQL against chDB’s embedded engine to query external sources directly.
- Input: { “query”: “
” } - Use to query files, URLs, or heterogeneous data without moving data into ClickHouse.
Health check (HTTP/SSE): GET /health — returns 200 and ClickHouse version when connected, 503 when not.
Use Cases
Real-time assistant answers from production analytics
- An assistant can run parameterized read-only SQL to fetch the latest metrics (top customers, KPI values) and combine them with model reasoning.
Ad-hoc data exploration for LLM prompts
- Use list_tables and run_query to let an assistant discover schema and produce context-aware SQL queries, enabling dynamic diagnostics and data-driven responses.
Querying external data without ETL
- With chDB enabled, run_chdb_select_query can read CSVs, JSON hosted on URLs, or other sources directly, letting models reason over external datasets without loading them into ClickHouse.
Embedding in dashboards and automation
- Trigger automated data checks or human-in-the-loop workflows where an assistant runs a fast aggregation via run_query and returns summarized results.
Security & Operational Notes
- HTTP/SSE transports require token authentication by default. The stdio transport (used for local CLI integrations) does not require a token.
- Never disable authentication in production. CLICKHOUSE_MCP_AUTH_DISABLED=true is for local development only.
- By default the server restricts write operations; enable write access explicitly if you need mutating queries.
- Monitor the /health endpoint from orchestration systems to assert ClickHouse connectivity.
For source code, issues, and contributions see the project repository: https://github.com/ClickHouse/mcp-clickhouse.