> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-home-button.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 在 Open WebUI 中使用 ClickHouse MCP 服务器

> 本指南介绍如何使用 Docker 为 Open WebUI 设置 ClickHouse MCP 服务器。

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

> 本指南介绍如何为 [Open WebUI](https://github.com/open-webui/open-webui) 配置 ClickHouse MCP 服务器，
> 并将其连接到 ClickHouse 示例数据集。

<Steps>
  <Step>
    ## 安装 uv

    要按照本指南操作，你需要先安装 [uv](https://docs.astral.sh/uv/)。
    如果你不想使用 uv，则需要更新 MCP 服务器配置，改用其他包管理器。
  </Step>

  <Step>
    ## 启动 Open WebUI

    要启动 Open WebUI，可以运行以下命令：

    ```bash theme={null}
    uv run --with open-webui open-webui serve
    ```

    访问 [http://localhost:8080/](http://localhost:8080/) 即可打开 UI。
  </Step>

  <Step>
    ## 配置 ClickHouse MCP 服务器

    要设置 ClickHouse MCP 服务器，我们需要先将 MCP 服务器转换为 Open API 端点。
    首先，设置环境变量，以便连接到 ClickHouse SQL Playground：

    ```bash theme={null}
    export CLICKHOUSE_HOST="sql-clickhouse.clickhouse.com"
    export CLICKHOUSE_USER="demo"
    export CLICKHOUSE_PASSWORD=""
    ```

    然后，运行 `mcpo` 来创建 Open API 端点：

    ```bash theme={null}
    uvx mcpo --port 8000 -- uv run --with mcp-clickhouse --python 3.10 mcp-clickhouse
    ```

    访问 [http://localhost:8000/docs](http://localhost:8000/docs) 即可查看已创建的端点列表。

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/0_endpoints.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=20b17744f7660940809865adc31ed3d5" alt="Open API 端点" size="md" width="1455" height="759" data-path="images/use-cases/AI_ML/MCP/0_endpoints.png" />

    要在 Open WebUI 中使用这些端点，需要进入设置：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/1_settings.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=7465241583cfa2136482f14c24607d08" alt="Open WebUI 设置" size="md" width="518" height="575" data-path="images/use-cases/AI_ML/MCP/1_settings.png" />

    点击 `Tools`：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/2_tools_page.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=31a7ba9072b2ddcd3d1a55f25bf339e0" alt="Open WebUI 工具" size="md" width="1829" height="1190" data-path="images/use-cases/AI_ML/MCP/2_tools_page.png" />

    将 [http://localhost:8000](http://localhost:8000) 添加为工具 URL：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/3_add_tool.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=9068aaf132fbf7ede524cc59cb6d7507" alt="Open WebUI 工具" size="md" width="1838" height="1201" data-path="images/use-cases/AI_ML/MCP/3_add_tool.png" />

    完成后，你应该会在聊天栏的工具图标旁看到一个 `1`：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/4_tools_available.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=7b43c59e6f78fc8e2a0f02506f3ab75d" alt="Open WebUI 可用工具" size="md" width="1495" height="229" data-path="images/use-cases/AI_ML/MCP/4_tools_available.png" />

    点击工具图标后，就可以查看可用工具列表：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/5_list_of_tools.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=b841711c91390ee4964e9a9fc92bc292" alt="Open WebUI 工具列表" size="md" width="1373" height="711" data-path="images/use-cases/AI_ML/MCP/5_list_of_tools.png" />
  </Step>

  <Step>
    ## 配置 OpenAI

    默认情况下，Open WebUI 使用 Ollama 模型，但也可以添加与 OpenAI 兼容的端点。
    这些连接可通过设置菜单进行配置，不过这次需要点击 `Connections` 选项卡：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/6_connections.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=670480b1ffffb7c054fdd6bda826aa9e" alt="Open WebUI 连接" size="md" width="1824" height="1184" data-path="images/use-cases/AI_ML/MCP/6_connections.png" />

    添加端点和你的 OpenAI 密钥：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/WFuxNqAZKLNkIccm/images/use-cases/AI_ML/MCP/7_add_connection.png?fit=max&auto=format&n=WFuxNqAZKLNkIccm&q=85&s=69d16fb6ee997a81fdc5f20360eb808d" alt="Open WebUI - 添加 OpenAI 连接" size="md" width="1821" height="1192" data-path="images/use-cases/AI_ML/MCP/7_add_connection.png" />

    之后，OpenAI 模型就会显示在顶部菜单中：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/KSay_cT2LdltZH8Z/images/use-cases/AI_ML/MCP/8_openai_models_more.png?fit=max&auto=format&n=KSay_cT2LdltZH8Z&q=85&s=ef7698cdde2874adb4b3d9f46976de36" alt="Open WebUI - 模型" size="md" width="1574" height="1248" data-path="images/use-cases/AI_ML/MCP/8_openai_models_more.png" />
  </Step>

  <Step>
    ## 在 Open WebUI 中与 ClickHouse MCP 服务器对话

    然后，你就可以开始对话；如有需要，Open WebUI 会调用 MCP 服务器：

    <Image img="https://mintcdn.com/private-7c7dfe99-home-button/KSay_cT2LdltZH8Z/images/use-cases/AI_ML/MCP/9_conversation.png?fit=max&auto=format&n=KSay_cT2LdltZH8Z&q=85&s=986ac4ed1c8750d2971dc0949cd5d723" alt="Open WebUI - 与 ClickHouse MCP 服务器对话" size="md" width="2449" height="1839" data-path="images/use-cases/AI_ML/MCP/9_conversation.png" />
  </Step>
</Steps>
