A comprehensive Model Context Protocol (MCP) server for ClickHouse database operations and ClickHouse Cloud management.
Project description
MCP ClickHouse Cloud Server
A comprehensive Model Context Protocol (MCP) server for ClickHouse database operations and ClickHouse Cloud management.
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 for organizations, services, API keys, members, backups, and more
- 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
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)
- Organizations: List, get details, update settings, view metrics
- Services: Create, manage, start/stop, configure scaling, delete services
- API Keys: Create, list, update, delete API keys
- Members: Manage organization members and roles
- Invitations: Send and manage organization invitations
- Backups: List, configure, and manage service backups
- ClickPipes: Manage data ingestion pipelines (Beta)
- Activities: View audit logs and organization activities
- Usage & Costs: Get detailed usage and cost analytics
- Private Endpoints: Configure private network access
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": {
"mcp-clickhouse-cloud": {
"command": "uv",
"args": [
"run",
"--with",
"mcp-clickhouse-cloud",
"--python",
"3.13",
"mcp-clickhouse-cloud"
],
"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": {
"mcp-clickhouse-cloud": {
"command": "uv",
"args": [
"run",
"--with",
"mcp-clickhouse-cloud",
"--python",
"3.13",
"mcp-clickhouse-cloud"
],
"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 mcp-clickhouse-cloud
Option 2: Manual Installation
# Clone the repository
git clone
cd mcp-clickhouse-cloud
# 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
cloud_list_organizations()- List available organizationscloud_get_organization(organization_id)- Get organization detailscloud_update_organization(organization_id, name?)- Update organizationcloud_get_organization_metrics(organization_id, filtered_metrics?)- Get Prometheus metrics
Service Management
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 servicecloud_update_service_state(organization_id, service_id, command)- Start/stop servicecloud_update_service_scaling(organization_id, service_id, ...)- Configure auto-scalingcloud_update_service_password(organization_id, service_id, ...)- Update passwordcloud_delete_service(organization_id, service_id)- Delete servicecloud_get_service_metrics(organization_id, service_id, ...)- Get service metrics
API Key Management
cloud_list_api_keys(organization_id)- List API keyscloud_create_api_key(organization_id, name, roles, ...)- Create API keycloud_delete_api_key(organization_id, key_id)- Delete API key
Member Management
cloud_list_members(organization_id)- List organization memberscloud_update_member_role(organization_id, user_id, role)- Update member rolecloud_remove_member(organization_id, user_id)- Remove member
Invitation Management
cloud_list_invitations(organization_id)- List pending invitationscloud_create_invitation(organization_id, email, role)- Send invitationcloud_delete_invitation(organization_id, invitation_id)- Cancel invitation
Backup Management
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 (Beta)
cloud_list_clickpipes(organization_id, service_id)- List ClickPipescloud_get_clickpipe(organization_id, service_id, clickpipe_id)- Get ClickPipe detailscloud_update_clickpipe_state(organization_id, service_id, clickpipe_id, command)- Start/stop ClickPipecloud_delete_clickpipe(organization_id, service_id, clickpipe_id)- Delete ClickPipe
Activity & Audit Logs
cloud_list_activities(organization_id, from_date?, to_date?)- Get activity logscloud_get_activity(organization_id, activity_id)- Get activity details
Usage & Cost Analytics
cloud_get_usage_cost(organization_id, from_date, to_date)- Get cost breakdown
Utilities
cloud_get_available_regions()- Get supported cloud regions and providerscloud_get_private_endpoint_config(organization_id, service_id)- Get private endpoint config
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 mcp_clickhouse_cloud/mcp_server.py # Start for testing # OR python -m mcp_clickhouse_cloud.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
mcp_clickhouse_cloud/
├── __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
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 mcp_clickhouse_cloud-0.1.1.tar.gz.
File metadata
- Download URL: mcp_clickhouse_cloud-0.1.1.tar.gz
- Upload date:
- Size: 73.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3de798ba65ac3c939b69eecf885c802ef47537f0ab51c62a4de92393e7f1512e
|
|
| MD5 |
27962b896d184a9a75f0c184d59fedbe
|
|
| BLAKE2b-256 |
859189d151ca0042af34d00d51909b87c0966ec9f7c91d6803e4dc7c9fb4b7da
|
File details
Details for the file mcp_clickhouse_cloud-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mcp_clickhouse_cloud-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.0 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 |
8fe7b345c49e7365f8cd2fdcb285375ff82468850f04b0587acb3951c3fe28c5
|
|
| MD5 |
b238d9ba484ffccf7fbc717bb15e1609
|
|
| BLAKE2b-256 |
2561340c632eae745d41b81eeed2674f5f65e51612575ed028e82c7094f08569
|