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
pipinstalled on your system. - You’ll need an Anthropic API key, or API key from another LLM provider
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 Langchain Providers docs
3
Initialize MCP server
Now configure the ClickHouse MCP server to point at the ClickHouse SQL playground:
4
Configure the stream handler
When working with Langchain and ClickHouse MCP server, query results are often
returned as streaming data rather than a single response. For large datasets or
complex analytical queries that may take time to process, it’s important to configure
a stream handler. Without proper handling, this streamed output can be difficult
to work with in your application.Configure the handler for the streamed output so that it’s easier to consume:
5
Call the agent
Finally, call your agent and ask it who’s committed the most code to ClickHouse:You should see a similar response as below:
Response