Skip to main content
Skip to main content

How to build an AI Agent with DSPy and the ClickHouse MCP Server

In this guide, you'll learn how to build an AI agent with DSPy that can interact with ClickHouse's SQL playground using ClickHouse's MCP Server.

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.

Example notebook

This example can be found as a notebook in the examples repository.

Install libraries

Run the following commands using pip to install the required libraries:

Setup credentials

Next, you'll need to provide your Anthropic API key:

Using another LLM provider

If 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 DSPy docs

Next, define the credentials needed to connect to the ClickHouse SQL playground:

Initialize MCP Server

Now configure the ClickHouse MCP Server to point at the ClickHouse SQL playground.

Initialize LLM

Next, initialize the LLM with the following line:

Run the agent

Finally, initialize and run the agent: