query_lokiLABSCO SUMMARY
Ask the logs a question in the same window as the code.
The label calls matter more than they look. LogQL is unwriteable unless you know which labels exist and what values they take, and both are one call away here.
What it is
A FastMCP server that queries Loki logs through a Grafana instance. Alongside the query itself it exposes the label names and values a LogQL query depends on, and a formatter that decides how results come back.
What you get
- Loki queried through the Grafana API
- The available label names listed
- The values a given label takes
- Results formatted as text, JSON or markdown
- A cap on characters per line so one enormous entry does not flood the response
- Both stdio and SSE transports
Requirements
Python 3.10 or newer, a Grafana instance, and a Grafana API key with permission to query Loki — set as GRAFANA_URL and GRAFANA_API_KEY, or passed as -u and -k. Install with pip install grafana-loki-mcp.
Setup effort
One command plus a key — pip install grafana-loki-mcp, then supply credentials
USE CASES
Chasing an error you just saw in production
Run the LogQL query against Loki and read the matching lines back.
Writing a query when you do not know the label names
List the labels, then the values one of them takes, before composing anything.
Pasting log evidence into a ticket
Return the results as markdown instead of raw text.
Keeping a noisy result readable
Cap the characters per line so a single huge log entry does not fill the response.
4 tools
Listed in project docs. Your client may show a different list.
get_loki_labelsget_loki_label_valuesformat_loki_resultsBEFORE YOU INSTALL
What to know first
Tools you get
4 tools named in the project's documentation.
Requires
- uvx on PATH
- Python 3.10+
- GRAFANA_API_KEY in your environment
INSTALLATION
Connect your client
Add the block to your client, or run the command directly.
Server setup
Configuration file
{
"mcpServers": {
"loki": {
"command": "uvx",
"args": [
"grafana-loki-mcp",
"-u",
"<YOUR_GRAFANA_URL>",
"-k",
"<YOUR_GRAFANA_API_KEY>"
]
}
}
}pip
pip install grafana-loki-mcp