Skip to main content

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 response
  • sql_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?

  1. Check existing issues/discussions
  2. Open a feature request with use case details
  3. Consider contributing via pull request

Current Focus: Message history integration and model agnostic support.

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.2.1a1.tar.gz (11.6 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.2.1a1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

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

Hashes for clickhouse_mcp_agent-0.2.1a1.tar.gz
Algorithm Hash digest
SHA256 7d1dfda72737fc899e707ef7cb6e75668799b038a17f1ca406faed469886a765
MD5 c194340ef6242ae801b32c77c824c382
BLAKE2b-256 f6681f9f69fba62d56e9c1f2df342d9bd1b9635ffc7aef88aab5f8acb35aff40

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickhouse_mcp_agent-0.2.1a1.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.2.1a1-py3-none-any.whl.

File metadata

File hashes

Hashes for clickhouse_mcp_agent-0.2.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 20f99b2a0be61a69a85b7c0ee3265c77c9ee37cea35a77c35b9d9a0c4c5d3673
MD5 807e706efa5d13e217b3625f4118be5c
BLAKE2b-256 ce05af49e93a3a3c27dba73e2513fae9d9450839103ddd375f49453a2d5c1887

See more details on using hashes here.

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

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