Skip to content

Add mTLS (mutual TLS) support#116

Open
vkazmirchuk wants to merge 1 commit intoClickHouse:mainfrom
vkazmirchuk:feature/mtls-support
Open

Add mTLS (mutual TLS) support#116
vkazmirchuk wants to merge 1 commit intoClickHouse:mainfrom
vkazmirchuk:feature/mtls-support

Conversation

@vkazmirchuk
Copy link

@vkazmirchuk vkazmirchuk commented Jan 27, 2026

Summary

This PR adds support for mutual TLS (mTLS) client certificate authentication, enabling connections to ClickHouse servers that require client certificates.

Changes

  • Added new environment variables in mcp_env.py:

    • CLICKHOUSE_CA_CERT: Path to CA certificate file for SSL verification
    • CLICKHOUSE_CLIENT_CERT: Path to client certificate file for mTLS authentication
    • CLICKHOUSE_CLIENT_CERT_KEY: Path to client private key file (optional if using combined .pem)
    • CLICKHOUSE_TLS_MODE: TLS mode for client certificate usage (mutual, proxy, or strict)
  • Updated get_client_config() to pass these parameters to clickhouse_connect.get_client()

  • Added comprehensive documentation in README.md:

    • New "mTLS (Mutual TLS) Variables" section with all four environment variables
    • Example configuration for mTLS setup
    • Example Claude Desktop configuration with mTLS

Motivation

Some ClickHouse deployments require mutual TLS authentication for enhanced security. Currently, there's no way to configure client certificates in mcp-clickhouse, which prevents connections to such servers.

The clickhouse-connect library already supports these parameters (ca_cert, client_cert, client_cert_key, tls_mode), so this PR simply exposes them through environment variables.

Example Usage

{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "uv",
      "args": ["run", "--with", "mcp-clickhouse", "--python", "3.10", "mcp-clickhouse"],
      "env": {
        "CLICKHOUSE_HOST": "your-secure-clickhouse.example.com",
        "CLICKHOUSE_PORT": "8443",
        "CLICKHOUSE_USER": "your-user",
        "CLICKHOUSE_PASSWORD": "your-password",
        "CLICKHOUSE_SECURE": "true",
        "CLICKHOUSE_CA_CERT": "/path/to/ca.crt",
        "CLICKHOUSE_CLIENT_CERT": "/path/to/client.crt",
        "CLICKHOUSE_CLIENT_CERT_KEY": "/path/to/client.key",
        "CLICKHOUSE_TLS_MODE": "mutual"
      }
    }
  }
}

Testing

  • Tested with ClickHouse server requiring mTLS authentication
  • Verified backward compatibility (no changes when mTLS variables are not set)

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2026

CLA assistant check
All committers have signed the CLA.

@vkazmirchuk vkazmirchuk changed the title feat: add mTLS (mutual TLS) support Add mTLS (mutual TLS) support Jan 27, 2026
- Add CLICKHOUSE_TLS_MODE to README mTLS section with valid options
- Update ClickHouseConfig docstring with TLS_MODE variable

feat: add CLICKHOUSE_TLS_MODE support for proxy/strict modes
docs: add mTLS configuration documentation

Document new environment variables for mutual TLS authentication:
- CLICKHOUSE_CA_CERT
- CLICKHOUSE_CLIENT_CERT
- CLICKHOUSE_CLIENT_CERT_KEY

Include example configuration for mTLS setup.

feat: add mTLS (mutual TLS) support

Add support for client certificate authentication (mTLS) via new
environment variables:
- CLICKHOUSE_CA_CERT: Path to CA certificate file
- CLICKHOUSE_CLIENT_CERT: Path to client certificate file
- CLICKHOUSE_CLIENT_CERT_KEY: Path to client private key file

These parameters are passed to clickhouse-connect's get_client()
function to enable secure connections to ClickHouse servers that
require mutual TLS authentication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants