Building an agentic app with ClickHouse MCP and CopilotKit
A natural-language analytics dashboard for UK property prices can be built by combining an LLM (Claude Sonnet 3.7), the ClickHouse MCP Server and CopilotKit in a Next.js app. The LLM turns a prompt into SQL, CopilotKit's MCP client runs it against ClickHouse over SSE, and the model then calls a `generateChart` action defined with `useCopilotAction` to render the result via ECharts. The walkthrough covers swapping in the Anthropic adapter, running the MCP server with fastmcp, and sharing chart state with `useCopilotReadable`. It recommends a read-only ClickHouse user with restricted databases, quotas and a limited settings profile so the model cannot reach data or run queries beyond what is intended.
Related posts
- Agentic coding with ClickHouse. One person, one data stack, one full-stack application
ClickHouse easyNovice
A ClickHouse Solutions Architect with no frontend or backend background built ClickShop, a full-stack retail analytics demo, in a couple of days using Cursor. The stack uses Next.js on Vercel with per-persona workspaces, PostgreSQL for transactions synced to ClickHouse via ClickPipes CDC, and a Bronze/Silver/Gold medallion layout built on materialized views. On top sit 18 LibreChat agents, plus two observability layers: Langfuse for LLM tracing and cost, and ClickStack over OpenTelemetry for infrastructure. Open source components, Cursor skills and MCP database connectors reduce AI guesswork, though iteration, review and token costs remain significant.
- Agentic analytics in Slack with ClickHouse, MCP, and PydanticAI
ClickHouse mediumAdept
A Slack bot built with PydanticAI and the Anthropic API answers natural-language analytics questions by querying ClickHouse through the mcp-clickhouse MCP server. The walkthrough covers Slack app setup in Socket Mode (scopes, events, tokens), launching the MCP server on demand via MCPServerStdio (simpler to manage, at some latency cost), configuring the Agent with a system prompt, and handling DMs and mentions with thread history passed as context. Logs show the LLM listing tools, databases and tables before issuing SQL against the public sql.clickhouse.com playground.
- AI Functions in ClickHouse: Upgrade your SQL to the AI age
ClickHouse mediumAdept
ClickHouse's beta AI Functions call LLM and embedding providers directly from SQL. They include aiClassify, aiExtract, aiGenerate, aiTranslate, aiFilter, aiRedact, aiEmbed and aiSimilarity, added across releases 26.4 to 26.8, and they make one HTTP request per row (batched for embeddings) and return native ClickHouse values. Setup on OSS uses named collections for credentials and works with any OpenAI-compatible endpoint, including local models via Ollama. Examples on the Hacker News dataset show classification, LLM predicates in WHERE, summarization, translation and an in-database RAG pipeline built on materialized-view embeddings and vector indexes. Per-query quotas on API calls and input/output tokens cap spend: call limits are exact, token limits can overshoot by one in-flight request per thread, a soft-stop mode returns partial results, and actual usage is visible in system.query_log ProfileEvents.
- Building a RAG pipeline for Google Analytics with ClickHouse and Amazon Bedrock
ClickHouse mediumAdept
A natural language interface over raw Google Analytics data stored in ClickHouse is built as a multi-step RAG pipeline that generates SQL from user questions using Amazon Bedrock models. Drawing on text-to-SQL research such as DAIL-SQL from the Spider benchmark, the design retrieves similar example questions and their SQL via vector embeddings, because concepts like "returning users" cannot be inferred from the schema alone. Embeddings come from a Python executable-pool UDF calling Titan embeddings, with retries and backoff for Bedrock quotas, and are invoked at query or insert time. ClickHouse serves as both the vector store and the analytics database, and specific settings are given to parallelize embedding generation on small tables.
- Integrating with ClickHouse MCP
ClickHouse mediumAdept
The open-source mcp-clickhouse server can be wired into five Python agent frameworks: Agno, DSPy, LangChain, LlamaIndex and PydanticAI. Each example uses uv to launch the server over stdio, points it at the public ClickHouse SQL Playground, and uses Anthropic Claude models. The frameworks differ mainly in ceremony. PydanticAI and Agno take the server directly, while DSPy needs a Signature class and manual conversion of MCP tools. LlamaIndex's default max_function_calls of 5 was too low to answer questions and had to be raised to 10. ClickHouse also plans a remote MCP server built into ClickHouse Cloud.