ClickHouse MCP server

Integrates with ClickHouse to enable natural language querying and exploration of large datasets while maintaining read-only safeguards.
Back to servers
Setup instructions
Provider
ClickHouse
Release date
Dec 25, 2024
Language
Python
Stats
441 stars

The ClickHouse MCP Server enables Claude to interact with ClickHouse databases and run SQL queries. It provides tools for executing SELECT queries, listing databases and tables, and also supports chDB's embedded OLAP engine for querying data from various sources without ETL processes.

Installation and Configuration

Installing the Server

You can install the ClickHouse MCP server in two ways:

Method 1: Using uv (Recommended)

  1. Add the following configuration to your Claude Desktop configuration file:
{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp-clickhouse",
        "--python",
        "3.10",
        "mcp-clickhouse"
      ],
      "env": {
        "CLICKHOUSE_HOST": "<clickhouse-host>",
        "CLICKHOUSE_PORT": "<clickhouse-port>",
        "CLICKHOUSE_USER": "<clickhouse-user>",
        "CLICKHOUSE_PASSWORD": "<clickhouse-password>",
        "CLICKHOUSE_SECURE": "true",
        "CLICKHOUSE_VERIFY": "true",
        "CLICKHOUSE_CONNECT_TIMEOUT": "30",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
      }
    }
  }
}
  1. Replace the placeholder values with your actual ClickHouse connection details.
  2. Find the absolute path to your uv executable (using which uv on Mac) and replace the command entry with this path.
  3. Restart Claude Desktop to apply the changes.

Method 2: Using System Python

  1. Install the package using pip:
python3 -m pip install mcp-clickhouse
  1. Update your Claude Desktop configuration:
{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "python3",
      "args": [
        "-m",
        "mcp_clickhouse.main"
      ],
      "env": {
        "CLICKHOUSE_HOST": "<clickhouse-host>",
        "CLICKHOUSE_PORT": "<clickhouse-port>",
        "CLICKHOUSE_USER": "<clickhouse-user>",
        "CLICKHOUSE_PASSWORD": "<clickhouse-password>",
        "CLICKHOUSE_SECURE": "true",
        "CLICKHOUSE_VERIFY": "true",
        "CLICKHOUSE_CONNECT_TIMEOUT": "30",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
      }
    }
  }
}

Alternatively, you can use the installed script directly:

{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "mcp-clickhouse",
      "env": {
        "CLICKHOUSE_HOST": "<clickhouse-host>",
        "CLICKHOUSE_PORT": "<clickhouse-port>",
        "CLICKHOUSE_USER": "<clickhouse-user>",
        "CLICKHOUSE_PASSWORD": "<clickhouse-password>",
        "CLICKHOUSE_SECURE": "true",
        "CLICKHOUSE_VERIFY": "true",
        "CLICKHOUSE_CONNECT_TIMEOUT": "30",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
      }
    }
  }
}

Configuration Options

The server supports both ClickHouse and chDB, and you can enable either or both depending on your needs.

ClickHouse Configuration

For a quick start using the ClickHouse SQL Playground:

{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp-clickhouse",
        "--python",
        "3.10",
        "mcp-clickhouse"
      ],
      "env": {
        "CLICKHOUSE_HOST": "sql-clickhouse.clickhouse.com",
        "CLICKHOUSE_PORT": "8443",
        "CLICKHOUSE_USER": "demo",
        "CLICKHOUSE_PASSWORD": "",
        "CLICKHOUSE_SECURE": "true",
        "CLICKHOUSE_VERIFY": "true",
        "CLICKHOUSE_CONNECT_TIMEOUT": "30",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
      }
    }
  }
}

chDB Configuration

To use the embedded OLAP engine:

{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp-clickhouse",
        "--python",
        "3.10",
        "mcp-clickhouse"
      ],
      "env": {
        "CHDB_ENABLED": "true",
        "CLICKHOUSE_ENABLED": "false",
        "CHDB_DATA_PATH": "/path/to/chdb/data"
      }
    }
  }
}

Combined Configuration

You can enable both ClickHouse and chDB simultaneously:

{
  "mcpServers": {
    "mcp-clickhouse": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp-clickhouse",
        "--python",
        "3.10",
        "mcp-clickhouse"
      ],
      "env": {
        "CLICKHOUSE_HOST": "<clickhouse-host>",
        "CLICKHOUSE_PORT": "<clickhouse-port>",
        "CLICKHOUSE_USER": "<clickhouse-user>",
        "CLICKHOUSE_PASSWORD": "<clickhouse-password>",
        "CLICKHOUSE_SECURE": "true",
        "CLICKHOUSE_VERIFY": "true",
        "CLICKHOUSE_CONNECT_TIMEOUT": "30",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30",
        "CHDB_ENABLED": "true",
        "CHDB_DATA_PATH": "/path/to/chdb/data"
      }
    }
  }
}

