clickhouse-mcp
Provides tools to list databases and tables, describe table schemas, and execute SQL statements including SELECT, DDL, and DML against a specified ClickHouse database, with per-call database routing, row caps, timeouts, and query IDs for traceability.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
clickhouse-mcp
An MCP server (stdio) for ClickHouse. The database is a required argument on every database-touching tool call, not server state: one server can answer questions about many databases without reconnecting.
Built with the official mcp SDK v2 and
clickhouse-connect. Connection
details come from environment variables; the per-call database is validated
as a simple identifier and routed through the driver's per-query database
setting. It is never interpolated into SQL.
Safety model:
execute_sqlis read-only by default. Statements other thanSELECT,SHOW,DESCRIBE,DESC,EXPLAIN,WITHandEXISTS(andSELECT ... INTO OUTFILE) are rejected locally, and every query also carries ClickHouse'sreadonly=1andallow_ddl=0settings. SetCLICKHOUSE_ALLOW_WRITE_ACCESS=trueto allow full SQL, including DDL and DML; the server then sends neither setting. These are defense-in-depth measures, not a substitute for access control in ClickHouse: deploy with a dedicated, least-privilege user, neverdefaultor an admin account.readonlydoes not block backups, andallow_ddldoes not restrict grants. Queries are capped byCLICKHOUSE_TIMEOUTandCLICKHOUSE_MAX_ROWS, and the row cap uses a matchingmax_block_size; row-returningSELECT/WITH/EXPLAINstatements are also wrapped in an outerLIMITso ClickHouse stops at the cap. Note thatreadonly=1rejects query-levelSETTINGSclauses, so remove them or use a restricted ClickHouse profile. It can also reject reads needing table functions. In write-enabled mode the caps are best-effort because a query can override them with its ownSETTINGS; enable writes only for trusted callers.
Configuration (environment variables)
Variable | Required | Default | Description |
| yes | — | ClickHouse hostname or IP |
| yes | — | ClickHouse user |
| no | empty | Password for the user |
| no | driver default | HTTP/HTTPS port ( |
| no |
| Use HTTPS/TLS |
| no |
| Verify TLS certificate |
| no |
| Connect/read timeout and max execution time, seconds |
| no |
| Hard cap on rows returned per call |
| no |
| Allow DDL/DML through |
There is intentionally no CLICKHOUSE_DATABASE variable. Booleans accept
true/false/1/0/yes/no/on/off (case-insensitive); invalid values abort startup.
.env.example is the canonical list of variables.
Related MCP server: mysql-mcp-zag
Concurrency
One ClickHouse client serves the whole process, and the MCP SDK runs each
synchronous tool on a worker thread, so calls can overlap. The client is created
with autogenerate_session_id=False, the driver's supported mode for sharing a
client across threads; nothing here relies on session state, because every call
is a single statement and database, readonly and the row/time caps travel as
per-request settings.
Tools
Tool | Description | Read-only |
| List databases visible to the configured user | yes |
| List tables in | yes |
| Describe one table in | yes |
| Run one SQL statement in | yes by default; writes opt-in |
database and table must be simple identifiers: letters, digits and
underscores, starting with a letter or underscore, at most 128 characters.
Quoted, dotted or Unicode names are rejected. This is a deliberate ceiling: it
keeps caller-controlled names safe without a parser. sql must contain exactly
one statement; trailing semicolons are ignored, semicolons inside string
literals are fine, and a second statement is rejected.
List tools return {"items": [...], "returned_count": 50, "has_more": true, "next_offset": 50, "query_id": "abc123def456"}. returned_count is the number
of items in this page; when has_more is true, pass next_offset as the next
call's offset. limit defaults to 50 and values above CLICKHOUSE_MAX_ROWS
are clamped to that cap. describe_table returns the same item shape with
returned_count, truncated and query_id.
execute_sql returns:
{
"database": "analytics",
"query_id": "abc123def456",
"columns": ["event", "count"],
"data": [["click", 42]],
"row_count": 1,
"truncated": false,
"summary": "OK",
"statistics": {"read_rows": 100, "elapsed_ns": 1234567}
}Non-finite Float values (nan, inf, -inf) are returned as null so the
payload remains valid JSON.
For DDL/DML, columns and data are empty, row_count is 0, and summary
carries the driver's result. Each call gets a correlation ID that is also sent
to ClickHouse as query_id, so stderr logs and system.query_log line up.
Logs go to stderr only; stdout is reserved for MCP stdio transport. SQL arguments
are never logged, and credentials/long literals in driver messages are
redacted while short table, column and setting names are kept for diagnosis.
Failures are surfaced as MCP tool errors with a code prefix:
INVALID_INPUT (including invalid database/table names), QUERY_FAILED or
CONFIG_ERROR. Driver messages are redacted before they reach the model.
Required ClickHouse privileges
list_databasesandlist_tablesreadsystem.databasesandsystem.tables; the configured user needs access to those system tables.describe_tablerunsDESCRIBE TABLE, which requires the correspondingSHOW/metadata privilege on the table.execute_sqlneedsSELECTfor read queries, plus the relevant DDL/DML grants whenCLICKHOUSE_ALLOW_WRITE_ACCESS=true.Use a dedicated user/profile. System tables may expose names beyond the user's query grants, and ClickHouse remains the authoritative access control.
Example calls
{"tool": "list_tables", "arguments": {"database": "analytics", "limit": 50, "offset": 0}}{"tool": "execute_sql", "arguments": {"database": "analytics", "sql": "SELECT event, count FROM events LIMIT 10", "max_rows": 10}}{"tool": "execute_sql", "arguments": {"database": "analytics", "sql": "SELECT * FROM events SETTINGS max_threads=4"}}The last example is rejected in read-only mode because query-level SETTINGS
are disabled; remove the clause or use a restricted profile.
Example client configuration
{
"mcpServers": {
"clickhouse": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/JakePeralta7/clickhouse-mcp.git",
"clickhouse-mcp"
],
"env": {
"CLICKHOUSE_HOST": "clickhouse.internal",
"CLICKHOUSE_USER": "mcp_reader",
"CLICKHOUSE_PASSWORD": "from-your-secret-store"
}
}
}
}Docker:
{
"mcpServers": {
"clickhouse": {
"command": "docker",
"args": ["run", "--rm", "-i",
"-e", "CLICKHOUSE_HOST", "-e", "CLICKHOUSE_USER",
"-e", "CLICKHOUSE_PASSWORD", "ghcr.io/jakeperalta7/clickhouse-mcp:latest"]
}
}
}Development
uv sync --group devuv run pytest -q(tests, including the tool-contract checks)uv run pyright(type check)uv run python -m clickhouse_mcp(fails fast without host/user)docker compose up -dthen$env:CLICKHOUSE_INTEGRATION="1"; uv run pytest -q -m integrationfor live checks against the seeded ClickHouseevals/README.mdfor the ten-question evaluation set
See AGENTS.md for the module layout, verification tiers and the add-a-tool
recipe.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Query, join, profile, clean and convert CSV/JSON/Parquet with server-side DuckDB over MCP.
Hosted BigQuery MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables interaction with ClickHouse databases via MCP, providing tools to list databases and tables and execute safe SELECT, SHOW, and DESCRIBE queries.41 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables SQL query execution and database structure browsing via MCP tools and resources.MIT
- AlicenseAqualityDmaintenanceEnables AI assistants to query and manage ClickHouse databases, supporting SELECT queries, DDL/DML statements, and metadata listing.57 npmMIT
- FlicenseAqualityDmaintenanceRead-only MCP server for ClickHouse that allows listing databases and tables, describing schemas, and running SELECT queries.4-