Skip to main content

AI agent for ClickHouse database analysis via MCP

Project description

ClickHouse MCP Agent

version

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 queries
  • sql_used: SQL query that was executed
  • confidence: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clickhouse_mcp_agent-0.3.1a0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clickhouse_mcp_agent-0.3.1a0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

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

Hashes for clickhouse_mcp_agent-0.3.1a0.tar.gz
Algorithm Hash digest
SHA256 9e0970b2497bd94549de48f489ceccff5a49f49573dc2ca2d65a8a5f0ede0035
MD5 6bb36c8f7d646a374fa09362f921e479
BLAKE2b-256 2c2821e6daca647eb69080689221ecb912fbf0a83fa8f452b8b4cb462e912376

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickhouse_mcp_agent-0.3.1a0.tar.gz:

Publisher: publish-pypi.yml on AranNomante/clickhousemcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clickhouse_mcp_agent-0.3.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for clickhouse_mcp_agent-0.3.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 26de5b3e9600573a9d0034c5603650fcb90b6fc62077abaa7997a838cff55848
MD5 9b33050079abc551d867659400f4c6cf
BLAKE2b-256 212c4a5c40a697ed9b0e58734a294a599814ede86418664834eb1ff0b31ce2d3

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page