Skip to content

Commit f45fcbf

Browse files
authored
Merge pull request #4084 from mneedham/ollama
Ollama/MCPHost example
2 parents 3a71063 + 37dde62 commit f45fcbf

File tree

6 files changed

+248
-17
lines changed

6 files changed

+248
-17
lines changed

.gitignore

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ docs/data-modeling/projections/index.md
6363
docs/cloud/manage/jan2025_faq/index.md
6464
docs/chdb/guides/index.md
6565
docs/use-cases/AI_ML/index.md
66+
docs/use-cases/AI_ML/MCP/index.md
67+
docs/integrations/data-ingestion/clickpipes/kafka/index.md
68+
6669

6770
.vscode
6871
.aspell.en.prepl
@@ -71,11 +74,3 @@ docs/use-cases/AI_ML/index.md
7174
**.translated
7275
**.translate
7376
/ClickHouse/
74-
75-
# Ignore table of contents files
76-
docs/cloud/reference/release-notes-index.md
77-
docs/whats-new/changelog/index.md
78-
docs/cloud/manage/api/api-reference-index.md
79-
docs/getting-started/index.md
80-
docs/data-modeling/projections/index.md
81-
docs/integrations/data-ingestion/clickpipes/kafka/index.md

docs/use-cases/AI_ML/MCP/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
slug: /use-cases/AI/MCP
3+
sidebar_label: 'MCP'
4+
title: 'MCP guides'
5+
pagination_prev: null
6+
pagination_next: null
7+
description: 'This page contains a landing page with table of contentsfor MCP guides.'
8+
keywords: ['ClickHouse', 'MCP']
9+
show_related_blogs: true
10+
---
11+
12+
<!--AUTOGENERATED_START-->
13+
<!--AUTOGENERATED_END-->

