Loki MCP Server
The Loki MCP Server enables querying and analyzing Grafana Loki logs using LogQL with various capabilities:
Query Loki logs: Submit LogQL queries with optional time ranges, batch size, and limits
Retrieve label information: Get all available labels and their specific values
Multiple output formats: Supports formatted logs, raw logs, and JSON lines format
Authentication: Supports basic auth, bearer tokens and other methods
Flexible configuration: Configure via environment variables or config files
API fallback: Automatically uses Loki HTTP API if
logcliis not available
Provides tools for querying Grafana Loki logs using LogQL, accessing label values and metadata, and analyzing log data with support for different output formats and filtering options.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Loki MCP Servershow me the last 10 error logs from the last hour"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Simple Loki MCP Server
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.
Features
Query Loki logs with full LogQL support
Get label values and metadata
Authentication and configuration support via environment variables or config files
Provides formatted results in different output formats (default, raw, JSON lines)
Automatic fallback to HTTP API when
logcliis not available in the environment
Related MCP server: Loki MCP Server
Prerequisites
Node.js v16 or higher
TypeScript
(Optional) Grafana Loki logcli installed and accessible in your PATH. If
logcliis not available, the server will automatically use the Loki HTTP API insteadAccess to a Loki server instance
Installation
Installing via Smithery
To install Simple Loki MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @ghrud92/simple-loki-mcp --client claudefor MCP
{
"mcpServers": {
"simple-loki": {
"command": "npx",
"args": ["-y", "simple-loki-mcp"],
"env": {
"LOKI_ADDR": "https://loki.sup.band"
}
}
}
}npm
Clone the repository:
git clone https://github.com/ghrud92/loki-mcp.git
cd loki-mcpInstall dependencies:
npm installBuild the project:
npm run buildAvailable MCP Tools
query-loki
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 order
get-label-values
Retrieve all values for a specific label.
Parameters:
label(required): Label name to get values for
get-labels
Retrieve all available labels.
No parameters required.
Configuration
You can configure Loki access using:
Environment Variables
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 logging
Note: When the client is using the HTTP API mode (when
logcliis not available), the same configuration parameters are used to authenticate and connect to the Loki server.
Config Files
Alternatively, create a logcli-config.yaml file in one of these locations:
Custom path specified by
LOKI_CONFIG_PATHCurrent working directory
Your home directory (
~/.logcli-config.yaml)
Example config file:
addr: https://loki.example.com
username: user
password: pass
tenant_id: mytenantUsage
Start the server:
npm startFor development:
npm run devImplementation Details
Automatic Fallback to HTTP API
The server will automatically check if logcli is installed and available in the environment:
If
logcliis available, it will be used for all queries, providing the full functionality of the CLI toolIf
logcliis not available, the server will automatically fall back to using the Loki HTTP API:No additional configuration is needed
The same authentication parameters are used for the HTTP API
Response formatting is consistent with the CLI output
Default limit of 1000 logs per query is applied in both modes
This automatic detection ensures that the server works seamlessly in different environments without manual configuration.
Development
# Run linter
npm run lint
# Fix linting issues
npm run lint:fix
# Run tests
npm run testLicense
This project is licensed under the MIT License - see the LICENSE.md file for details.
Available Tools
3 toolsget_labelsD
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_label_valuesD
| Name | Required | Description | Default |
|---|---|---|---|
| label | Yes | Label name to get values for |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
query_lokiD
| Name | Required | Description | Default |
|---|---|---|---|
| batch | No | Batch size for query results | |
| forward | No | Display results in chronological order | |
| from | No | Start timestamp in UTC (e.g. '2023-01-01T12:00:00Z'). Relative time expressions like '1h ago' are not supported. Use ISO 8601 format. | |
| limit | No | Maximum number of logs to return. Maximum value is 1000 | |
| output | No | Output format - valid values are 'default' (formatted log lines), 'raw' (unprocessed log lines), or 'jsonl' (JSON Lines format). Note: values like 'text' or 'json' are not supported. | |
| query | Yes | Loki query string | |
| quiet | No | Suppress query metadata | |
| to | No | End timestamp in UTC (e.g. '2023-01-01T13:00:00Z'). Relative time expressions like 'now' are not supported. Use ISO 8601 format. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
Each tool has a clearly distinct purpose: get_labels retrieves label names, get_label_values fetches values for a specific label, and query_loki performs log queries. There is no overlap or ambiguity between these functions.
All tool names follow a consistent verb_noun pattern with snake_case (get_labels, get_label_values, query_loki). The naming is predictable and uniform throughout the set.
With only 3 tools, the set feels thin for a Loki server, which typically handles log management and querying. While the tools cover basic operations, more functionality (e.g., log ingestion, stream management) might be expected.
The tool surface is severely incomplete for a Loki server. It lacks essential operations like pushing logs, managing log streams, configuring settings, or performing advanced queries, leaving significant gaps that could cause agent failures.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Query application logs, traces, and metrics from your AI coding assistant via Foam's MCP server.
MCP observability. Query live traffic, errors, duration, and alerts from your AI agent.
A paid remote MCP for AI SDK data query MCP, built to return verdicts, receipts, usage logs, and aud
The Grafbase MCP server sits in front of a GraphQL API and exposes an MCP protocol-compliant interface that allows AI agents and LLMs to explore and query GraphQL APIs using natural language. It provides tools to search schemas, introspect types and fields, and execute GraphQL queries while minimizing context bloat by returning only relevant schema subsets, with built-in support for authentication, authorization, and configurable access control.
Related MCP Servers
- AlicenseAqualityDmaintenanceA server that enables AI assistants to access and query Grafana dashboards, metrics, logs, and configurations through an MCP protocol interface.106MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI models to query and analyze Kubernetes cluster logs through Grafana Loki, supporting semantic operations like error aggregation and pod restart detection. It provides tools for regex-based log searching and namespace discovery to facilitate natural language troubleshooting.
- AlicenseNot gradedqualityDmaintenanceThis MCP server enables natural-language querying of Grafana logs by automatically detecting log sources and service labels. It provides read-only access to log data with intelligent caching for efficient repeat queries.35MIT
- FlicenseNot gradedqualityFmaintenanceAn MCP server that enables AI assistants to query and analyze logs from Grafana Loki using LogQL, supporting label discovery and keyword search.4
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ghrud92/simple-loki-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server