Environment Variables

Required ClickHouse Variables

  • CLICKHOUSE_HOST: The hostname of your ClickHouse server
  • CLICKHOUSE_USER: The username for authentication
  • CLICKHOUSE_PASSWORD: The password for authentication

Optional ClickHouse Variables

  • CLICKHOUSE_PORT: Default is 8443 for HTTPS, 8123 for HTTP
  • CLICKHOUSE_SECURE: Enable/disable HTTPS connection (default: "true")
  • CLICKHOUSE_VERIFY: Enable/disable SSL certificate verification (default: "true")
  • CLICKHOUSE_CONNECT_TIMEOUT: Connection timeout in seconds (default: "30")
  • CLICKHOUSE_SEND_RECEIVE_TIMEOUT: Send/receive timeout in seconds (default: "300")
  • CLICKHOUSE_DATABASE: Default database to use
  • CLICKHOUSE_ENABLED: Enable/disable ClickHouse functionality (default: "true")

chDB Variables

  • CHDB_ENABLED: Enable/disable chDB functionality (default: "false")
  • CHDB_DATA_PATH: Path to chDB data directory (default: ":memory:")

Server Transport Variables

  • CLICKHOUSE_MCP_SERVER_TRANSPORT: Sets transport method ("stdio", "http", "sse") (default: "stdio")
  • CLICKHOUSE_MCP_BIND_HOST: Host to bind when using HTTP/SSE transport (default: "127.0.0.1")
  • CLICKHOUSE_MCP_BIND_PORT: Port to bind when using HTTP/SSE transport (default: "8000")

Using the MCP Server

ClickHouse Tools

Running SELECT Queries

You can execute read-only SQL queries on your ClickHouse cluster:

SELECT * FROM system.databases LIMIT 10

All queries are executed with readonly = 1 for safety.

Listing Databases

To list all databases on your ClickHouse cluster:

list_databases

Listing Tables

To list all tables in a specific database:

list_tables database_name

Replace database_name with the actual name of your database.

chDB Tools

If you've enabled chDB, you can query data directly from various sources without ETL processes:

SELECT * FROM 'https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet' LIMIT 10

Health Check

When running with HTTP or SSE transport, a health check endpoint is available at /health:

curl http://localhost:8000/health
# Response: OK - Connected to ClickHouse 24.3.1

This returns 200 OK with the ClickHouse version if the server is healthy, or 503 Service Unavailable if it cannot connect to ClickHouse.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mcp-clickhouse" '{"command":"uv","args":["run","--with","mcp-clickhouse","--python","3.13","mcp-clickhouse"],"env":{"CLICKHOUSE_HOST":"<clickhouse-host>","CLICKHOUSE_PORT":"<clickhouse-port>","CLICKHOUSE_USER":"<clickhouse-user>","CLICKHOUSE_PASSWORD":"<clickhouse-password>","CLICKHOUSE_SECURE":"true","CLICKHOUSE_VERIFY":"true","CLICKHOUSE_CONNECT_TIMEOUT":"30","CLICKHOUSE_SEND_RECEIVE_TIMEOUT":"30"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mcp-clickhouse": {
            "command": "uv",
            "args": [
                "run",
                "--with",
                "mcp-clickhouse",
                "--python",
                "3.13",
                "mcp-clickhouse"
            ],
            "env": {
                "CLICKHOUSE_HOST": "<clickhouse-host>",
                "CLICKHOUSE_PORT": "<clickhouse-port>",
                "CLICKHOUSE_USER": "<clickhouse-user>",
                "CLICKHOUSE_PASSWORD": "<clickhouse-password>",
                "CLICKHOUSE_SECURE": "true",
                "CLICKHOUSE_VERIFY": "true",
                "CLICKHOUSE_CONNECT_TIMEOUT": "30",
                "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mcp-clickhouse": {
            "command": "uv",
            "args": [
                "run",
                "--with",
                "mcp-clickhouse",
                "--python",
                "3.13",
                "mcp-clickhouse"
            ],
            "env": {
                "CLICKHOUSE_HOST": "<clickhouse-host>",
                "CLICKHOUSE_PORT": "<clickhouse-port>",
                "CLICKHOUSE_USER": "<clickhouse-user>",
                "CLICKHOUSE_PASSWORD": "<clickhouse-password>",
                "CLICKHOUSE_SECURE": "true",
                "CLICKHOUSE_VERIFY": "true",
                "CLICKHOUSE_CONNECT_TIMEOUT": "30",
                "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later