fix: add actionable hints on ClickHouse connection failures - #212
Conversation
Detect common misconfigurations when the HTTP client fails to connect: native TCP ports (9000/9440), TLS/scheme mismatches involving CLICKHOUSE_SECURE, and opaque HTTP errors. Surface clear hints in logs and raised errors so users do not confuse database client settings with MCP transport or ingress TLS. Also warn proactively when CLICKHOUSE_PORT is a known native protocol port. Related to ClickHouse#102 and the setup confusion described in ClickHouse#172.
joe-clickhouse
left a comment
There was a problem hiding this comment.
Hi @sankalpsthakur thanks for this work as well. I pushed a followup here too that separates an explicitly configured native port from the case where a cporrectly configured HTTP port is being misrouted to a native endpoint. It also preserves the original CH exception type, improves the generic connectivity guidance, and adds some tests around the scenario that #102 laid out and exception compatibility. Thanks again!
There was a problem hiding this comment.
Pull request overview
This PR improves the ClickHouse connection failure experience by adding targeted, actionable hints for common misconfigurations (native TCP vs HTTP ports, TLS/scheme mismatches, and opaque HTTP client errors), and by warning early when CLICKHOUSE_PORT is set to a known native protocol port.
Changes:
- Add
_connection_error_hints()+_format_connection_failure()and a_NATIVE_PROTOCOL_PORTSconstant to enrich connection-failure diagnostics. - Emit a warning before connecting when
CLICKHOUSE_PORTis set to a native TCP (clickhouse-client) port. - Add unit tests covering hint selection, formatting, logging, and the native-port warning.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
mcp_clickhouse/mcp_server.py |
Adds hint generation/formatting for connection failures and warns on native TCP ports before connecting. |
tests/test_connection_errors.py |
Adds unit tests validating hint behavior, formatting, logging output, and the native-port warning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Same here — ready when you are. |
Fixes #102
What
Improves failure messages when
create_clickhouse_client()cannot connect to ClickHouse by appending short, actionable Hints for common misconfigurations:9000/9440, or server messages likePort 9000 is for clickhouse-client program) — this server uses the HTTP interface (8123/8443).CLICKHOUSE_SECURE— clarifies that this flag is for the database HTTPS connection, not MCP or ingress TLS.CLICKHOUSE_SECURE+ HTTP interface port.Also logs a warning before connecting when
CLICKHOUSE_PORTis a known native protocol port.Companion docs change: #211 (README env-var grouping) addresses the same setup confusion described in #172.
Why
Users frequently misconfigure ports and
CLICKHOUSE_SECURE, then see low-context errors such as:The original exception is re-raised unchanged and hints are added to the log message.
Changes
mcp_clickhouse/mcp_server.py:_connection_error_hints,_format_connection_failure, native-port warning, richer raise pathtests/test_connection_errors.py: unit coverage for hints, formatting, raise path, and native-port warningValidation