AI agent for ClickHouse database analysis via MCP
Project description
ClickHouse MCP Agent
AI agent for ClickHouse database analysis via MCP (Model Context Protocol).
This release reflects a simplified architecture: a single MCP server
(mcp-clickhouse) driven by a single agent instance. Access restriction is
performed via explicit allow-lists you pass per call (databases/tables), rather
than managing multiple keys or fan-out across multiple agents.
Features
- Query ClickHouse databases using AI models
- Structured output: analysis, confidence
- Easy connection management (predefined or custom)
- Conversational context with message-history pruning/summarization
- No CLI or external .env required; configure at runtime
- Single MCP server, single agent lifecycle (no multi-key fan-out)
- Access restriction via per-call allow-lists (
allowed_tables) - Streamable results
Supported Providers
- OpenAI
- Anthropic
- Google Gemini
- Groq
- Mistral
- Cohere
Local Development (Docker)
The fastest way to get started — no cloud ClickHouse account needed:
# Start ClickHouse with seeded demo data (orders + products)
docker compose up -d
# Install the package with dev dependencies
pip install -e ".[dev]"
# Run the examples (set your API key first)
OPENAI_API_KEY=sk-... python examples/example_minimal.py
OPENAI_API_KEY=sk-... python examples/example_stream.py
The docker/init.sql file seeds demo.orders (25 orders, May 2026) and demo.products (10 products across Electronics, Sports, Home, Books) automatically on first start.
Quickstart
- Set model/provider and API key using the runtime config
- Instantiate
ClickHouseAgentand callrun()orrun_stream()
import asyncio
from agent.clickhouse_agent import ClickHouseAgent
from agent.config import config
config.set_ai_model("openai:gpt-4o-mini")
config.set_model_api_key("openai", "your_api_key_here")
config.set_clickhouse(host="localhost", port="8123", user="default", password="", secure="false")
async def main():
agent = ClickHouseAgent()
result = await agent.run(
allowed_tables=["orders", "products"],
query="give me some insights on the recent data",
)
print("Analysis:", result.analysis)
print("Confidence:", result.confidence)
asyncio.run(main())
Switching providers
All providers use the same interface — just swap the model string and key:
# Anthropic
config.set_ai_model("anthropic:claude-haiku-4-5-20251001")
config.set_model_api_key("anthropic", "your_key")
# Google
config.set_ai_model("google-gla:gemini-2.0-flash")
config.set_model_api_key("google", "your_key")
# Groq
config.set_ai_model("groq:llama-3.3-70b-versatile")
config.set_model_api_key("groq", "your_key")
- For multi-turn conversations, pass
message_historybetween calls. If token usage grows, the agent can summarize history (see below).
Message History & Summarization
- History processing is handled in
agent/history_processor.py. - Summarization behavior is controlled via
agent.config.summarize_config(model, provider, token limit). - When token usage exceeds the configured limit, older messages are summarized into a compact form.
Output
Each call to ClickHouseAgent.run() returns a RunResult with:
messages: Full (possibly pruned/summarized) message history.new_messages: Only messages created in the latest turn.last_message: The last message in the conversation.usage: Token/usage statistics for the run.analysis: Natural-language result text from the model.confidence: Confidence level (1-10).
Requirements
- Python 3.10+
- AI API key for your provider (OpenAI, Anthropic, Google/Gemini, Groq, Mistral, Cohere)
All dependencies are managed via pyproject.toml.
Roadmap
✅ Done
- MCP integration via
pydantic_ai.mcp.MCPServerStdio - SQL generation/execution via MCP tools
- Schema inspection (databases/tables/columns)
- Config-driven connections (playground/local/custom)
- Access restriction via per-call allow-lists (
allowed_tables) - Runtime provider/model selection and API key management
- Structured outputs (
ClickHouseOutput) andRunResult - Message history pruning/summarization
- Streaming results via
run_stream() - Local development via Docker (
docker compose up -d) rufflinting, Python 3.13 support, CI hardened
🔨 0.10 — Production hardening
- Custom exception types (
MCPConnectionError,AgentExecutionError) sql_usedextraction from tool call resultsallowed_databasesparameter alongsideallowed_tablesasync with ClickHouseAgent()context manager- Persistent MCP server across multiple
run()calls - Integration tests: allow-list, streaming, summarization, error paths
⚙️ 0.11 — Agent API expansion
- Async batch queries (parallel queries in one call)
ClickHouseAgent.reset()for lifecycle controlstructlogoptional dep for structured observabilitypydantic-aiAPI audit and model ref updates
🔒 0.12 — Stable
- API locked — no breaking changes without a major version
- All known bugs resolved
🔭 Post-1.0 — Future
- Database-agnostic abstraction (Elasticsearch, MongoDB, Postgres)
- FastAPI standalone deployment option
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.9.0.tar.gz.
File metadata
- Download URL: clickhouse_mcp_agent-0.9.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbb7c1cfca908c357e73564cab386e89ca2987b69786d26daef44a0e660a2dc8
|
|
| MD5 |
1d913d86a8cb91e2d7d234a09902446f
|
|
| BLAKE2b-256 |
8e162eca050573de23f37d771617b9e6afb2b50e176f2a5b7c19506018dd75a4
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.9.0.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.9.0.tar.gz -
Subject digest:
bbb7c1cfca908c357e73564cab386e89ca2987b69786d26daef44a0e660a2dc8 - Sigstore transparency entry: 1623951326
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@f6df8440008d01e7386b9d9af85b119be7687078 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f6df8440008d01e7386b9d9af85b119be7687078 -
Trigger Event:
release
-
Statement type:
File details
Details for the file clickhouse_mcp_agent-0.9.0-py3-none-any.whl.
File metadata
- Download URL: clickhouse_mcp_agent-0.9.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa01f75c4441de02bb724f37a35522005250267812efee3f4140f5d17bad7fec
|
|
| MD5 |
bb00b0e8335fc1dd4153dcf08020e35a
|
|
| BLAKE2b-256 |
8c62e4dbfcd16a73af50fafd33cf228dba744210e7807be29fe78a4ee786b79c
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.9.0-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.9.0-py3-none-any.whl -
Subject digest:
aa01f75c4441de02bb724f37a35522005250267812efee3f4140f5d17bad7fec - Sigstore transparency entry: 1623951363
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@f6df8440008d01e7386b9d9af85b119be7687078 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f6df8440008d01e7386b9d9af85b119be7687078 -
Trigger Event:
release
-
Statement type: