> ## 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](https://docs.sureops.ai/integrations/grafana.md) 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.

***

## 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

* An environment selected in the top-right context switcher — **Settings → Environment → Integrations** is scoped to that environment and stays disabled until one is selected
* A running Loki instance reachable from your network
* The `loki-mcp` server running and reachable from sureops

> [!NOTE]
>
> Integration connections are per-environment. Connecting Loki here only applies to the environment that was selected in the context switcher at the time — it does not carry over to your other environments. Repeat this connect flow for each environment that needs Loki.

***

## Setup

**1. Stand up loki-mcp**

Deploy an MCP server that speaks LogQL against your Loki instance. The sureops demo environment doesn't use this integration — Grafana is already connected there and covers Loki queries.

For your own environment, deploy your MCP server of choice with your Loki base URL configured as its upstream.

**2. Connect in sureops**

In sureops, go to **Settings → Environment → Integrations** and click **Connect** next to Loki.

Fill in:

* **Integration Name** — prefilled; change it if you need to tell two configurations of this integration apart
* **MCP Server Endpoint** — the URL of your running `loki-mcp` server (e.g. `https://loki-mcp.internal.company.com/mcp`)
* **Bearer Token** — the token your `loki-mcp` endpoint (or the proxy in front of it) expects. sureops always sends this to `loki-mcp` as an `Authorization: Bearer` header, so there is no authentication method to choose. The form won't save a blank token, so if nothing in front of `loki-mcp` checks a token, put it behind an ingress or proxy that does.

Click **Save & Connect**.

**3. Configure Tenant ID (after connecting, if needed)**

Once connected, reopen the Loki integration from **Settings → Environment → Integrations**. If you run a multi-tenant Loki, a **Settings** section appears below the connection status with a **Tenant ID** field — set it there, not on the connect form. When set, it's sent as the `X-Scope-OrgID` header. There's no system default — `fake` is just the value single-tenant Loki commonly expects if it enforces the header at all; don't type it in unless that's genuinely your tenant ID. Leave it blank for single-tenant Loki.

***

## Required credentials

Fields collected when you connect the integration:

| Field | Required | Description |
| - | - | - |
| Integration Name | No | Prefilled with a default name; distinguishes two configurations of the same integration in one environment |
| MCP Server Endpoint | Yes | URL of your running `loki-mcp` server |
| Bearer Token | Yes | Token your `loki-mcp` endpoint (or the proxy in front of it) expects. Required; sent to `loki-mcp` as an `Authorization: Bearer` header |

Field configured afterward, via the integration's Settings section once connected:

| Field | Required | Description |
| - | - | - |
| Tenant ID | No | Optional Loki `X-Scope-OrgID` for multi-tenant deployments. Unset by default — no system default value. |

***

## 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/)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.