You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: clarify ClickHouse vs MCP environment variables (#211)
* docs: clarify ClickHouse vs MCP environment variables
Make it explicit that CLICKHOUSE_SECURE/PORT/VERIFY configure the
database HTTP(S) connection, not the MCP transport. Group env vars
into database connection vs MCP server/transport sections, document
HTTP vs native ports, and add common configuration pitfalls.
Fixes#172
* chore: re-trigger CLA check after signing
* refine environment variable descriptions
* clarify intention of glob pattern
---------
Co-authored-by: Joe S <joe.spadola@clickhouse.com>
The following environment variables are used to configure the ClickHouse and chDB connections:
487
+
Configuration is split into **independent** groups. Mixing them up is a common cause of hard-to-debug connection failures:
488
488
489
-
#### ClickHouse Variables
489
+
| Group | Variables | Controls |
490
+
|-------|-----------|----------|
491
+
|**ClickHouse database connection**|`CLICKHOUSE_HOST`, `CLICKHOUSE_PORT`, `CLICKHOUSE_SECURE`, `CLICKHOUSE_VERIFY`, … | How **this MCP server** connects to your ClickHouse cluster over the **HTTP interface**|
492
+
|**MCP server / transport**|`CLICKHOUSE_MCP_*`, `FASTMCP_SERVER_AUTH`, `FASTMCP_SERVER_AUTH_*`| MCP transport, authentication, and query-tool execution limits |
> Variables such as `CLICKHOUSE_SECURE`, `CLICKHOUSE_VERIFY`, and `CLICKHOUSE_PORT` apply to the **ClickHouse database** connection only. They do **not** configure TLS, ports, or auth for the MCP protocol endpoint.
497
+
>
498
+
> Example: if the MCP server runs in Kubernetes behind an ingress that terminates TLS, that is an **MCP transport** concern. Keep `CLICKHOUSE_SECURE` aligned with how the pod reaches ClickHouse itself (HTTPS → `true`, plain HTTP → `false`). Setting `CLICKHOUSE_SECURE=false` because the MCP server is behind an ingress will make the server dial ClickHouse over HTTP—often against an HTTPS-only port—and produce opaque HTTP/TLS errors in the server logs.
499
+
500
+
#### ClickHouse database connection
501
+
502
+
These variables configure the [clickhouse-connect](https://clickhouse.com/docs/en/integrations/python) HTTP client and the behavior of ClickHouse-backed tools such as `run_query`, `list_databases`, and `list_tables`.
490
503
491
504
##### Required Variables
492
505
493
-
*`CLICKHOUSE_HOST`: The hostname of your ClickHouse server
494
-
*`CLICKHOUSE_USER`: The username for authentication
495
-
*`CLICKHOUSE_PASSWORD`: The password for authentication
506
+
*`CLICKHOUSE_HOST`: The hostname of your ClickHouse server (database endpoint, not the MCP server bind address)
507
+
*`CLICKHOUSE_USER`: The username for **ClickHouse**authentication
508
+
*`CLICKHOUSE_PASSWORD`: The password for **ClickHouse**authentication
496
509
497
510
> [!CAUTION]
498
511
> It is important to treat your MCP database user as you would any external client connecting to your database, granting only the minimum necessary privileges required for its operation. The use of default or administrative users should be strictly avoided at all times.
499
512
500
513
##### Optional Variables
501
514
502
-
*`CLICKHOUSE_PORT`: The port number of your ClickHouse server
503
-
* Default: `8443` if HTTPS is enabled, `8123` if disabled
515
+
*`CLICKHOUSE_PORT`: HTTP interface port of your ClickHouse server
516
+
* Default: `8443` if `CLICKHOUSE_SECURE=true`, `8123` if `CLICKHOUSE_SECURE=false`
504
517
* Usually doesn't need to be set unless using a non-standard port
505
-
*`CLICKHOUSE_ROLE`: The role to use for authentication
518
+
***Must be an HTTP interface port**, not the native TCP protocol port used by `clickhouse-client`
519
+
* Common values:
520
+
* HTTP: `8123` (plain) / `8443` (TLS) — used by this server and ClickHouse Cloud HTTPS
521
+
* Native TCP (not supported here): `9000` (plain) / `9440` (TLS) — used by `clickhouse-client`
522
+
* If the server responds with `Port 9000 is for clickhouse-client program`, you are pointed at the native protocol; switch to the HTTP port (`8123`/`8443` or your deployment's HTTP mapping)
523
+
*`CLICKHOUSE_ROLE`: The ClickHouse role to use for authentication
* Set to `"false"` only when the MCP server reaches ClickHouse over plain HTTP (typical for local Docker Compose on port `8123`)
529
+
* Leave `"true"` for ClickHouse Cloud and any HTTPS database endpoint—even if the MCP server itself is exposed via HTTP, stdio, or an ingress that terminates TLS separately
530
+
* Mismatching this flag with the database port (e.g. `CLICKHOUSE_SECURE=false` against port `8443`) is a frequent setup mistake and usually surfaces as confusing HTTP client errors rather than a clear "wrong scheme" message
531
+
*`CLICKHOUSE_VERIFY`: Enable/disable SSL certificate verification for the **ClickHouse** HTTPS connection
512
532
* Default: `"true"`
513
533
* Set to `"false"` to disable certificate verification (not recommended for production)
514
534
* TLS certificates: The package uses your operating system trust store for TLS certificate verification via `truststore`. We call `truststore.inject_into_ssl()` at startup to ensure proper certificate handling. Python’s default SSL behavior is used as a fallback only if an unexpected error occurs.
515
-
*`CLICKHOUSE_SERVER_HOST_NAME`: Server hostname for SNI override and certificate validation
535
+
*`CLICKHOUSE_SERVER_HOST_NAME`: Server hostname for SNI override and certificate validation on the **ClickHouse** connection
516
536
* Default: None (uses the connection hostname)
517
537
* This is useful when connecting through proxies or load balancers where the certificate hostname differs from the connection hostname. When set, this hostname will be used for both SNI (Server Name Indication) during the TLS handshake and for certificate hostname validation.
518
-
*`CLICKHOUSE_CONNECT_TIMEOUT`: Connection timeout in seconds
538
+
*`CLICKHOUSE_PROXY_PATH`: URL path prefix for the ClickHouse HTTP endpoint
539
+
* Default: None
540
+
* Set this when the ClickHouse HTTP interface is exposed behind a reverse proxy under a path prefix (for example, `/clickhouse`)
541
+
*`CLICKHOUSE_CONNECT_TIMEOUT`: Connection timeout in seconds for the **ClickHouse** client
519
542
* Default: `"30"`
520
543
* Increase this value if you experience connection timeouts
521
-
*`CLICKHOUSE_SEND_RECEIVE_TIMEOUT`: Send/receive timeout in seconds
544
+
*`CLICKHOUSE_SEND_RECEIVE_TIMEOUT`: Send/receive timeout in seconds for the **ClickHouse** client
522
545
* Default: `"300"`
523
546
* Increase this value for long-running queries
524
-
*`CLICKHOUSE_DATABASE`: Default database to use
547
+
*`CLICKHOUSE_DATABASE`: Default ClickHouse database to use
525
548
* Default: None (uses server default)
526
549
* Set this to automatically connect to a specific database
527
-
*`CLICKHOUSE_MCP_SERVER_TRANSPORT`: Sets the transport method for the MCP server.
* Set to `"false"` to disable ClickHouse tools when using chDB only
553
+
*`CLICKHOUSE_ALLOW_WRITE_ACCESS`: Allow write operations (DDL and DML) against ClickHouse
554
+
* Default: `"false"`
555
+
* Set to `"true"` to allow DDL (CREATE, ALTER, DROP) and DML (INSERT, UPDATE, DELETE) operations
556
+
* When disabled (default), queries run with `readonly=1` setting to prevent data modifications
557
+
*`CLICKHOUSE_ALLOW_DROP`: Allow destructive operations (DROP TABLE, DROP DATABASE, DROP VIEW, DROP DICTIONARY, TRUNCATE TABLE)
558
+
* Default: `"false"`
559
+
* Only takes effect when `CLICKHOUSE_ALLOW_WRITE_ACCESS=true` is also set
560
+
* Set to `"true"` to explicitly allow destructive DROP and TRUNCATE operations
561
+
* This is a safety feature to prevent accidental data deletion during AI exploration
562
+
563
+
#### MCP server and transport
564
+
565
+
These variables control the MCP process itself, including transport, authentication, and query-tool execution limits. They are independent of the ClickHouse database settings above. See also [Authentication for HTTP/SSE Transports](#authentication-for-httpsse-transports).
566
+
567
+
*`CLICKHOUSE_MCP_SERVER_TRANSPORT`: Sets the transport method for the MCP server
528
568
* Default: `"stdio"`
529
569
* Valid options: `"stdio"`, `"http"`, `"sse"`. This is useful for local development with tools like MCP Inspector.
570
+
*`stdio` is typical for Claude Desktop; `http`/`sse` expose a network listener (bind host/port below)
530
571
*`CLICKHOUSE_MCP_BIND_HOST`: Host to bind the MCP server to when using HTTP or SSE transport
531
572
* Default: `"127.0.0.1"`
532
573
* Set to `"0.0.0.0"` to bind to all network interfaces (useful for Docker or remote access)
533
-
* Only used when transport is `"http"` or `"sse"`
574
+
* Only used when transport is `"http"` or `"sse"` — not related to `CLICKHOUSE_HOST`
534
575
*`CLICKHOUSE_MCP_BIND_PORT`: Port to bind the MCP server to when using HTTP or SSE transport
535
576
* Default: `"8000"`
536
-
* Only used when transport is `"http"` or `"sse"`
537
-
*`CLICKHOUSE_MCP_QUERY_TIMEOUT`: Timeout in seconds for SELECT tools
577
+
* Only used when transport is `"http"` or `"sse"` — not related to `CLICKHOUSE_PORT`
578
+
*`CLICKHOUSE_MCP_QUERY_TIMEOUT`: Timeout in seconds for query tools
538
579
* Default: `"30"`
539
580
* Increase this if you see `Query timed out after ...` errors for heavy queries
540
581
*`CLICKHOUSE_MCP_AUTH_TOKEN`: Static bearer token for HTTP/SSE transports
@@ -550,18 +591,6 @@ The following environment variables are used to configure the ClickHouse and chD
550
591
* Default: `"false"` (authentication is enabled)
551
592
* Set to `"true"` to disable authentication for local development/testing only
552
593
***WARNING:** Only use for local development. Do not disable when exposed to networks
* Set to `"false"` to disable ClickHouse tools when using chDB only
556
-
*`CLICKHOUSE_ALLOW_WRITE_ACCESS`: Allow write operations (DDL and DML)
557
-
* Default: `"false"`
558
-
* Set to `"true"` to allow DDL (CREATE, ALTER, DROP) and DML (INSERT, UPDATE, DELETE) operations
559
-
* When disabled (default), queries run with `readonly=1` setting to prevent data modifications
560
-
*`CLICKHOUSE_ALLOW_DROP`: Allow destructive operations (DROP TABLE, DROP DATABASE, DROP VIEW, DROP DICTIONARY, TRUNCATE TABLE)
561
-
* Default: `"false"`
562
-
* Only takes effect when `CLICKHOUSE_ALLOW_WRITE_ACCESS=true` is also set
563
-
* Set to `"true"` to explicitly allow destructive DROP and TRUNCATE operations
564
-
* This is a safety feature to prevent accidental data deletion during AI exploration
565
594
566
595
#### Middleware Variables
567
596
@@ -582,6 +611,12 @@ The following environment variables are used to configure the ClickHouse and chD
582
611
* Use `:memory:` for in-memory database
583
612
* Use a file path for persistent storage (e.g., `/path/to/chdb/data`)
584
613
614
+
#### Common configuration pitfalls
615
+
616
+
***`CLICKHOUSE_SECURE` vs MCP / ingress TLS** — Turning off `CLICKHOUSE_SECURE` because the MCP server sits behind Kubernetes ingress, a reverse proxy, or is reached over plain HTTP does not disable database TLS; it only changes how this process connects to ClickHouse. Configure ingress TLS separately from the database client settings.
617
+
***Native protocol ports** — `CLICKHOUSE_PORT` must target ClickHouse's HTTP interface (`8123`/`8443` by default). Ports `9000`/`9440` are for the native TCP protocol (`clickhouse-client`) and will not work with this server.
618
+
***Host confusion** — `CLICKHOUSE_HOST` is the database hostname. `CLICKHOUSE_MCP_BIND_HOST` is only the address the MCP HTTP/SSE server listens on.
0 commit comments