> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-vortex-format.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 = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

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

<Steps>
  <Step title="安装 uv" id="install-uv">
    按照本指南操作前，需要先安装 [uv](https://docs.astral.sh/uv/)。
    如果不想使用 uv，则需要更新 MCP 服务器的 config，改用其他 package manager。
  </Step>

  <Step title="启动 Open WebUI" id="launch-open-webui">
    要启动 Open WebUI，可以运行以下命令：

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

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

  <Step title="配置 ClickHouse MCP 服务器" id="configure-clickhouse-mcp-server">
    要配置 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-vortex-format/mc_CXbtYxT_GqYxL/images/use-cases/AI_ML/MCP/0_endpoints.webp?fit=max&auto=format&n=mc_CXbtYxT_GqYxL&q=85&s=e08cb52990ea84f3739005932686f2f6" alt="Open API 端点" size="md" width="1455" height="759" data-path="images/use-cases/AI_ML/MCP/0_endpoints.webp" />

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

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

    点击 `Tools`：

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

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

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

    完成后，聊天栏中的工具图标旁应该会显示一个 `1`：

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

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

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

  <Step title="配置 OpenAI" id="configure-openai">
    默认情况下，Open WebUI 使用 Ollama 模型，但也可以添加与 OpenAI 兼容的端点。
    这些内容可通过设置菜单进行配置，这里需要点击 `Connections` 选项卡：

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

    添加该端点以及 OpenAI 密钥：

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

    随后，OpenAI 模型就会出现在顶部菜单中：

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

  <Step title="通过 Open WebUI 与 ClickHouse MCP 服务器聊天" id="chat-to-clickhouse-mcp-server">
    接下来即可开始对话，Open WebUI 会在需要时调用 MCP 服务器：

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/mc_CXbtYxT_GqYxL/images/use-cases/AI_ML/MCP/9_conversation.webp?fit=max&auto=format&n=mc_CXbtYxT_GqYxL&q=85&s=811df4b7acf2ede51f59a178efed4881" alt="Open WebUI - 与 ClickHouse MCP 服务器聊天" size="md" width="2449" height="1839" data-path="images/use-cases/AI_ML/MCP/9_conversation.webp" />
  </Step>
</Steps>
