A comprehensive Model Context Protocol (MCP) server for ClickHouse database operations and ClickHouse Cloud management.
Project description
MCP ClickHouse Cloud & On-Prem Server
A comprehensive Model Context Protocol (MCP) server for ClickHouse database operations and ClickHouse Cloud management.
๐ Quick Start
Start with our step-by-step tutorial:
๐ Complete Setup Tutorial - Transform Claude into a powerful ClickHouse data agent
For experienced users, jump to the Quick Configuration section below.
๐ Table of Contents
- ๐ Quick Start
- ๐ Table of Contents
- ๐ Why This Server?
- โจ Features
- โก Quick Configuration
- ๐ฆ Installation
- โ๏ธ Environment Variables
- ๐ ๏ธ Available Tools
- ๐ก Examples
- ๐ง Development
- ๐ Project Structure
- ๐ How MCP Tool Discovery Works
- ๐ Getting ClickHouse Cloud API Keys
- ๐ Troubleshooting
- ๐ License
Why This Server?
This repository is a significant improvement over the original ClickHouse MCP server. While the original server only supports basic database operations (list databases, run SELECT queries, and list tables), this enhanced version provides:
- 50+ Cloud Management Tools: Complete ClickHouse Cloud API integration covering 100% of the official API
- Superior Code Quality: Well-structured, maintainable codebase with proper error handling and type hints
- Enhanced Database Operations: Extended functionality with metadata access and safety guarantees
- Production Ready: Comprehensive configuration options, SSL support, and robust error handling
| Feature | Original Server | This Server |
|---|---|---|
| Database Operations | 3 basic tools | 3 enhanced tools with safety |
| Cloud Management | โ None | โ 50+ comprehensive tools (100% API coverage) |
| Code Quality | Basic | Production-ready with proper structure |
| SSL Support | Limited | Full SSL configuration options |
| Error Handling | Basic | Robust with detailed error messages |
Features
Database Operations
- List databases: Get all available databases
- List tables: Get detailed table information including schema, row counts, and column details
- Run SELECT queries: Execute read-only queries with timeout protection and safety guarantees
- Metadata access: Full access to ClickHouse system tables
ClickHouse Cloud Management (50+ Tools)
Complete coverage of the ClickHouse Cloud API including:
- Organizations: List, get details, update settings, view metrics, manage private endpoints
- Services: Create, manage, start/stop, configure scaling, update passwords, delete services
- API Keys: Create, list, get details, update, delete API keys
- Members: Manage organization members and roles, get member details
- Invitations: Send, list, get details, and manage organization invitations
- Backups: List, get details, configure, and manage service backups
- ClickPipes: Complete management of data ingestion pipelines (Beta)
- Reverse Private Endpoints: Manage reverse private endpoints (Beta)
- Query Endpoints: Configure query endpoints (Experimental)
- Activities: View audit logs and organization activities with filtering
- Usage & Costs: Get detailed usage and cost analytics
- Private Endpoints: Configure private network access and endpoint services
- Service Scaling: Both legacy and modern replica-based scaling methods
Configuration
Claude Desktop Setup
-
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
- On macOS:
-
Add the following configuration:
For Your Own ClickHouse Server
{
"mcpServers": {
"chmcp": {
"command": "uv",
"args": [
"run",
"--with",
"chmcp",
"--python",
"3.13",
"chmcp"
],
"env": {
"CLICKHOUSE_HOST": "",
"CLICKHOUSE_PORT": "",
"CLICKHOUSE_USER": "",
"CLICKHOUSE_PASSWORD": "",
"CLICKHOUSE_SECURE": "true",
"CLICKHOUSE_VERIFY": "true",
"CLICKHOUSE_CONNECT_TIMEOUT": "30",
"CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "300"
}
}
}
}
For ClickHouse SQL Playground (Free Testing)
{
"mcpServers": {
"chmcp": {
"command": "uv",
"args": [
"run",
"--with",
"chmcp",
"--python",
"3.13",
"chmcp"
],
"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": "300"
}
}
}
}
-
Important: Locate the command entry for
uvand replace it with the absolute path to theuvexecutable. On macOS, find this path usingwhich uv. -
Restart Claude Desktop to apply the changes.
Installation
Option 1: Using uv (Recommended)
# Install via uv (used by Claude Desktop)
uv add chmcp
Option 2: Manual Installation
# Clone the repository
git clone
cd chmcp
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration
Environment Variables
Database Configuration (Required for database tools)
Required Variables
CLICKHOUSE_HOST=your-clickhouse-host.com # ClickHouse server hostname
CLICKHOUSE_USER=your-username # Username for authentication
CLICKHOUSE_PASSWORD=your-password # Password for authentication
[!CAUTION] Treat your MCP database user as you would any external client connecting to your database. Grant only the minimum necessary privileges required for operation. Avoid using default or administrative users.
Optional Variables (with defaults)
CLICKHOUSE_PORT=8443 # 8443 for secure, 8123 for non-secure
CLICKHOUSE_SECURE=true # Enable HTTPS connection
CLICKHOUSE_VERIFY=true # Verify SSL certificates
CLICKHOUSE_CONNECT_TIMEOUT=30 # Connection timeout in seconds
CLICKHOUSE_SEND_RECEIVE_TIMEOUT=300 # Query timeout in seconds
CLICKHOUSE_DATABASE=default # Default database to use
CLICKHOUSE_PROXY_PATH= # Path for HTTP proxy
SSL Configuration Issues
If you encounter SSL certificate verification issues, you can disable SSL verification:
CLICKHOUSE_VERIFY=false # Disable SSL certificate verification
Cloud API Configuration (Required for cloud tools)
# Required - Get these from ClickHouse Cloud Console
CLICKHOUSE_CLOUD_KEY_ID=your-cloud-key-id
CLICKHOUSE_CLOUD_KEY_SECRET=your-cloud-key-secret
# Optional
CLICKHOUSE_CLOUD_API_URL=https://api.clickhouse.cloud
CLICKHOUSE_CLOUD_TIMEOUT=30
CLICKHOUSE_CLOUD_SSL_VERIFY=true # Set to "false" for SSL issues
Cloud API SSL Configuration Issues
If you encounter SSL certificate verification issues with the Cloud API:
CLICKHOUSE_CLOUD_SSL_VERIFY=false # Disable SSL certificate verification for Cloud API
Example Configurations
Local Development with Docker
CLICKHOUSE_HOST=localhost
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=clickhouse
CLICKHOUSE_SECURE=false # Uses port 8123 automatically
CLICKHOUSE_VERIFY=false
ClickHouse Cloud
CLICKHOUSE_HOST=your-instance.clickhouse.cloud
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=your-password
# CLICKHOUSE_SECURE=true # Uses port 8443 automatically
# CLICKHOUSE_DATABASE=your_database
ClickHouse SQL Playground
CLICKHOUSE_HOST=sql-clickhouse.clickhouse.com
CLICKHOUSE_USER=demo
CLICKHOUSE_PASSWORD=
# Uses secure defaults (HTTPS on port 8443)
Available Tools
Database Tools (3 tools)
list_databases()- List all databaseslist_tables(database, like?, not_like?)- List tables with metadatarun_select_query(query)- Execute SELECT queries (all queries run withreadonly = 1for safety)
Cloud Tools (50+ tools)
Organization Management (5 tools)
cloud_list_organizations()- List available organizationscloud_get_organization(organization_id)- Get organization detailscloud_update_organization(organization_id, name?, private_endpoints?)- Update organizationcloud_get_organization_metrics(organization_id, filtered_metrics?)- Get Prometheus metricscloud_get_organization_private_endpoint_info(organization_id, cloud_provider, region)- Get private endpoint info
Service Management (12 tools)
cloud_list_services(organization_id)- List all servicescloud_get_service(organization_id, service_id)- Get service detailscloud_create_service(organization_id, name, provider, region, ...)- Create new service (with all options)cloud_update_service(organization_id, service_id, ...)- Update service detailscloud_update_service_state(organization_id, service_id, command)- Start/stop servicecloud_update_service_scaling(organization_id, service_id, ...)- Configure auto-scaling (legacy)cloud_update_service_replica_scaling(organization_id, service_id, ...)- Configure replica scaling (preferred)cloud_update_service_password(organization_id, service_id, ...)- Update service passwordcloud_create_service_private_endpoint(organization_id, service_id, id, description)- Create private endpointcloud_get_service_metrics(organization_id, service_id, filtered_metrics?)- Get service metricscloud_delete_service(organization_id, service_id)- Delete service
Query Endpoints (3 tools - Experimental)
cloud_get_query_endpoint_config(organization_id, service_id)- Get query endpoint configcloud_create_query_endpoint_config(organization_id, service_id, roles, open_api_keys, allowed_origins)- Create configcloud_delete_query_endpoint_config(organization_id, service_id)- Delete config
API Key Management (5 tools)
cloud_list_api_keys(organization_id)- List API keyscloud_create_api_key(organization_id, name, roles, ...)- Create API keycloud_get_api_key(organization_id, key_id)- Get API key detailscloud_update_api_key(organization_id, key_id, ...)- Update API keycloud_delete_api_key(organization_id, key_id)- Delete API key
Member Management (4 tools)
cloud_list_members(organization_id)- List organization memberscloud_get_member(organization_id, user_id)- Get member detailscloud_update_member_role(organization_id, user_id, role)- Update member rolecloud_remove_member(organization_id, user_id)- Remove member
Invitation Management (4 tools)
cloud_list_invitations(organization_id)- List pending invitationscloud_create_invitation(organization_id, email, role)- Send invitationcloud_get_invitation(organization_id, invitation_id)- Get invitation detailscloud_delete_invitation(organization_id, invitation_id)- Cancel invitation
Backup Management (3 tools)
cloud_list_backups(organization_id, service_id)- List service backupscloud_get_backup(organization_id, service_id, backup_id)- Get backup detailscloud_get_backup_configuration(organization_id, service_id)- Get backup configcloud_update_backup_configuration(organization_id, service_id, ...)- Update backup settings
ClickPipes Management (7 tools - Beta)
cloud_list_clickpipes(organization_id, service_id)- List ClickPipescloud_create_clickpipe(organization_id, service_id, name, description, source, destination, field_mappings?)- Create ClickPipecloud_get_clickpipe(organization_id, service_id, clickpipe_id)- Get ClickPipe detailscloud_update_clickpipe(organization_id, service_id, clickpipe_id, ...)- Update ClickPipecloud_update_clickpipe_scaling(organization_id, service_id, clickpipe_id, replicas?)- Update scalingcloud_update_clickpipe_state(organization_id, service_id, clickpipe_id, command)- Start/stop/resync ClickPipecloud_delete_clickpipe(organization_id, service_id, clickpipe_id)- Delete ClickPipe
Reverse Private Endpoints (4 tools - Beta)
cloud_list_reverse_private_endpoints(organization_id, service_id)- List reverse private endpointscloud_create_reverse_private_endpoint(organization_id, service_id, description, type, ...)- Create endpointcloud_get_reverse_private_endpoint(organization_id, service_id, reverse_private_endpoint_id)- Get endpoint detailscloud_delete_reverse_private_endpoint(organization_id, service_id, reverse_private_endpoint_id)- Delete endpoint
Activity & Audit Logs (2 tools)
cloud_list_activities(organization_id, from_date?, to_date?)- Get activity logscloud_get_activity(organization_id, activity_id)- Get activity details
Usage & Cost Analytics (1 tool)
cloud_get_usage_cost(organization_id, from_date, to_date)- Get cost breakdown
Private Endpoints (1 tool)
cloud_get_private_endpoint_config(organization_id, service_id)- Get private endpoint config
Utilities (1 tool)
cloud_get_available_regions()- Get supported cloud regions and providers
Examples
Query Database
# List all databases
databases = list_databases()
# List tables in a specific database
tables = list_tables("my_database")
# Run a SELECT query
result = run_select_query("SELECT count() FROM my_table")
Manage Cloud Services
# List organizations
orgs = cloud_list_organizations()
# Create a new service with full configuration
service = cloud_create_service(
organization_id="org-123",
name="my-service",
provider="aws",
region="us-east-1",
tier="production",
min_replica_memory_gb=16,
max_replica_memory_gb=120,
num_replicas=3,
idle_scaling=True,
ip_access_list=[{"source": "0.0.0.0/0", "description": "Allow all"}]
)
# Start the service
cloud_update_service_state(
organization_id="org-123",
service_id="service-456",
command="start"
)
# Update service scaling
cloud_update_service_replica_scaling(
organization_id="org-123",
service_id="service-456",
min_replica_memory_gb=24,
max_replica_memory_gb=240,
num_replicas=5
)
Manage ClickPipes
# Create a Kafka ClickPipe
clickpipe = cloud_create_clickpipe(
organization_id="org-123",
service_id="service-456",
name="kafka-ingestion",
description="Ingest data from Kafka",
source={
"kafka": {
"type": "kafka",
"format": "JSONEachRow",
"brokers": "broker1:9092,broker2:9092",
"topics": "my-topic",
"authentication": "PLAIN"
}
},
destination={
"database": "default",
"table": "kafka_data",
"managedTable": True
}
)
# Start the ClickPipe
cloud_update_clickpipe_state(
organization_id="org-123",
service_id="service-456",
clickpipe_id=clickpipe["data"]["id"],
command="start"
)
Development
Local Development Setup
-
Start ClickHouse cluster:
cd test-services docker compose up -d
-
Create environment file:
# Create .env file in repository root cat > .env << EOF CLICKHOUSE_HOST=localhost CLICKHOUSE_PORT=8123 CLICKHOUSE_USER=default CLICKHOUSE_PASSWORD=clickhouse CLICKHOUSE_SECURE=false EOF
-
Install dependencies:
uv sync # Install dependencies source .venv/bin/activate # Activate virtual environment
-
Run the MCP server:
mcp dev chmcp/mcp_server.py # Start for testing # OR python -m chmcp.main # Start normally
Running Tests
uv sync --all-extras --dev # Install dev dependencies
uv run ruff check . # Run linting
docker compose up -d test_services # Start ClickHouse
uv run pytest tests # Run tests
Project Structure
chmcp/
โโโ __init__.py # Package initialization
โโโ main.py # Entry point
โโโ mcp_env.py # Database environment configuration
โโโ mcp_server.py # Main server + database tools
โโโ cloud_config.py # Cloud API configuration
โโโ cloud_client.py # HTTP client for Cloud API
โโโ cloud_tools.py # Cloud MCP tools (50+ tools)
How MCP Tool Discovery Works
- Decorator Registration: All tools use the
@mcp.tool()decorator - Import-based Discovery: When modules are imported, FastMCP automatically scans for decorated functions
- Automatic Registration: All discovered tools become available through the MCP protocol
- No Manual Setup: No need to manually register tools or maintain tool lists
Getting ClickHouse Cloud API Keys
- Log into ClickHouse Cloud Console
- Go to Settings โ API Keys
- Click Create API Key
- Choose appropriate permissions (admin, developer, etc.)
- Copy the Key ID and Key Secret to your
.envfile
Examples
Query Database
# List all databases
databases = list_databases()
# List tables in a specific database
tables = list_tables("my_database")
# Run a SELECT query
result = run_select_query("SELECT count() FROM my_table")
Manage Cloud Services
# List organizations
orgs = cloud_list_organizations()
# Create a new service
service = cloud_create_service(
organization_id="org-123",
name="my-service",
provider="aws",
region="us-east-1"
)
# Start the service
cloud_update_service_state(
organization_id="org-123",
service_id="service-456",
command="start"
)
Troubleshooting
Database Connection Issues
- Verify
CLICKHOUSE_HOST,CLICKHOUSE_USER, andCLICKHOUSE_PASSWORD - Check network connectivity to ClickHouse server
- Ensure firewall allows connections on the specified port
- For SSL issues, try setting
CLICKHOUSE_VERIFY=false
Cloud API Issues
- Verify
CLICKHOUSE_CLOUD_KEY_IDandCLICKHOUSE_CLOUD_KEY_SECRET - Check API key permissions in ClickHouse Cloud Console
- Ensure API key is not expired or disabled
- For SSL issues, try setting
CLICKHOUSE_CLOUD_SSL_VERIFY=false
Missing Tools
- Database tools require database configuration
- Cloud tools require cloud API configuration
- Check logs for import errors or missing dependencies
API Coverage
This implementation provides 100% coverage of the ClickHouse Cloud API as documented in the official API specification. All endpoints are implemented including:
- โ Organizations - Complete management
- โ Services - Full lifecycle management with all options
- โ API Keys - Complete CRUD operations
- โ Members & Invitations - Full user management
- โ Backups - Configuration and management
- โ ClickPipes - Complete pipeline management (Beta)
- โ Reverse Private Endpoints - Full endpoint management (Beta)
- โ Query Endpoints - Configuration management (Experimental)
- โ Activities & Audit Logs - Complete audit trail access
- โ Usage & Cost Analytics - Detailed cost reporting
- โ Private Endpoints - Network configuration
- โ Utilities - Region and provider information
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Developed by Badr Ouali.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chmcp-0.1.0.tar.gz.
File metadata
- Download URL: chmcp-0.1.0.tar.gz
- Upload date:
- Size: 3.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de9b3ce9e4718ab2c959f3b9da3f22895533b775f4f6cfde4a67da7fcf3c4a16
|
|
| MD5 |
c6202a1e7cb3364dea5d9bbfa35c587c
|
|
| BLAKE2b-256 |
c58e223b18cf5e6a0943db48737811c8811ab7c1462fea091fb4bd459a384d3a
|
File details
Details for the file chmcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chmcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ec0056c94750e78e039ff89641adc0efaed90ef26dab7a0020b6e8f3cc2b0bb
|
|
| MD5 |
6b00bd5011a821fb71e32c27e6bf5b5f
|
|
| BLAKE2b-256 |
f9b5502526f821beb3dc2f0b08c38f4bb22f209d10aa269064085bae7c22310a
|