clickhouse_mcp_server
A MCP server for ClickHouse
claude mcp add --transport stdio thomaub-clickhouse_mcp_server python clickhouse_mcp_server/server.py \ --env LOG_LEVEL="optional: e.g., INFO, DEBUG" \ --env CLICKHOUSE_HOST="host where ClickHouse is running" \ --env CLICKHOUSE_PORT="port of ClickHouse server (default 9000 for native protocol or 8123 for HTTP)" \ --env CLICKHOUSE_USER="username for ClickHouse connection" \ --env CLICKHOUSE_DATABASE="default database to connect to" \ --env CLICKHOUSE_PASSWORD="password for ClickHouse connection"
How to use
This MCP server exposes ClickHouse databases and tables as resources that can be discovered, inspected, and queried by clients using the MCP protocol. It can list available ClickHouse databases and tables, retrieve table schemas, and execute SELECT queries against the ClickHouse instance. To use it, start the server with Python and ensure the ClickHouse connection details are provided via environment variables or by editing the get_clickhouse_client function in server.py. Once running, clients can query for resources like databases, tables, and schemas, and send SELECT statements to retrieve data from ClickHouse through the MCP interface. The server handles the MCP messaging, resource discovery, and safe query execution, enabling seamless integration with LLMs and other AI tools.
How to install
Prerequisites:
- Python 3.10+
- Access to a running ClickHouse server
- Git
Installation steps:
-
Clone the repository: git clone https://github.com/ThomAub/clickhouse_mcp_server.git cd clickhouse_mcp_server
-
Install dependencies (via uv, as per project instructions): uv sync --all-extras
-
Configure ClickHouse connection:
- Set environment variables as described in the mcp_config (or edit server.py to customize the connection).
- Example (bash): export CLICKHOUSE_HOST=localhost export CLICKHOUSE_PORT=9000 export CLICKHOUSE_USER=default export CLICKHOUSE_PASSWORD= export CLICKHOUSE_DATABASE=default
-
Run the server: python clickhouse_mcp_server/server.py
-
(Optional) Run tests: pytest tests/
Additional notes
Tips and notes:
- Ensure the ClickHouse server is reachable from the MCP server host and that the credentials have access to the target databases.
- If you change the ClickHouse connection details, restart the MCP server to apply the new configuration.
- The MCP server supports listing databases and tables, retrieving table schemas, and executing SELECT queries. Use MCP-compatible clients to interact with these capabilities.
- If you encounter authentication or network issues, verify firewall rules and that the ClickHouse user has the necessary privileges.
- You can customize logging via the LOG_LEVEL environment variable for easier debugging (e.g., DEBUG, INFO, WARN).
- For production, consider setting up proper TLS/HTTPS and securing MCP communications as needed by your deployment environment.
Related MCP Servers
mcp-vegalite
MCP server from isaacwasserman/mcp-vegalite-server
github-chat
A Model Context Protocol (MCP) for analyzing and querying GitHub repositories using the GitHub Chat API.
nautex
MCP server for guiding Coding Agents via end-to-end requirements to implementation plan pipeline
pagerduty
PagerDuty's official local MCP (Model Context Protocol) server which provides tools to interact with your PagerDuty account directly from your MCP-enabled client.
futu-stock
mcp server for futuniuniu stock
mcp -boilerplate
Boilerplate using one of the 'better' ways to build MCP Servers. Written using FastMCP