Skip to main content
In this guide, you’ll learn how to build a LlamaIndex AI agent that can interact with ClickHouse’s SQL playground using ClickHouse’s MCP server.
Example notebookThis example can be found as a notebook in the examples repository.

Prerequisites

  • You’ll need to have Python installed on your system.
  • You’ll need to have pip installed on your system.
  • You’ll need an Anthropic API key, or API key from another LLM provider
You can run the following steps either from your Python REPL or via script.
1

Install libraries

Install the required libraries by running the following commands:
2

Setup credentials

Next, you’ll need to provide your Anthropic API key:
Response
Using another LLM providerIf you don’t have an Anthropic API key, and want to use another LLM provider, you can find the instructions for setting up your credentials in the LlamaIndex “LLMs” docs
3

Initialize MCP server

Now configure the ClickHouse MCP server to point at the ClickHouse SQL playground. You’ll need to convert those from Python functions into Llama Index tools:
4

Create an agent

You’re now ready to create an agent that has access to those tools. Set the maximum number of tool calls in one run to 10. You can modify this parameter if you want:
5

Initialize the LLM

Initialize the Claude Sonnet 4.0 model with the following code:
6

Run the agent

Finally, you can ask the agent a question:
The response back is long, so it has been truncated in the example response below:
Response
Last modified on July 10, 2026