docs/use-cases/AI_ML/MCP/ollama.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
slug: /use-cases/AI/MCP/ollama
3+
sidebar_label: 'Ollama and ClickHouse MCP'
4+
title: 'Set Up ClickHouse MCP Server with Ollama'
5+
pagination_prev: null
6+
pagination_next: null
7+
description: 'This guide explains how to set up Ollama with a ClickHouse MCP server.'
8+
keywords: ['AI', 'Ollama', 'MCP']
9+
show_related_blogs: true
10+
---
11+
12+
import {CardHorizontal} from '@clickhouse/click-ui/bundled'
13+
import Link from '@docusaurus/Link';
14+
import Image from '@theme/IdealImage';
15+
16+
# Using ClickHouse MCP server with Ollama
17+
18+
> This guide explains how to use the ClickHouse MCP Server with Ollama.
19+
20+
<VerticalStepper headerLevel="h2">
21+
22+
## Install Ollama {#install-ollama}
23+
24+
Ollama is a library for running Large Language Models (LLMs) on your own machine.
25+
It has a [wide range of models available](https://ollama.com/library) and is easy to use.
26+
27+
You can download Ollama for Mac, Windows, or Linux from the [download page](https://ollama.com/download).
28+
29+
Once you run Ollama, it will start a local server in the background that you can use to run models.
30+
Alternatively, you can run the server manually by running `ollama serve`.
31+
32+
Once installed, you can pull a model down to your machine like this:
33+
34+
```bash
35+
ollama pull qwen3:8b
36+
```
37+
38+
This will pull the model to your local machine if it is not present.
39+
Once it's downloaded, you can run the model like this:
40+
41+
```bash
42+
ollama run qwen3:8b
43+
```
44+
45+
:::note
46+
Only [models that have tool support](https://ollama.com/search?c=tools) will work with MCP Servers.
47+
:::
48+
49+
We can list the models that we have downloaded like this:
50+
51+
```bash
52+
ollama ls
53+
```
54+
55+
```text
56+
NAME ID SIZE MODIFIED
57+
qwen3:latest 500a1f067a9f 5.2 GB 3 days ago
58+
```
59+
60+
We can use the following command to see more information about the model that we've downloaded:
61+
62+
```bash
63+
ollama show qwen3
64+
```
65+
66+
```text
67+
Model
68+
architecture qwen3
69+
parameters 8.2B
70+
context length 40960
71+
embedding length 4096
72+
quantization Q4_K_M
73+
74+
Capabilities
75+
completion
76+
tools
77+
78+
Parameters
79+
repeat_penalty 1
80+
stop "<|im_start|>"
81+
stop "<|im_end|>"
82+
temperature 0.6
83+
top_k 20
84+
top_p 0.95
85+
86+
License
87+
Apache License
88+
Version 2.0, January 2004
89+
```
90+
91+
We can see from this output that the default qwen3 model has just over 8 billion parameters.
92+
93+
## Install MCPHost {#install-mcphost}
94+
95+
At the time of writing (July 2025) there is no native functionality for using Ollama with MCP Servers.
96+
However, we can use [MCPHost](https://github.com/mark3labs/mcphost) to run Ollama models with MCP Servers.
97+
98+
MCPHost is a Go application, so you'll need to make sure that you have [Go installed](https://go.dev/doc/install) on your machine.
99+
You can then install MCPHost by running the following command:
100+
101+
```bash
102+
go install github.com/mark3labs/mcphost@latest
103+
```
104+
105+
The binary will be installed under `~/go/bin` so we need to make sure that directory is on our path.
106+
107+
## Configuring ClickHouse MCP Server {#configure-clickhouse-mcp-server}
108+
109+
We can configure MCP Servers with MCPHost in YAML or JSON files.
110+
MCPHost will look for config files in your home directory the following order:
111+
112+
1. `.mcphost.yml` or `.mcphost.json` (preferred)
113+
2. `.mcp.yml` or `.mcp.json` (backwards compatibility)
114+
115+
It uses a syntax that's similar to that used in the standard MCP configuration file.
116+
Here's an example of a ClickHouse MCP server configuration, which we'll save to the `~/.mcphost.json` file:
117+
118+
```json
119+
{
120+
"mcpServers": {
121+
"mcp-ch": {
122+
"type": "local",
123+
"command": ["uv",
124+
"run",
125+
"--with",
126+
"mcp-clickhouse",
127+
"--python",
128+
"3.10",
129+
"mcp-clickhouse"
130+
]
131+
}
132+
}
133+
}
134+
```
135+
136+
The main difference from the standard MCP configuration file is that we need to specify a `type`.
137+
The type is used to indicate the transport type used by the MCP Server.
138+
139+
* `local` → stdio transport
140+
* `remote` → streamable transport
141+
* `builtin` → inprocess transport
142+
143+
We'll also need to configure the following environment variables:
144+
145+
```bash
146+
export CLICKHOUSE_HOST=sql-clickhouse.clickhouse.com
147+
export CLICKHOUSE_USER=demo
148+
export CLICKHOUSE_PASSWORD=""
149+
```
150+
151+
:::note
152+
In theory, you should be able to provide these variables under the `environment` key in the MCP configuration file, but we've found that this doesn't work.
153+
:::
154+
155+
## Running MCPHost {#running-mcphost}
156+
157+
Once you've configured the ClickHouse MCP server, you can run MCPHost by running the following command:
158+
159+
```bash
160+
mcphost --model ollama:qwen3
161+
```
162+
163+
Or, if you want to have it use a specific config file:
164+
165+
```bash
166+
mcphost --model ollama:qwen3 --config ~/.mcphost.json
167+
```
168+
169+
:::warning
170+
If you don't provide `--model`, MCPHost will look in the environment variables for `ANTHROPIC_API_KEY` and will use the `anthropic:claude-sonnet-4-20250514` model.
171+
:::
172+
173+
We should see the following output:
174+
175+
```text
176+
┃ ┃
177+
┃ Model loaded: ollama (qwen3) ┃
178+
┃ MCPHost System (09:52) ┃
179+
┃ ┃
180+
181+
┃ ┃
182+
┃ Model loaded successfully on GPU ┃
183+
┃ MCPHost System (09:52) ┃
184+
┃ ┃
185+
186+
┃ ┃
187+
┃ Loaded 3 tools from MCP servers ┃
188+
┃ MCPHost System (09:52) ┃
189+
┃ ┃
190+
191+
Enter your prompt (Type /help for commands, Ctrl+C to quit, ESC to cancel generation)
192+
```
193+
194+
We can use the `/servers` command to list the MCP Servers:
195+
196+
```text
197+
┃ ┃
198+
┃ ## Configured MCP Servers ┃
199+
┃ ┃
200+
┃ 1. mcp-ch ┃
201+
┃ MCPHost System (10:00) ┃
202+
203+
```
204+
205+
And `/tools` to list the tools available:
206+
207+
```text
208+
┃ ## Available Tools ┃
209+
┃ ┃
210+
┃ 1. mcp-ch__list_databases ┃
211+
┃ 2. mcp-ch__list_tables ┃
212+
┃ 3. mcp-ch__run_select_query
213+
```
214+
215+
We can then ask the model questions about the databases/tables available in the ClickHouse SQL playground.
216+
217+
In our experience when using smaller models (the default qwen3 model has 8 billion parameters), you'll need to be more specific about what you'd like it to do.
218+
For example, you'll need to explicitly ask it to list the databases and tables rather than straight away asking it to query a certain table.
219+
You can partially eleviate this problem by using a large model (e.g. qwen3:14b), but that will run more slowly on consumer hardware.
220+
221+
</VerticalStepper>

docs/use-cases/AI_ML/index.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ keywords: ['machine learning', 'genAI', 'AI']
1111

1212
ClickHouse is ideally suited as a real-time database to power Machine Learning workloads.
1313
With ClickHouse, it's easier than ever to unleash GenAI on your analytics data.
14-
In this section you'll find some guides around how ClickHouse is used for
14+
In this section, you'll find some guides around how ClickHouse is used for
1515
Machine Learning and GenAI.
1616

17-
<!--AUTOGENERATED_START-->
18-
<!--AUTOGENERATED_END-->
17+
| Section | Description |
18+
|--------------------------|--------------------------------------------------------------------------------------------|
19+
| [MCP](/use-cases/AI/MCP) | A collection of guides to get you setup using Model Context Protocol (MCP) with ClickHouse |

docs/use-cases/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ description: 'Landing page for use case guides'
88

99
In this section of the docs you can find our use case guides.
1010

11-
| Page | Description |
12-
|-----------------------------------------|---------------------------------------------------------------------|
13-
| [Observability](observability/index.md) | Use case guide on how to setup and use ClickHouse for Observability |
14-
| [Time-Series](time-series/index.md) | Use case guide on how to setup and use ClickHouse for time-series |
15-
| [Data Lake](data_lake/index.md) | Use case guide on Data Lakes in ClickHouse |
11+
| Page | Description |
12+
|---------------------------------------------|-------------------------------------------------------------------------------|
13+
| [Observability](observability/index.md) | Use case guide on how to setup and use ClickHouse for Observability |
14+
| [Time-Series](time-series/index.md) | Use case guide on how to setup and use ClickHouse for time-series |
15+
| [Data Lake](data_lake/index.md) | Use case guide on Data Lakes in ClickHouse |
16+
| [Machine Learning and GenAI](/use-cases/AI) | Use case guides for Machine Learning and GenAI applications with ClickHouse |

scripts/autogenerate-table-of-contents.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ COMMANDS=(
4545
'--single-toc --dir="docs/development" --md="docs/development/index.md" --ignore images'
4646
'--single-toc --dir="docs/getting-started/example-datasets" --md="docs/getting-started/index.md" --ignore images'
4747
'--single-toc --dir="docs/integrations/data-ingestion/clickpipes/kafka" --md="docs/integrations/data-ingestion/clickpipes/kafka/index.md" --ignore images'
48-
'--single-toc --dir="docs/use-cases/AI_ML/MCP" --md="docs/use-cases/AI_ML/index.md" --ignore images'
48+
'--single-toc --dir="docs/use-cases/AI_ML/MCP" --md="docs/use-cases/AI_ML/MCP/index.md" --ignore images'
4949
)
5050

5151
# Execute each command

0 commit comments

Comments
 (0)