How to build an AI agent with CopilotKit and the ClickHouse MCP Server
This is an example of how to build an agentic application using data stored in ClickHouse. It uses the ClickHouse MCP Server to query data from ClickHouse and generate charts based on the data.
CopilotKit is used to build the UI and provide a chat interface to the user.
The code for this example can be found in the examples repository.
Prerequisites
Node.js >= 20.14.0
uv >= 0.1.0
Install dependencies
Clone the project locally: git clone https://github.com/ClickHouse/examples
and
navigate to the ai/mcp/copilotkit
directory.
Skip this section and run the script ./install.sh
to install dependencies. If
you want to install dependencies manually, follow the instructions below.
Install dependencies manually
- Install dependencies:
Run npm install
to install node dependencies.
- Install mcp-clickhouse:
Create a new folder external
and clone the mcp-clickhouse repository into it.
Install Python dependencies and add fastmcp cli tool.
Configure the application
Copy the env.example
file to .env
and edit it to provide your ANTHROPIC_API_KEY
.
Use your own LLM
If you'd rather use another LLM provider than Anthropic, you can modify the Copilotkit runtime to use a different LLM adapter. Here is a list of supported providers.
Use your own ClickHouse cluster
By default, the example is configured to connect to the ClickHouse demo cluster. You can also use your own ClickHouse cluster by setting the following environment variables:
CLICKHOUSE_HOST
CLICKHOUSE_PORT
CLICKHOUSE_USER
CLICKHOUSE_PASSWORD
CLICKHOUSE_SECURE
Run the application
Run npm run dev
to start the development server.
You can test the Agent using prompt like:
"Show me the price evolution in Manchester for the last 10 years."
Open http://localhost:3000 with your browser to see the result.