AI agent for ClickHouse database analysis via MCP
Project description
ClickHouse MCP Agent
AI agent for ClickHouse database analysis via MCP (Model Context Protocol).
Features
- Query ClickHouse databases using AI models
- Structured output: analysis, SQL used, confidence
- Easy connection management (predefined or custom)
- No CLI or environment setup required
Usage
Basic Example
import asyncio
from agent.clickhouse_agent import ClickHouseAgent
from agent.config import config
# Set up model and logging (optional)
config.set_ai_model("gemini-2.0-flash")
config.set_log_level("INFO")
# Set connection defaults (optional)
config.set_clickhouse(host="sql-clickhouse.clickhouse.com", user="demo")
# The 'query' parameter is a natural language request from the user. The agent will analyze it and generate the appropriate SQL for ClickHouse.
async def run_query():
agent = ClickHouseAgent()
result = await agent.run(
model_api_key="your_api_key_here",
model=config.ai_model,
query="Show all databases available to the demo user"
# Uses config defaults for connection
)
print("Analysis:", result.analysis)
print("SQL Used:", result.sql_used)
print("Confidence:", result.confidence)
asyncio.run(run_query())
Custom Connection Example
from agent.clickhouse_agent import ClickHouseAgent
from agent.config import ClickHouseConnections
ch_config = ClickHouseConnections.get_config("playground")
agent = ClickHouseAgent()
result = await agent.run(
model_api_key="your_api_key_here",
model="gemini-2.0-flash",
query="List all tables in the default database",
host=ch_config.host,
port=ch_config.port,
user=ch_config.user,
password=ch_config.password,
secure=ch_config.secure,
)
print("Analysis:", result.analysis)
Output
Returns a ClickHouseOutput object:
analysis: Natural language results with SQL queriessql_used: SQL query that was executedconfidence: Confidence level (1-10)
Requirements
- Python 3.10+
- AI API key (Google/Gemini)
All dependencies are handled by pyproject.toml.
Roadmap
✅ Completed Features
- MCP Integration: PydanticAI + ClickHouse MCP server integration
- Query Execution: SQL query generation and execution via MCP
- Schema Inspection: Database, table, and column exploration
- Connection Management: Multiple connection configurations (playground, custom)
- RBAC Support: Per-query user credentials via config
- Dynamic Connections: Runtime connection configuration, no environment dependencies
- Direct API Key Passing: Pass AI API keys directly to agent (model_api_key)
- Structured Output: ClickHouseOutput with analysis, SQL, and confidence
- Type Safety: Full type annotations and mypy compliance
- Code Quality: Black formatting, isort, flake8 linting
🚧 Planned / In Progress
- Message History: Add message_history parameter for conversational context
- Conversational Agent: Persistent memory across queries
- Model Agnostic Support: Support for additional AI models
- Improved Error Handling: More robust error and exception management
- Advanced Output Formatting: Customizable output for downstream applications
Contributing
Open an issue or pull request for features or fixes.
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.3.1a0.tar.gz.
File metadata
- Download URL: clickhouse_mcp_agent-0.3.1a0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e0970b2497bd94549de48f489ceccff5a49f49573dc2ca2d65a8a5f0ede0035
|
|
| MD5 |
6bb36c8f7d646a374fa09362f921e479
|
|
| BLAKE2b-256 |
2c2821e6daca647eb69080689221ecb912fbf0a83fa8f452b8b4cb462e912376
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.3.1a0.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.3.1a0.tar.gz -
Subject digest:
9e0970b2497bd94549de48f489ceccff5a49f49573dc2ca2d65a8a5f0ede0035 - Sigstore transparency entry: 330533658
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@7413a598357eb55c4911ff0cf56e4eed8c9f348e -
Branch / Tag:
refs/tags/v0.3.1a0 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7413a598357eb55c4911ff0cf56e4eed8c9f348e -
Trigger Event:
release
-
Statement type:
File details
Details for the file clickhouse_mcp_agent-0.3.1a0-py3-none-any.whl.
File metadata
- Download URL: clickhouse_mcp_agent-0.3.1a0-py3-none-any.whl
- Upload date:
- Size: 8.4 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 |
26de5b3e9600573a9d0034c5603650fcb90b6fc62077abaa7997a838cff55848
|
|
| MD5 |
9b33050079abc551d867659400f4c6cf
|
|
| BLAKE2b-256 |
212c4a5c40a697ed9b0e58734a294a599814ede86418664834eb1ff0b31ce2d3
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.3.1a0-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.3.1a0-py3-none-any.whl -
Subject digest:
26de5b3e9600573a9d0034c5603650fcb90b6fc62077abaa7997a838cff55848 - Sigstore transparency entry: 330533683
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@7413a598357eb55c4911ff0cf56e4eed8c9f348e -
Branch / Tag:
refs/tags/v0.3.1a0 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7413a598357eb55c4911ff0cf56e4eed8c9f348e -
Trigger Event:
release
-
Statement type: