loki_queryLABSCO SUMMARY
One tool, and the defaults do the work.
There is exactly one query tool here, which is the right shape for Loki: the interesting variation is in LogQL, not in the API surface. Setting the URL, tenant and credentials once in the environment means a question like "find error logs from the last hour" needs no connection details in the prompt, and the org parameter maps cleanly onto multi-tenant setups through the standard scope header.
What it is
A small Go MCP server for querying Grafana Loki. It runs over stdio for desktop clients, and can also start an HTTP server exposing an SSE endpoint for workflow tools such as n8n.
What you get
- A LogQL query with everything but the query string optional —
loki_query - Sensible defaults on the optional parameters:
startan hour ago,endnow,limit100 results - Multi-tenant support through an
orgparameter, sent as theX-Scope-OrgIDheader - Connection details supplied per call or read from the environment, so a natural-language question does not have to repeat them
- Both authentication styles — basic auth via
LOKI_USERNAMEandLOKI_PASSWORD, or a bearer token viaLOKI_TOKEN - An SSE endpoint at
/sseand an MCP endpoint at/mcpwhen run in HTTP mode, for tools that connect over the network rather than launching a process
Requirements
Go 1.16 or higher to build (go build -o loki-mcp-server ./cmd/server), or the Docker image, which the README calls the most reliable option because it packages the Go module and build caches the client would otherwise have to find. LOKI_URL defaults to http://localhost:3100; LOKI_ORG_ID, LOKI_USERNAME, LOKI_PASSWORD and LOKI_TOKEN set the defaults for tenant and authentication. HTTP mode listens on port 8080 unless SSE_PORT says otherwise. The project's own security note asks you to prefer token authentication over username and password where you can. Licensed MIT.
Setup effort
Build from source — git clone https://github.com/grafana/loki-mcp.git
USE CASES
Finding errors in the last hour
Ask in plain language with a LogQL selector; the time range and limit fall back to an hour ago and 100 results.
Querying one tenant in a shared Loki
Name the org in the request, or set the default in the environment — either way it goes out as X-Scope-OrgID.
Narrowing a noisy stream
Add a LogQL line filter to the selector and raise or lower the result limit for the window you care about.
Using it from an n8n workflow
Run it in HTTP mode and point the MCP Client Tools node at the SSE endpoint, then wire that into an agent node.
1 tool
Listed in project docs. Your client may show a different list.
BEFORE YOU INSTALL
What to know first
Tools you get
1 tool named in the project's documentation.
Requires
Go 1.16 or later
INSTALLATION
Connect your client
You clone this one yourself.
Server setup
git clone https://github.com/grafana/loki-mcp.git
cd loki-mcpMCP Clients
Claude Desktop — binary
go build -o loki-mcp-server ./cmd/server{
"mcpServers": {
"lokiserver": {
"command": "<YOUR_PATH_TO_LOKI_MCP_SERVER>",
"args": [],
"env": {
"LOKI_URL": "http://localhost:3100",
"LOKI_ORG_ID": "<YOUR_LOKI_ORG_ID>",
"LOKI_USERNAME": "<YOUR_LOKI_USERNAME>",
"LOKI_PASSWORD": "<YOUR_LOKI_PASSWORD>",
"LOKI_TOKEN": "<YOUR_LOKI_TOKEN>"
},
"disabled": false,
"autoApprove": [
"loki_query"
]
}
}
}<YOUR_PATH_TO_LOKI_MCP_SERVER> is the full path of the loki-mcp-server binary the build wrote into your clone. Set LOKI_URL to your Loki server and use either LOKI_USERNAME and LOKI_PASSWORD or LOKI_TOKEN. The file is ~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows and ~/.config/Claude/claude_desktop_config.json on Linux.
Cursor — Docker
docker build -t loki-mcp-server .{
"mcpServers": {
"loki-mcp-server": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"LOKI_URL=http://host.docker.internal:3100",
"-e",
"LOKI_ORG_ID=<YOUR_LOKI_ORG_ID>",
"-e",
"LOKI_USERNAME=<YOUR_LOKI_USERNAME>",
"-e",
"LOKI_PASSWORD=<YOUR_LOKI_PASSWORD>",
"-e",
"LOKI_TOKEN=<YOUR_LOKI_TOKEN>",
"loki-mcp-server:latest"
]
}
}
}Run the build inside your clone. LOKI_URL is your Loki server's address; http://host.docker.internal:3100 is a sample that reaches a Loki running on this computer.
n8n
docker build -t loki-mcp-server .
docker run -p 8080:8080 --rm -i loki-mcp-serverIn n8n, install the MCP Client Tools node and set its SSE Endpoint to:
http://<YOUR_SERVER_ADDRESS>:8080/sse<YOUR_SERVER_ADDRESS> is the address of the machine running the container.