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

# Loki

> Connect Loki directly for LogQL log search during diagnosis

The Loki integration gives sureops agents access to your Loki instance for LogQL log queries — used during diagnosis to surface relevant log lines, error patterns, and stack traces correlated with an incident's time window and affected services.

<Note>
  If your Loki is already configured as a Grafana datasource, you likely **do not need this integration** — the [Grafana integration](/next/integrations/grafana) covers Loki log queries through a single MCP server. Connect Loki directly only if you run Loki standalone without Grafana, or if your Loki is not accessible through your Grafana instance.
</Note>

***

## What this integration enables

* **LogQL queries** — agents search log streams for error messages, exception traces, and service-level events during diagnosis
* **Time-window correlation** — agents narrow log searches to the incident time window and affected services automatically
* **Multi-tenant support** — if you run a multi-tenant Loki, configure the Tenant ID to scope queries to the correct org

***

## Prerequisites

* A running Loki instance reachable from your network
* The `loki-mcp` server running and reachable from sureops

***

## Setup

<Steps>
  <Step title="Stand up loki-mcp">
    Deploy `loki-mcp` pointed at your Loki instance. If you're using the sureops demo environment, `loki-mcp` is already provisioned in-cluster — you can skip this step.

    For your own environment, deploy `loki-mcp` with your Loki base URL. The sureops MCP setup guide has Helm and Docker Compose examples.
  </Step>

  <Step title="Enter MCP endpoint and token">
    In sureops, go to **Settings → Integrations** and click **Connect** next to Loki.

    Fill in:

    * **Loki MCP Endpoint** — the URL of your running `loki-mcp` server (e.g. `https://loki-mcp.internal.company.com/mcp`)
    * **MCP Connection Token** — the bearer token used to authenticate sureops to your `loki-mcp` deployment
    * **Tenant ID** — optional; only required for multi-tenant Loki deployments. Uses the `X-Scope-OrgID` header. Defaults to `fake` for single-tenant deployments.

    Click **Verify connection** to confirm sureops can reach the MCP server.
  </Step>
</Steps>

***

## Required credentials

| Field                | Required | Description                                                           |
| -------------------- | -------- | --------------------------------------------------------------------- |
| Loki MCP Endpoint    | Yes      | URL of your running `loki-mcp` server                                 |
| MCP Connection Token | Yes      | Bearer token for authenticating sureops to your `loki-mcp` deployment |
| Tenant ID            | No       | Optional Loki `X-Scope-OrgID` for multi-tenant deployments            |

***

## Common errors

| Error                  | Fix                                                                                                                                                                                          |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| "401 Unauthorized"     | The MCP connection token is incorrect or the `loki-mcp` server doesn't recognize it. Regenerate the token and update both the server config and sureops.                                     |
| "No logs found"        | Your LogQL query is valid but returns no results. Confirm that Loki is receiving logs from your services and that the label selectors (e.g. `{namespace="default"}`) match your log streams. |
| "Connection timed out" | Your `loki-mcp` server is not reachable from sureops. Check network accessibility and port configuration.                                                                                    |

***

## Official documentation

* [Loki documentation](https://grafana.com/docs/loki/latest/)
* [LogQL reference](https://grafana.com/docs/loki/latest/query/)
