Skip to content

Commit 1235413

Browse files
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>
1 parent 66f0d1b commit 1235413

1 file changed

Lines changed: 66 additions & 31 deletions

File tree

README.md

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -484,57 +484,98 @@ CLICKHOUSE_PASSWORD=clickhouse
484484

485485
### Environment Variables
486486

487-
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:
488488

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 |
493+
| **Middleware / chDB** | `MCP_MIDDLEWARE_MODULE`, `CHDB_*` | Optional extensions |
494+
495+
> [!IMPORTANT]
496+
> 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`.
490503

491504
##### Required Variables
492505

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
496509

497510
> [!CAUTION]
498511
> 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.
499512
500513
##### Optional Variables
501514

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`
504517
* 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
506524
* Default: None
507525
* Set this if your user requires a specific role
508-
* `CLICKHOUSE_SECURE`: Enable/disable HTTPS connection
526+
* `CLICKHOUSE_SECURE`: Enable HTTPS **for the ClickHouse database connection** (not for MCP clients)
509527
* Default: `"true"`
510-
* Set to `"false"` for non-secure connections
511-
* `CLICKHOUSE_VERIFY`: Enable/disable SSL certificate verification
528+
* 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
512532
* Default: `"true"`
513533
* Set to `"false"` to disable certificate verification (not recommended for production)
514534
* 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
516536
* Default: None (uses the connection hostname)
517537
* 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
519542
* Default: `"30"`
520543
* 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
522545
* Default: `"300"`
523546
* Increase this value for long-running queries
524-
* `CLICKHOUSE_DATABASE`: Default database to use
547+
* `CLICKHOUSE_DATABASE`: Default ClickHouse database to use
525548
* Default: None (uses server default)
526549
* Set this to automatically connect to a specific database
527-
* `CLICKHOUSE_MCP_SERVER_TRANSPORT`: Sets the transport method for the MCP server.
550+
* `CLICKHOUSE_ENABLED`: Enable/disable ClickHouse database tools
551+
* Default: `"true"`
552+
* 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
528568
* Default: `"stdio"`
529569
* 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)
530571
* `CLICKHOUSE_MCP_BIND_HOST`: Host to bind the MCP server to when using HTTP or SSE transport
531572
* Default: `"127.0.0.1"`
532573
* 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`
534575
* `CLICKHOUSE_MCP_BIND_PORT`: Port to bind the MCP server to when using HTTP or SSE transport
535576
* 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
538579
* Default: `"30"`
539580
* Increase this if you see `Query timed out after ...` errors for heavy queries
540581
* `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
550591
* Default: `"false"` (authentication is enabled)
551592
* Set to `"true"` to disable authentication for local development/testing only
552593
* **WARNING:** Only use for local development. Do not disable when exposed to networks
553-
* `CLICKHOUSE_ENABLED`: Enable/disable ClickHouse functionality
554-
* Default: `"true"`
555-
* 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
565594

566595
#### Middleware Variables
567596

@@ -582,6 +611,12 @@ The following environment variables are used to configure the ClickHouse and chD
582611
* Use `:memory:` for in-memory database
583612
* Use a file path for persistent storage (e.g., `/path/to/chdb/data`)
584613

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.
619+
585620
#### Example Configurations
586621

587622
For local development with Docker:

0 commit comments

Comments
 (0)