Grafana Loki MCP Server

A [FastMCP](https://github.com/jlowin/fastmcp) server that allows querying Loki logs from Grafana.

Local serverstdioPython

What is the Grafana Loki MCP MCP server?

Connect Grafana Loki MCP to Claude, Cursor or any other MCP client and it stops being a tab you switch to. A FastMCP server that allows querying Loki logs from Grafana. The grafana loki mcp mcp server is what makes that connection.

What the server does

  • Query Loki logs through Grafana API
  • Get Loki labels and label values
  • Format query results in different formats (text, JSON, markdown)
  • Support for both stdio and SSE transport protocols

Available tools

The toolset is worth reading before you wire it up, because it tells you what the integration is really for:

  • Testing — The Testing tool exposed by this server
  • query_loki — Parameters: - query: Loki query string - start: Start time (ISO format, Unix timestamp, or Grafana-style relative time like 'now-1h', default: 1 hour
  • get_loki_labels — The get_loki_labels tool exposed by this server
  • get_loki_label_values — The get_loki_label_values tool exposed by this server
  • format_loki_results — Parameters: - results: Loki query results from query_loki - format_type: Output format ('text', 'json', or 'markdown', default: 'text') -

Credentials and setup notes

Configuration is passed through the environment: GRAFANA_URL, GRAFANA_API_KEY. Treat anything key-shaped as a real credential — scope it to the minimum the server needs, and rotate it if it ever lands in a shared config.

  • Python 3.10+ - FastMCP - Requests

Installation

The server ships on PyPI as grafana-loki-mcp, so your MCP client can launch it on demand — there is no separate build step. Add the server block to your client's configuration, restart it, and the tools register themselves.

Where it fits

Plenty of monitoring and observability servers cover similar ground. The differences that matter in practice are scope of access and how much setup stands between you and a working tool call. Grafana Loki MCP's toolset — Testing, query_loki, get_loki_labels and 2 more — is a fair guide to whether it matches your workflow. It is maintained by tumf; worth a glance at recent repository activity before you build anything load-bearing on it.

We check each listing at SyncDev against the project's documentation before it goes live — if something here drifts out of date, it is a bug worth reporting.

Worth knowing first

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • Missing credentials fail quietly in some clients — if no tools show up, check the environment block first.
  • Keep per-call confirmation enabled while you learn its behaviour; it is the cheapest safeguard you have.

Available tools

ToolWhat it does
TestingThe Testing tool exposed by this server.
query_lokiParameters: - query: Loki query string - start: Start time (ISO format, Unix timestamp, or Grafana-style relative time like 'now-1h', default: 1 hour ago) - end: End time (ISO format, Unix timestamp, or Grafana-style rel
get_loki_labelsThe get_loki_labels tool exposed by this server.
get_loki_label_valuesThe get_loki_label_values tool exposed by this server.
format_loki_resultsParameters: - results: Loki query results from query_loki - format_type: Output format ('text', 'json', or 'markdown', default: 'text') - max_per_line: Maximum characters per log line (0 for unlimited, default: 0)

How to install the Grafana Loki MCP MCP server

{
  "mcpServers": {
    "loki": {
      "command": "uvx",
      "args": [
        "grafana-loki-mcp",
        "-u",
        "GRAFANA_URL",
        "-k",
        "GRAFANA_API_KEY"
      ]
    }
  }
}

Configuration as documented by the project. Restart the client after saving.

Configuration

  • Python 3.10+ - FastMCP - Requests
VariableDescriptionRequired
GRAFANA_URLEndpoint or connection string the server talks to.Yes
GRAFANA_API_KEYCredential the server authenticates with.Yes

Example prompts to try

  • Use Grafana Loki MCP to Testing.
  • Use Grafana Loki MCP to query loki.
  • Use Grafana Loki MCP to get loki labels.

Frequently asked questions

It connects Grafana Loki MCP to MCP-compatible AI assistants such as Claude and Cursor, exposing 5 tools (Testing, query_loki, get_loki_labels, and more) that the assistant can call on your behalf. Instead of copying data back and forth by hand, the assistant works with Grafana Loki MCP directly.