AI agent for ClickHouse database analysis via MCP
Project description
ClickHouse MCP Agent
A PydanticAI agent that integrates with ClickHouse databases using the Model Context Protocol (MCP).
Features
- MCP-based ClickHouse integration with secure database access
- Structured output with natural language analysis and SQL transparency
- Flexible connection management for different ClickHouse instances
- Built-in configurations for common scenarios
Usage
Basic Query
from agent import query_clickhouse
result = await query_clickhouse(
query="What are the top 5 GitHub repositories by stars?",
connection="playground",
model="gemini-2.0-flash",
api_key="your-google-api-key"
)
print(f"Analysis: {result.analysis}")
Custom Connection
from agent import ClickHouseConfig
config = ClickHouseConfig(
name="production",
host="clickhouse.company.com",
port="8443",
user="analyst",
password="secret"
)
result = await query_clickhouse(
query="SHOW TABLES",
connection=config,
model="gemini-2.0-flash",
api_key="your-google-api-key"
)
Current Usage (Library Import)
# When installed as a library: pip install clickhouse-mcp-agent
from agent import query_clickhouse, ClickHouseConfig
# Basic usage
result = await query_clickhouse(
query="SHOW DATABASES",
connection="playground",
model="gemini-2.0-flash",
api_key="your-google-api-key"
)
# RBAC with dynamic user credentials
user_config = ClickHouseConfig(
name="user_session",
host="clickhouse.company.com",
user="analyst_jane",
password="jane_specific_password"
)
result = await query_clickhouse(
query="SELECT * FROM user_logs",
connection=user_config,
model="gemini-2.0-flash",
api_key="your-google-api-key"
)
# Completely dynamic
result = await query_clickhouse(
query="SHOW TABLES",
connection=ClickHouseConfig(
name="runtime",
host="dynamic.clickhouse.com",
user="runtime_user",
password="runtime_pass"
),
model="gemini-2.0-flash",
api_key="your-google-api-key-here"
)
Environment Variables
The project automatically loads from .env file:
result = await query_clickhouse(
query="SELECT 1",
connection="env",
model="gemini-2.0-flash",
api_key="your-google-api-key"
)
Built-in Connections
playground: ClickHouse SQL playground (public demo data)local: Local instance (localhost:9000)env: From environment variables
CLI
./run.sh # Automated run script
# OR manually:
source .venv/bin/activate
clickhouse-mcp-demo # CLI command from pyproject.toml
python -m agent.main # Direct module execution
Output
Returns ClickHouseOutput with:
analysis: Natural language results with SQL queries mentioned in the responsesql_used: Optional SQL query that was executed (when available)confidence: Confidence level of the analysis (1-10 scale)
Requirements
- Python 3.10+
- AI API key (Google/Gemini) - can be set via environment variable, .env file, or passed directly to the function
All other dependencies (UV, MCP servers, etc.) are handled automatically by pyproject.toml.
Roadmap
✅ Completed Features
- MCP Integration: PydanticAI + ClickHouse MCP server integration
- Query Execution: SQL query execution via MCP tools
- Schema Inspection: Database, table, and column exploration
- Connection Management: Multiple connection configurations (playground, local, env)
- RBAC Support: Pass different user credentials dynamically via ClickHouseConfig
- Dynamic Connections: Runtime connection configuration without environment dependencies
- Direct API Key Passing: Pass AI API keys directly to functions (model_api_key parameter)
- Structured Output: ClickHouseOutput with analysis, SQL, and confidence
- CLI Interface: Command-line tool via clickhouse-mcp-demo
- Type Safety: Full mypy compliance with proper type annotations
- Code Quality: Black formatting, isort import organization, flake8 linting
🚧 Planned Features (Discussed)
Enhanced Conversation Support
- Message History: Add message_history parameter to query_clickhouse() for conversation continuity
- Conversational Agent: ConversationalClickHouseAgent class for persistent memory across queries
Model Support
- Model Agnostic Support: Support for different AI models beyond Gemini
Contributing
Have ideas for new features? Found something missing?
- Check existing issues/discussions
- Open a feature request with use case details
- Consider contributing via pull request
Current Focus: Message history integration and model agnostic support.
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 clickhouse_mcp_agent-0.2.1a1.tar.gz.
File metadata
- Download URL: clickhouse_mcp_agent-0.2.1a1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d1dfda72737fc899e707ef7cb6e75668799b038a17f1ca406faed469886a765
|
|
| MD5 |
c194340ef6242ae801b32c77c824c382
|
|
| BLAKE2b-256 |
f6681f9f69fba62d56e9c1f2df342d9bd1b9635ffc7aef88aab5f8acb35aff40
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.2.1a1.tar.gz:
Publisher:
publish-pypi.yml on AranNomante/clickhousemcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_mcp_agent-0.2.1a1.tar.gz -
Subject digest:
7d1dfda72737fc899e707ef7cb6e75668799b038a17f1ca406faed469886a765 - Sigstore transparency entry: 325105373
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@99fdfa1828ec9ec05df851a2bc5a18d3fb6f2409 -
Branch / Tag:
refs/tags/v0.2.1a1 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@99fdfa1828ec9ec05df851a2bc5a18d3fb6f2409 -
Trigger Event:
release
-
Statement type:
File details
Details for the file clickhouse_mcp_agent-0.2.1a1-py3-none-any.whl.
File metadata
- Download URL: clickhouse_mcp_agent-0.2.1a1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20f99b2a0be61a69a85b7c0ee3265c77c9ee37cea35a77c35b9d9a0c4c5d3673
|
|
| MD5 |
807e706efa5d13e217b3625f4118be5c
|
|
| BLAKE2b-256 |
ce05af49e93a3a3c27dba73e2513fae9d9450839103ddd375f49453a2d5c1887
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.2.1a1-py3-none-any.whl:
Publisher:
publish-pypi.yml on AranNomante/clickhousemcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_mcp_agent-0.2.1a1-py3-none-any.whl -
Subject digest:
20f99b2a0be61a69a85b7c0ee3265c77c9ee37cea35a77c35b9d9a0c4c5d3673 - Sigstore transparency entry: 325105413
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@99fdfa1828ec9ec05df851a2bc5a18d3fb6f2409 -
Branch / Tag:
refs/tags/v0.2.1a1 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@99fdfa1828ec9ec05df851a2bc5a18d3fb6f2409 -
Trigger Event:
release
-
Statement type: