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

# Using ClickHouse MCP server with LibreChat

> This guide explains how to set up LibreChat with a ClickHouse MCP server using Docker.

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

> This guide explains how to set up LibreChat with a ClickHouse MCP server using Docker
> and connect it to the ClickHouse example datasets.

<Steps>
  <Step>
    <h2 id="install-docker">
      Install docker
    </h2>

    You will need Docker to run LibreChat and the MCP server. To get Docker:

    1. Visit [docker.com](https://www.docker.com/products/docker-desktop)
    2. Download Docker desktop for your operating system
    3. Install Docker by following the instructions for your operating system
    4. Open Docker Desktop and ensure it is running

    <br />

    For more information, see the [Docker documentation](https://docs.docker.com/get-docker/).
  </Step>

  <Step>
    <h2 id="clone-librechat-repo">
      Clone the LibreChat repository
    </h2>

    Open a terminal (command prompt, terminal or PowerShell) and clone the
    LibreChat repository using the following command:

    ```bash theme={null}
    git clone https://github.com/danny-avila/LibreChat.git
    cd LibreChat
    ```
  </Step>

  <Step>
    <h2 id="create-and-edit-env-file">
      Create and edit the .env file
    </h2>

    Copy the example configuration file from `.env.example` to `.env`:

    ```bash theme={null}
    cp .env.example .env
    ```

    Open the `.env` file in your favorite text editor. You will see sections for
    many popular LLM providers, including OpenAI, Anthropic, AWS bedrock etc, for
    example:

    ```text title=".venv" highlight={4} theme={null}
    #============#
    # Anthropic  #
    #============#
    ANTHROPIC_API_KEY=user_provided
    # ANTHROPIC_MODELS=claude-opus-4-20250514,claude-sonnet-4-20250514,claude-3-7-sonnet-20250219,claude-3-5-sonnet-20241022,claude-3-5-haiku-20241022,claude-3-opus-20240229,claude-3-sonnet-20240229,claude-3-haiku-20240307
    # ANTHROPIC_REVERSE_PROXY=
    ```

    Replace `user_provided` with your API key for the LLM provider you want to use.

    <Info>
      **Using a local LLM**

      If you don't have an API key you can use a local LLM like Ollama. You'll see how
      to do this later in step ["Install Ollama"](#add-local-llm-using-ollama). For now
      don't modify the .env file and continue with the next steps.
    </Info>
  </Step>

  <Step>
    <h2 id="create-librechat-yaml-file">
      Create a librechat.yaml file
    </h2>

    Run the following command to create a new `librechat.yaml` file:

    ```bash theme={null}
    cp librechat.example.yaml librechat.yaml
    ```

    This creates the main [configuration file](https://www.librechat.ai/docs/configuration/librechat_yaml) for LibreChat.
  </Step>

  <Step>
    <h2 id="add-clickhouse-mcp-server-to-docker-compose">
      Add ClickHouse MCP server to Docker compose
    </h2>

    Next we'll add the ClickHouse MCP server to the LibreChat Docker compose file
    so that the LLM can interact with the
    [ClickHouse SQL playground](https://sql.clickhouse.com/).

    Create a file called `docker-compose.override.yml` and add the following configuration to it:

    ```yml title="docker-compose.override.yml" theme={null}
    services:
      api:
        volumes:
          - ./librechat.yaml:/app/librechat.yaml
      mcp-clickhouse:
        image: mcp/clickhouse
        container_name: mcp-clickhouse
        ports:
          - 8001:8000
        extra_hosts:
          - "host.docker.internal:host-gateway"
        environment:
          - CLICKHOUSE_HOST=sql-clickhouse.clickhouse.com
          - CLICKHOUSE_USER=demo
          - CLICKHOUSE_PASSWORD=
          - CLICKHOUSE_MCP_SERVER_TRANSPORT=sse
          - CLICKHOUSE_MCP_BIND_HOST=0.0.0.0
    ```

    If you want to explore your own data, you can do so by
    using the [host, username and password](/get-started/setup/cloud#connect-with-your-app)
    of your own ClickHouse Cloud service.

    <Card title="Get started with ClickHouse Cloud" href="https://cloud.clickhouse.com/" icon="cloud">
      If you don't have a Cloud account yet, get started with ClickHouse Cloud today and receive \$300 in credits. At the end of your 30-day free trial, continue with a pay-as-you-go plan, or contact us to learn more about our volume-based discounts. Visit our pricing page for details.
    </Card>
  </Step>

  <Step>
    <h2 id="configure-mcp-server-in-librechat-yaml">
      Configure MCP server in librechat.yaml
    </h2>

    Open `librechat.yaml` and place the following configuration at the end of the file:

    ```yml theme={null}
    mcpServers:
      clickhouse-playground:
        type: sse
        url: http://host.docker.internal:8001/sse
    ```

    This configures LibreChat to connect to the MCP server running on Docker.

    Find the following line:

    ```text title="librechat.yaml" theme={null}
    socialLogins: ['github', 'google', 'discord', 'openid', 'facebook', 'apple', 'saml']
    ```

    For simplicity, we will remove the need to authenticate for now:

    ```text title="librechat.yaml" theme={null}
    socialLogins: []
    ```
  </Step>

  <Step>
    <h2 id="add-local-llm-using-ollama">
      Add a local LLM using Ollama (optional)
    </h2>

    <h3 id="install-ollama">
      Install Ollama
    </h3>

    Go to the [Ollama website](https://ollama.com/download) and install Ollama for your system.

    Once installed, you can run a model like this:

    ```bash theme={null}
    ollama run qwen3:32b
    ```

    This will pull the model to your local machine if it isn't present.

    For a list of models see the [Ollama library](https://ollama.com/library)

    <h3 id="configure-ollama-in-librechat-yaml">
      Configure Ollama in librechat.yaml
    </h3>

    Once the model has downloaded, configure it in `librechat.yaml`:

    ```text title="librechat.yaml" theme={null}
    custom:
      - name: "Ollama"
        apiKey: "ollama"
        baseURL: "http://host.docker.internal:11434/v1/"
        models:
          default:
            [
              "qwen3:32b"
            ]
          fetch: false
        titleConvo: true
        titleModel: "current_model"
        summarize: false
        summaryModel: "current_model"
        forcePrompt: false
        modelDisplayLabel: "Ollama"
    ```
  </Step>

  <Step>
    <h2 id="start-all-services">
      Start all services
    </h2>

    From the root of the LibreChat project folder, run the following command to start the services:

    ```bash theme={null}
    docker compose up
    ```

    Wait until all services are fully running.
  </Step>

  <Step>
    <h2 id="open-librechat-in-browser">
      Open LibreChat in your browser
    </h2>

    Once all services are up and running, open your browser and go to `http://localhost:3080/`

    Create a free LibreChat account if you don't yet have one, and sign in. You should
    now see the LibreChat interface connected to the ClickHouse MCP server, and optionally,
    your local LLM.

    From the chat interface, select `clickhouse-playground` as your MCP server:

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/aVaB4U557by41sEW/images/use-cases/AI_ML/MCP/librechat.png?fit=max&auto=format&n=aVaB4U557by41sEW&q=85&s=149945076810ab29e1dec92ae6efdd34" alt="Select your MCP server" size="md" width="1630" height="918" data-path="images/use-cases/AI_ML/MCP/librechat.png" />

    You can now prompt the LLM to explore the ClickHouse example datasets. Give it a go:

    ```text title="Prompt" theme={null}
    What datasets do you have access to?
    ```
  </Step>
</Steps>

<Note>
  If the MCP server option doesn't appear in the LibreChat UI,
  check that the proper permissions are set in your `librechat.yaml` file.
</Note>

If `use` is set to `false` in the `mcpServers` section under `interface`, the MCP selection dropdown won't appear in chat:

```yml title="librechat.yaml" theme={null}
interface:
  mcpServers:
    use: true
    share: false
    create: false
    public: false
```
