loki mcp
An MCP interface that allows AI assistants to query and analyze Grafana Loki logs using LogQL, with support for authentication and various output formats.
An MCP interface that allows AI assistants to query and analyze Grafana Loki logs using LogQL, with support for authentication and various output formats.
Loki MCP Server is a Model Context Protocol (MCP) interface for querying Grafana Loki logs using logcli
. The server enables AI assistants to access and analyze log data from Loki directly.
To install Simple Loki MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @ghrud92/simple-loki-mcp --client claude
{
"mcpServers": {
"simple-loki": {
"command": "npx",
"args": ["-y", "simple-loki-mcp"],
"env": {
"LOKI_ADDR": "https://loki.sup.band"
}
}
}
}
git clone https://github.com/ghrud92/loki-mcp.git
cd loki-mcp
npm install
npm run build
Query logs from Loki with filtering options.
Parameters:
query
(required): Loki query string (LogQL)from
: Start timestamp (e.g. "2023-01-01T12:00:00Z")to
: End timestamp (e.g. "2023-01-01T13:00:00Z")limit
: Maximum number of logs to returnbatch
: Batch size for query resultsoutput
: Output format ("default", "raw", or "jsonl")quiet
: Suppress query metadataforward
: Display results in chronological orderRetrieve all values for a specific label.
Parameters:
label
(required): Label name to get values forRetrieve all available labels.
No parameters required.
You can configure Loki access using:
LOKI_ADDR
: Loki server address (URL)LOKI_USERNAME
: Username for basic authLOKI_PASSWORD
: Password for basic authLOKI_TENANT_ID
: Tenant ID for multi-tenant LokiLOKI_BEARER_TOKEN
: Bearer token for authenticationLOKI_BEARER_TOKEN_FILE
: File containing bearer tokenLOKI_CA_FILE
: Custom CA file for TLSLOKI_CERT_FILE
: Client certificate file for TLSLOKI_KEY_FILE
: Client key file for TLSLOKI_ORG_ID
: Organization ID for multi-org setupsLOKI_TLS_SKIP_VERIFY
: Skip TLS verification ("true" or "false")LOKI_CONFIG_PATH
: Custom path to config fileDEBUG
: Enable debug loggingAlternatively, create a logcli-config.yaml
file in one of these locations:
LOKI_CONFIG_PATH
~/.logcli-config.yaml
)Example config file:
addr: https://loki.example.com
username: user
password: pass
tenant_id: mytenant
Start the server:
npm start
For development:
npm run dev
# Run linter
npm run lint
# Fix linting issues
npm run lint:fix
# Run tests
npm run test
This project is licensed under the MIT License - see the LICENSE.md file for details.