Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ An MCP server for ClickHouse.

### ClickHouse Tools

* `list_clickhouse_tenants`
* List all clickhouse tenants.

* `run_select_query`
* Execute SQL queries on your ClickHouse cluster.
* Input: `sql` (string): The SQL query to execute.
Expand All @@ -24,6 +27,9 @@ An MCP server for ClickHouse.

### chDB Tools

* `list_chdb_tenants`
* List all chdb tenants.

* `run_chdb_select_query`
* Execute SQL queries using [chDB](https://github.com/chdb-io/chdb)'s embedded ClickHouse engine.
* Input: `sql` (string): The SQL query to execute.
Expand Down Expand Up @@ -168,6 +174,132 @@ You can also enable both ClickHouse and chDB simultaneously:
}
```

Multi-tenancy configuration is also supported. This is enabled by defining custom prefixes in front of the base environment variables. The below configuration creates two tenants: `cluster1` and `cluster2`.

```json
{
"mcpServers": {
"mcp-clickhouse": {
"command": "uv",
"args": [
"run",
"--with",
"mcp-clickhouse",
"--python",
"3.10",
"mcp-clickhouse"
],
"env": {
"cluster1_CLICKHOUSE_HOST": "<clickhouse-host>",
"cluster1_CLICKHOUSE_PORT": "<clickhouse-port>",
"cluster1_CLICKHOUSE_USER": "<clickhouse-user>",
"cluster1_CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"cluster1_CLICKHOUSE_SECURE": "true",
"cluster1_CLICKHOUSE_VERIFY": "true",
"cluster1_CLICKHOUSE_CONNECT_TIMEOUT": "30",
"cluster1_CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30",
"cluster1_CHDB_ENABLED": "true",
"cluster1_CHDB_DATA_PATH": "/path/to/chdb/data",
"cluster2_CLICKHOUSE_HOST": "<clickhouse-host>",
"cluster2_CLICKHOUSE_PORT": "<clickhouse-port>",
"cluster2_CLICKHOUSE_USER": "<clickhouse-user>",
"cluster2_CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"cluster2_CLICKHOUSE_SECURE": "true",
"cluster2_CLICKHOUSE_VERIFY": "true",
"cluster2_CLICKHOUSE_CONNECT_TIMEOUT": "30",
"cluster2_CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30",
"cluster2_CHDB_ENABLED": "true",
"cluster2_CHDB_DATA_PATH": "/path/to/chdb/data"
}
}
}
}
```

If no custom prefix is defined, a `default` tenant is automatically assigned based on the original environment variables. Defining custom tenants using the reserved `default` prefix is not allowed. The below example creates two tenants: `default` and `custom`.

```json
{
"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",
"custom_CLICKHOUSE_HOST": "<clickhouse-host>",
"custom_CLICKHOUSE_PORT": "<clickhouse-port>",
"custom_CLICKHOUSE_USER": "<clickhouse-user>",
"custom_CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"custom_CLICKHOUSE_SECURE": "true",
"custom_CLICKHOUSE_VERIFY": "true",
"custom_CLICKHOUSE_CONNECT_TIMEOUT": "30",
"custom_CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30",
"custom_CHDB_ENABLED": "true",
"custom_CHDB_DATA_PATH": "/path/to/chdb/data"
}
}
}
}
```

The below example will throw an error as `default` prefix is used.

```json
{
"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",
"default_CLICKHOUSE_HOST": "<clickhouse-host>",
"default_CLICKHOUSE_PORT": "<clickhouse-port>",
"default_CLICKHOUSE_USER": "<clickhouse-user>",
"default_CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"default_CLICKHOUSE_SECURE": "true",
"default_CLICKHOUSE_VERIFY": "true",
"default_CLICKHOUSE_CONNECT_TIMEOUT": "30",
"default_CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30",
"default_CHDB_ENABLED": "true",
"default_CHDB_DATA_PATH": "/path/to/chdb/data"
}
}
}
}
```

3. Locate the command entry for `uv` and replace it with the absolute path to the `uv` executable. This ensures that the correct version of `uv` is used when starting the server. On a mac, you can find this path using `which uv`.

4. Restart Claude Desktop to apply the changes.
Expand Down
4 changes: 4 additions & 0 deletions mcp_clickhouse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .mcp_server import (
list_clickhouse_tenants,
list_chdb_tenants,
create_clickhouse_client,
list_databases,
list_tables,
Expand All @@ -9,6 +11,8 @@
)

__all__ = [
"list_clickhouse_tenants",
"list_chdb_tenants",
"list_databases",
"list_tables",
"run_select_query",
Expand Down
4 changes: 2 additions & 2 deletions mcp_clickhouse/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .mcp_server import mcp
from .mcp_env import get_config, TransportType
from .mcp_env import get_mcp_config, TransportType


def main():
config = get_config()
config = get_mcp_config()
transport = config.mcp_server_transport

# For HTTP and SSE transports, we need to specify host and port
Expand Down
Loading