ClickHouse
About
Integrates with ClickHouse to enable natural language querying and exploration of large datasets while maintaining read-only safeguards.
Details
- Author
- clickhouse
- Repository
- ClickHouse/mcp-clickhouse
- GitHub stars
- 818
- Downloads
- 899
- License
- Apache License 2.0
- Categories
- Developer Tools, Database, Other, Productivity, AI, Design, Search, Knowledge Base, Frontend
- Tags
- #sql, #analytics
Jump to
- Execute SQL queries on ClickHouse (read‑only by default)
- List all databases in your ClickHouse cluster
- List tables with pagination, filtering (LIKE/NOT LIKE)
- Support for chDB embedded ClickHouse engine
- Health check endpoint for HTTP/SSE transports
- Authentication via static bearer token or OAuth/OIDC
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
ClickHouseCommand (node, npx, python, etc.)uvArguments-
Argument 1
run -
Argument 2
--with -
Argument 3
mcp-clickhouse -
Argument 4
--python -
Argument 5
3.10 -
Argument 6
mcp-clickhouse
Environment-
CLICKHOUSE_HOST
<clickhouse-host> -
CLICKHOUSE_PORT
<clickhouse-port> -
CLICKHOUSE_ROLE
<clickhouse-role> -
CLICKHOUSE_USER
<clickhouse-user> -
CLICKHOUSE_SECURE
true -
CLICKHOUSE_VERIFY
true -
CLICKHOUSE_PASSWORD
<clickhouse-password> -
CLICKHOUSE_CONNECT_TIMEOUT
30 -
CLICKHOUSE_SEND_RECEIVE_TIMEOUT
30
Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
-
Argument 1
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
Development Mode Disabling Authentication
For local development and testing only, you can disable authentication by setting:
export CLICKHOUSE_MCP_AUTH_DISABLED=true
WARNING:Only use this for local development. Do not disable authentication when the server is exposed to any network.
This MCP server supports both ClickHouse and chDB. You can enable either or both depending on your needs.
-
Open the Claude Desktop configuration file located at:
- On macOS:~/Library/Application Support/Claude/claude_desktop_config.json
- On Windows:%APPDATA%/Claude/claude_desktop_config.json
{ "mcpServers": { "mcp-clickhouse": { "command": "uv", "args": ](https://gofastmcp.com/servers/auth)[ "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_ROLE": "<clickhouse-role>", "CLICKHOUSE_SECURE": "true", "CLICKHOUSE_VERIFY": "true", "CLICKHOUSE_CONNECT_TIMEOUT": "30", "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30" } } } }
Update the environment variables to point to your own ClickHouse service.
Or, if you'd like to try it out with theClickHouse SQL Playground, you can use the following config:
{ "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" } } } }
For chDB (embedded ClickHouse engine), add the following configuration:
{ "mcpServers": { "mcp-clickhouse": { "command": "uv", "args": [ "run", "--with", "mcp-clickhouse[chdb]", "--python", "3.10", "mcp-clickhouse" ], "env": { "CHDB_ENABLED": "true", "CLICKHOUSE_ENABLED": "false", "CHDB_DATA_PATH": "/path/to/chdb/data" } } } }
You can also enable both ClickHouse and chDB simultaneously:
{ "mcpServers": { "mcp-clickhouse": { "command": "uv", "args": [ "run", "--with", "mcp-clickhouse[chdb]", "--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" } } } }
-
Locate the command entry foruvand replace it with the absolute path to theuvexecutable. This ensures that the correct version ofuvis used when starting the server. On a mac, you can find this path usingwhich uv.
Restart Claude Desktop to apply the changes.
By default, this MCP enforces read-only queries so that accidental mutations cannot happen during exploration. To allow DDL or INSERT/UPDATE statements, set theCLICKHOUSE_ALLOW_WRITE_ACCESSenvironment variable totrue. The server keeps enforcing read-only mode if the ClickHouse instance itself disallows writes.
Even when write access is enabled (CLICKHOUSE_ALLOW_WRITE_ACCESS=true), destructive operations (DROP TABLE, DROP DATABASE, DROP VIEW, DROP DICTIONARY, TRUNCATE TABLE) require an additional opt-in flag for safety. This prevents accidental data deletion during AI exploration.
To enable destructive operations, set both flags:
"env": { "CLICKHOUSE_ALLOW_WRITE_ACCESS": "true", "CLICKHOUSE_ALLOW_DROP": "true" }
This two-tier approach ensures that accidental drops are very difficult:
- Write operations(INSERT, UPDATE, CREATE) requireCLICKHOUSE_ALLOW_WRITE_ACCESS=true
- Destructive operations(DROP, TRUNCATE) additionally requireCLICKHOUSE_ALLOW_DROP=true
Running Without Uv Using System Python
If you prefer to use the system Python installation instead of uv, you can install the package from PyPI and run it directly:
python3 -m pip install 'mcp-clickhouse[chdb]'
python3 -m pip install --upgrade mcp-clickhouse
Update your Claude Desktop configuration to use Python directly:
{ "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" } } } }
Note: Make sure to use the full path to the Python executable or themcp-clickhousescript if they are not in your system PATH. You can find the paths using:
- which python3for the Python executable
- which mcp-clickhousefor the installed script
You can add custom middleware to the MCP server without modifying the source code. FastMCP provides a middleware system that allows you to intercept and process MCP protocol messages (tool calls, resource reads, prompts, etc.).
- Create a Python module with middleware classes extendingMiddlewareand asetup_middleware(mcp)function:
# my_middleware.py import logging from fastmcp.server.middleware import Middleware, MiddlewareContext, CallNext logger = logging.getLogger("my-middleware") class LoggingMiddleware(Middleware): """Log all tool calls.""" async def on_call_tool(self, context: MiddlewareContext, call_next: CallNext): tool_name = context.message.name if hasattr(context.message, 'name') else 'unknown' logger.info(f"Calling tool: {tool_name}") result = await call_next(context) logger.info(f"Tool {tool_name} completed") return result def setup_middleware(mcp): """Register middleware with the MCP server.""" mcp.add_middleware(LoggingMiddleware())
- Set theMCP_MIDDLEWARE_MODULEenvironment variable to the module name (without.pyextension):
{ "mcpServers": { "mcp-clickhouse": { "command": "uv", "args": ["run", "--with", "mcp-clickhouse", "--python", "3.10", "mcp-clickhouse"], "env": { "CLICKHOUSE_HOST": "<clickhouse-host>", "CLICKHOUSE_USER": "<clickhouse-user>", "CLICKHOUSE_PASSWORD": "<clickhouse-password>", "MCP_MIDDLEWARE_MODULE": "my_middleware" } } } }
- Ensure your middleware module is in Python's import path (e.g., in the same directory where the MCP server runs, or installed as a package).
An example middleware module is provided inexample_middleware.pyshowing common patterns:
- Logging all MCP requests
- Logging tool calls specifically
- Measuring request processing time
"env": { "MCP_MIDDLEWARE_MODULE": "example_middleware" }
TheMiddlewarebase class provides hooks for different MCP operations:
- on_message(context, call_next)- Called for all messages
- on_request(context, call_next)- Called for all requests
- on_notification(context, call_next)- Called for all notifications
- on_call_tool(context, call_next)- Called when a tool is executed
- on_read_resource(context, call_next)- Called when a resource is read
- on_get_prompt(context, call_next)- Called when a prompt is retrieved
- on_list_tools(context, call_next)- Called when listing tools
- on_list_resources(context, call_next)- Called when listing resources
- on_list_resource_templates(context, call_next)- Called when listing resource templates
- on_list_prompts(context, call_next)- Called when listing prompts
Each hook receives aMiddlewareContextobject containing the message and metadata, and acall_nextfunction to continue the pipeline.
Dynamic Client Configuration Via Context State
Middleware can override ClickHouse client configuration on a per-request basis using theCLIENT_CONFIG_OVERRIDES_KEYcontext state key. The server merges these overrides with the base configuration from environment variables.
from fastmcp.server.dependencies import get_context from mcp_clickhouse.mcp_server import CLIENT_CONFIG_OVERRIDES_KEY ctx = get_context() ctx.set_state(CLIENT_CONFIG_OVERRIDES_KEY, { "connect_timeout": 60, "send_receive_timeout": 120 })
This enables advanced use cases like dynamic timeout adjustments, tenant-specific routing, or per-user connection settings.
-
Intest-servicesdirectory rundocker compose up -dto start the ClickHouse cluster.
Add the following variables to a.envfile in the root of the repository.
Note: The use of thedefaultuser in this context is intended solely for local development purposes.
CLICKHOUSE_HOST=localhost CLICKHOUSE_PORT=8123 CLICKHOUSE_USER=default CLICKHOUSE_PASSWORD=clickhouse
-
Runuv syncto install the dependencies. To installuvfollow the instructionshere. Then dosource .venv/bin/activate.
For easy testing with the MCP Inspector, runfastmcp dev mcp_clickhouse/mcp_server.pyto start the MCP server.
To test with HTTP transport and the health check endpoint:
# For development, disable authentication CLICKHOUSE_MCP_SERVER_TRANSPORT=http CLICKHOUSE_MCP_AUTH_DISABLED=true python -m mcp_clickhouse.main # Or with authentication (generate a token first) CLICKHOUSE_MCP_SERVER_TRANSPORT=http CLICKHOUSE_MCP_AUTH_TOKEN="your-token" python -m mcp_clickhouse.main # Then in another terminal: curl http://localhost:8000/health
run_query
Execute SQL queries on your ClickHouse cluster. Input: query (string): The SQL query to execute.
list_databases
List all databases on your ClickHouse cluster.
list_tables
List tables in a database with pagination. Required input: database (string). Optional inputs: like / not_like (string): Apply LIKE or NOT LIKE filters to table names, page_token (string): Token returned by a previous call for fetching the next page, page_size (int, default 50): Number of tables returned per page, include_detailed_columns (bool, default true): When false, omits column metadata for lighter responses while keeping the full create_table_query.
run_chdb_select_query
Execute SQL queries using chDB's embedded ClickHouse engine. Input: query (string): The SQL query to execute.
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"clickhouse": {
"env": {
"CLICKHOUSE_HOST": "<clickhouse-host>",
"CLICKHOUSE_PORT": "<clickhouse-port>",
"CLICKHOUSE_ROLE": "<clickhouse-role>",
"CLICKHOUSE_USER": "<clickhouse-user>",
"CLICKHOUSE_SECURE": "true",
"CLICKHOUSE_VERIFY": "true",
"CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"CLICKHOUSE_CONNECT_TIMEOUT": "30",
"CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
},
"args": [
"run",
"--with",
"mcp-clickhouse",
"--python",
"3.10",
"mcp-clickhouse"
],
"command": "uv"
}
}
}
Linux
{
"env": {
"CLICKHOUSE_HOST": "<clickhouse-host>",
"CLICKHOUSE_PORT": "<clickhouse-port>",
"CLICKHOUSE_ROLE": "<clickhouse-role>",
"CLICKHOUSE_USER": "<clickhouse-user>",
"CLICKHOUSE_SECURE": "true",
"CLICKHOUSE_VERIFY": "true",
"CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"CLICKHOUSE_CONNECT_TIMEOUT": "30",
"CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
},
"args": [
"run",
"--with",
"mcp-clickhouse",
"--python",
"3.10",
"mcp-clickhouse"
],
"command": "uv"
}
Macos
{
"env": {
"CLICKHOUSE_HOST": "<clickhouse-host>",
"CLICKHOUSE_PORT": "<clickhouse-port>",
"CLICKHOUSE_ROLE": "<clickhouse-role>",
"CLICKHOUSE_USER": "<clickhouse-user>",
"CLICKHOUSE_SECURE": "true",
"CLICKHOUSE_VERIFY": "true",
"CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"CLICKHOUSE_CONNECT_TIMEOUT": "30",
"CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
},
"args": [
"run",
"--with",
"mcp-clickhouse",
"--python",
"3.10",
"mcp-clickhouse"
],
"command": "uv"
}
Windows
{
"env": {
"CLICKHOUSE_HOST": "<clickhouse-host>",
"CLICKHOUSE_PORT": "<clickhouse-port>",
"CLICKHOUSE_ROLE": "<clickhouse-role>",
"CLICKHOUSE_USER": "<clickhouse-user>",
"CLICKHOUSE_SECURE": "true",
"CLICKHOUSE_VERIFY": "true",
"CLICKHOUSE_PASSWORD": "<clickhouse-password>",
"CLICKHOUSE_CONNECT_TIMEOUT": "30",
"CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
},
"args": [
"run",
"--with",
"mcp-clickhouse",
"--python",
"3.10",
"mcp-clickhouse"
],
"command": "uv"
}
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





