Grafana MCP Server
Provides a tool to search Grafana Loki logs using LogQL queries, with configurable lookback hours, result limits, and Markdown or JSON response formats.
Click on "Deploy 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., "@Grafana MCP Server Find 5xx errors in production 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.
Grafana MCP Server
MCP (Model Context Protocol) server for querying Grafana Loki logs. Enables Claude to search your logs using natural language.
Features
🔍 Search logs using LogQL query language
⏰ Time-based filtering (hours back from now)
📊 Configurable result limits
📝 Markdown or JSON response formats
🔐 Secure API key authentication
Related MCP server: Loki MCP Server
Installation
Option 1: Local Development (Use from cloned repo)
Setup:
# Clone and build
git clone https://github.com/alludium/grafana-mcp-server.git
cd grafana-mcp-server
npm install
npm run buildFor Claude Desktop - Add to your claude_desktop_config.json:
{
"mcpServers": {
"grafana": {
"command": "node",
"args": ["/absolute/path/to/grafana-mcp-server/dist/index.js"],
"env": {
"GRAFANA_URL": "https://your-grafana-instance.com",
"GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
}
}
}
}For Claude Code - Add to .claude/config.json in your project:
{
"mcpServers": {
"grafana": {
"command": "node",
"args": ["/absolute/path/to/grafana-mcp-server/dist/index.js"],
"env": {
"GRAFANA_URL": "https://your-grafana-instance.com",
"GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
}
}
}
}Option 2: npm Package (When published)
For Claude Desktop - Add to your claude_desktop_config.json:
{
"mcpServers": {
"grafana": {
"command": "npx",
"args": ["-y", "@alludium/grafana-mcp-server"],
"env": {
"GRAFANA_URL": "https://your-grafana-instance.com",
"GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
}
}
}
}For Claude Code - Add to .claude/config.json in your project:
{
"mcpServers": {
"grafana": {
"command": "npx",
"args": ["-y", "@alludium/grafana-mcp-server"],
"env": {
"GRAFANA_URL": "https://your-grafana-instance.com",
"GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
}
}
}
}Set your API key in your environment:
export GRAFANA_API_KEY="your_grafana_api_key"Usage
Once configured, you can ask Claude to search logs naturally:
"Search our production logs for 5xx errors in the last hour"
"Find all database timeout errors from the last 24 hours"
"Show me errors in the auth service from the last 30 minutes"Direct LogQL Queries
You can also provide specific LogQL queries:
"Search logs with query: {app=\"web\"} |= \"error\""
"Query: {job=\"api\"} |~ \"timeout|failed\" for the last 6 hours"Tool: search_logs
Search Grafana Loki logs using LogQL query language.
Parameters:
query(string, required): LogQL query stringExample:
{app="web"} |= "error"
hours(number, optional): Hours to search back from now (default: 1)limit(number, optional): Maximum number of log lines (default: 100)response_format(string, optional): "markdown" or "json" (default: "markdown")
Example:
{
"query": "{namespace=\"production\"} |~ \"5[0-9]{2}\"",
"hours": 24,
"limit": 50,
"response_format": "markdown"
}Configuration
Environment Variables
GRAFANA_URL: Your Grafana instance URL (e.g.,https://grafana.example.com)GRAFANA_API_KEY: API key with read access to Loki
Getting a Grafana API Key
Log in to your Grafana instance
Go to Configuration → API Keys
Click "New API Key"
Name: "MCP Server" or similar
Role: Viewer (read-only access is sufficient)
Copy the generated key
Development
# Clone the repository
git clone https://github.com/alludium/grafana-mcp-server.git
cd grafana-mcp-server
# Install dependencies
npm install
# Set environment variables
cp .env.example .env
# Edit .env with your Grafana URL and API key
# Run in development mode
npm run dev
# Build
npm run build
# Run built version
npm startLogQL Query Examples
# All errors from web app
{app="web"} |= "error"
# 5xx HTTP errors
{job="api"} | json | status >= 500
# Pattern matching for timeouts or failures
{service="backend"} |~ "timeout|failed"
# Specific time range with filters
{namespace="production", app="auth"} |= "login" | json | status != 200License
MIT
Author
Alludium
Available Tools
1 toolsearch_logsC
Search Grafana Loki logs using LogQL query language. Returns log entries matching the query within the specified time range.
Inputs: query (required), hours, limit, response_format.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 1 tool
With only a single tool exposed, there is no possibility of tool confusion or misselection. The one tool has a clear, specific purpose (LogQL log search).
The single name search_logs follows a clear verb_noun snake_case convention, which is a good choice for a Grafana tool. Consistency cannot be fully demonstrated with only one tool, so it falls short of a 5.
A single tool is far too thin for a server branded as a general 'Grafana MCP Server', which implies dashboards, alerts, datasources, and metrics. One narrowly scoped log-search tool does not earn the server's stated scope.
The surface covers only log search; there is no way to list or query dashboards, Prometheus metrics, alerts, or datasources. Even within logs, there is no metadata/discovery tool, leaving agents with dead ends for most Grafana workflows.
Maintenance
Related MCP Connectors
Search logs, metrics, traces, alerts and incidents in Epok observability from your AI agent.
Ingest and search LogsLoom logs from coding agents.
Search dashboards, query data sources, list alert rules; add annotations in Grafana.
Lets AI agents analyze API metrics, request logs, and traces, and manage apps and alerts.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables querying and formatting Loki logs from Grafana via the Model Context Protocol. It supports LogQL queries, label retrieval, and provides results in text, JSON, or markdown formats.750 PyPI29MIT
- 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.-
- AlicenseAqualityCmaintenanceEnables read-only querying of Grafana Loki logs through tools like label discovery, LogQL queries, and recent log retrieval, without requiring knowledge of the Loki API.4MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query Grafana dashboards, alerts, and datasources for observability insights and incident investigation.MIT