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, SQL used, 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
Quickstart
- Set model/provider and API key using the runtime config
- Instantiate
ClickHouseAgentand callrun()orrun_stream()
Example mirrors examples/example_minimal.py:
import asyncio
from agent.clickhouse_agent import ClickHouseAgent
from agent.config import config
config.set_log_level("DEBUG")
config.set_ai_model("gemini-2.0-flash")
config.set_model_api_key("google", "your_api_key_here")
async def main():
agent = ClickHouseAgent()
# Single MCP server (mcp-clickhouse). Limit scope via allow-lists (recommended)
result = await agent.run(
allowed_tables=["top_repos_mv"],
query="SHOW_TABLES",
)
print("Analysis:", result.analysis)
print("SQL Used:", result.sql_used)
print("Confidence:", result.confidence)
asyncio.run(main())
- 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.sql_used: SQL used (if applicable) from the model output.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
✅ Completed
- 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
- Type annotations and basic linting
- Streaming results via
run_stream()
🚧 Planned
- Improved error handling and diagnostics
- Advanced output formatting for downstream apps
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.8.0.tar.gz.
File metadata
- Download URL: clickhouse_mcp_agent-0.8.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53668d3d1d57fb16c94b75903a9df46df0b0c930415a7bc66fb6776618d377a7
|
|
| MD5 |
5fb16b92a54d98d6ee89896d0dfc4493
|
|
| BLAKE2b-256 |
944f6e0f847effee968cd88cc31592a403351280400e592b995a3cf544bfc1d2
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.8.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.8.0.tar.gz -
Subject digest:
53668d3d1d57fb16c94b75903a9df46df0b0c930415a7bc66fb6776618d377a7 - Sigstore transparency entry: 473432380
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@56c8d881904d7eca8a59c697de8f4e6821e7a568 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@56c8d881904d7eca8a59c697de8f4e6821e7a568 -
Trigger Event:
release
-
Statement type:
File details
Details for the file clickhouse_mcp_agent-0.8.0-py3-none-any.whl.
File metadata
- Download URL: clickhouse_mcp_agent-0.8.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa4de3864b24e9f7aad814a48979d0810f982743768bfb0e5b06aaa2a3bae699
|
|
| MD5 |
c289eb521f5eff5af934393fbc053096
|
|
| BLAKE2b-256 |
edf812aa465ecc347bf740da5faf23e7b7463b203a37f6d8139ccf9d733fa06c
|
Provenance
The following attestation bundles were made for clickhouse_mcp_agent-0.8.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.8.0-py3-none-any.whl -
Subject digest:
aa4de3864b24e9f7aad814a48979d0810f982743768bfb0e5b06aaa2a3bae699 - Sigstore transparency entry: 473432398
- Sigstore integration time:
-
Permalink:
AranNomante/clickhousemcp@56c8d881904d7eca8a59c697de8f4e6821e7a568 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/AranNomante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@56c8d881904d7eca8a59c697de8f4e6821e7a568 -
Trigger Event:
release
-
Statement type: