> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude DesktopでClickHouse MCPサーバーを使う

> このガイドでは、Claude Desktop で 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>;
};

> このガイドでは、`uv` を使って Claude Desktop を ClickHouse MCPサーバーに設定し、
> ClickHouse のサンプルデータセットに接続する方法を説明します。

<Frame>
  <iframe src="https://www.youtube.com/embed/y9biAm_Fkqw?si=9PP3-1Y1fvX8xy7q" title="YouTubeビデオプレーヤー" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen />
</Frame>

<Steps>
  <Step title="uvをインストールする" id="install-uv">
    このガイドの手順に従うには、[uv](https://docs.astral.sh/uv/) をインストールする必要があります。
    uv を使わない場合は、別のパッケージマネージャーを使うように MCPサーバーの設定を更新する必要があります。
  </Step>

  <Step title="Claude Desktopをダウンロードする" id="download-claude-desktop">
    Claude Desktop アプリもインストールする必要があります。これは [Claude Desktop website](https://claude.ai/desktop) からダウンロードできます。
  </Step>

  <Step title="ClickHouse MCPサーバーを設定する" id="configure-clickhouse-mcp-server">
    Claude Desktop をインストールしたら、次は [ClickHouse MCPサーバー](https://github.com/ClickHouse/mcp-clickhouse) を設定します。
    これは [Claude Desktop configuration file](https://claude.ai/docs/configuration) で行えます。

    このファイルを見つけるには、まず設定ページ (Mac では `Cmd+,`) を開き、左側のメニューで `Developer` タブをクリックします。
    すると次の画面が表示されるので、`Edit config` ボタンをクリックします。

    <Image img="https://mintcdn.com/private-7c7dfe99/F7iOqwDUBB9E2S65/images/use-cases/AI_ML/MCP/claude-desktop-config.webp?fit=max&auto=format&n=F7iOqwDUBB9E2S65&q=85&s=c0bb7df35d863e36f02b5223e5356c71" alt="Claude Desktopの設定" size="md" width="831" height="512" data-path="images/use-cases/AI_ML/MCP/claude-desktop-config.webp" />

    すると、設定ファイル (`claude_desktop_config.json`) があるディレクトリが開きます。
    このファイルを初めて開いたときは、おそらく次の内容になっています。

    ```json theme={null}
    {
      "mcpServers": {}
    }
    ```

    `mcpServers` Dictionary は、キーとして MCPサーバー名を取り、値として設定オプションの Dictionary を取ります。
    たとえば、ClickHouse Playground に接続する ClickHouse MCPサーバーの設定は次のようになります。

    ```json theme={null}
    {
      "mcpServers": {
        "mcp-clickhouse": {
          "command": "uv",
          "args": [
            "run",
            "--with",
            "mcp-clickhouse",
            "--python",
            "3.10",
            "mcp-clickhouse"
          ],
          "env": {
            "CLICKHOUSE_HOST": "sql-clickhouse.clickhouse.com",
            "CLICKHOUSE_PORT": "8443",
            "CLICKHOUSE_USER": "demo",
            "CLICKHOUSE_PASSWORD": "",
            "CLICKHOUSE_SECURE": "true",
            "CLICKHOUSE_VERIFY": "true",
            "CLICKHOUSE_CONNECT_TIMEOUT": "30",
            "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
          }
        }
      }
    }
    ```

    設定を更新したら、変更を反映するために Claude Desktop を再起動する必要があります。

    <Warning>
      `uv` のインストール方法によっては、Claude Desktop の再起動時に次のエラーが表示されることがあります。

      ```text theme={null}
      MCP mcp-clickhouse: spawn uv ENOENT
      ```

      その場合は、`command` を `uv` のフルパスに更新する必要があります。たとえば Cargo 経由でインストールした場合は `/Users/<username>/.cargo/bin/uv` になります。
    </Warning>
  </Step>

  <Step title="ClickHouse MCPサーバーを使う" id="using-clickhouse-mcp-server">
    Claude Desktop を再起動したら、`Search and tools` アイコンをクリックして ClickHouse MCPサーバーを見つけられます。

    <Image img="https://mintcdn.com/private-7c7dfe99/F7iOqwDUBB9E2S65/images/use-cases/AI_ML/MCP/find-mcp-servers.webp?fit=max&auto=format&n=F7iOqwDUBB9E2S65&q=85&s=e565fac435e15ec696063e9075d44c86" alt="MCPサーバーを見つける" size="md" width="868" height="788" data-path="images/use-cases/AI_ML/MCP/find-mcp-servers.webp" />

    <br />

    その後、すべてのツールを無効にするか、一部だけ無効にするかを選べます。

    これで、ClickHouse MCPサーバーを使って Claude に質問する準備が整いました。
    たとえば、`What's the most interesting dataset in the SQL playground?` と尋ねることができます。

    Claude は、MCPサーバー内の各ツールを初めて呼び出す際に、その使用を確認するよう求めます。

    <Image img="https://mintcdn.com/private-7c7dfe99/F7iOqwDUBB9E2S65/images/use-cases/AI_ML/MCP/mcp-permission.webp?fit=max&auto=format&n=F7iOqwDUBB9E2S65&q=85&s=a4e6835ed862a91732d79b92f0276a2f" alt="list_databasesツールの使用を許可する" size="md" width="536" height="411" data-path="images/use-cases/AI_ML/MCP/mcp-permission.webp" />

    以下では、ClickHouse MCPサーバーへのいくつかのツール呼び出しを含む会話の一部を確認できます。

    <Image img="https://mintcdn.com/private-7c7dfe99/F7iOqwDUBB9E2S65/images/use-cases/AI_ML/MCP/claude-conversation.webp?fit=max&auto=format&n=F7iOqwDUBB9E2S65&q=85&s=91f4c471e7711719f61b7dd5f1d6e5ac" alt="Claudeとの会話" size="md" width="1857" height="1684" data-path="images/use-cases/AI_ML/MCP/claude-conversation.webp" />
  </Step>
</Steps>
