Provides comprehensive integration with Grafana instances through 52 MCP tools across 8 categories, enabling programmatic interaction with dashboards, data sources, metrics, logs, alerting, and administrative functions including dashboard management, user/team administration, and incident response.
Enables execution of PromQL queries, exploration of metrics metadata, retrieval of labels and label values, time series discovery, and interactive query building for Prometheus data sources within Grafana.
Grafana MCP Server
A Model Context Protocol (MCP) server that provides AI-powered integration with Grafana instances. This server exposes Grafana's comprehensive functionality through standardized MCP tools, enabling programmatic interaction with dashboards, data sources, metrics, logs, alerting, and administrative functions.
Features
- 52 MCP Tools across 8 categories for complete Grafana integration
- Dashboard Management - Search, create, update, and analyze dashboards
- Prometheus Integration - Execute PromQL queries and explore metrics
- Loki Integration - Search logs with LogQL and manage log streams
- Alerting & Incident Response - Manage alert rules and notifications
- Administrative Tools - User, team, and organization management
- Security-First Design - Automatic credential sanitization and error categorization
- TypeScript Excellence - Full type safety with strict mode enabled
Installation
Prerequisites
- Node.js 18+ with ES modules support
- TypeScript 4.9+
- Access to a Grafana instance (v8.0+)
Setup
Configuration
Environment Variables
Create a .env
file or set these environment variables:
Authentication
The server supports multiple authentication methods:
- Service Account Tokens (Recommended)
- API Keys (Legacy)
- Basic Authentication
Usage
Development
Production
MCP Client Integration
Configure your MCP client (e.g., Claude Desktop) to use this server:
Available Tools
Dashboard Tools (8 tools)
search_dashboards
- Find dashboards by title, tags, or metadataget_dashboard_by_uid
- Retrieve complete dashboard detailsget_dashboard_panel_queries
- Extract queries from all panelsupdate_dashboard
- Create or update dashboardsget_dashboard_versions
- View dashboard version historyrestore_dashboard_version
- Restore to a specific versiondelete_dashboard
- Remove dashboards
Prometheus Tools (6 tools)
query_prometheus
- Execute PromQL queriesget_prometheus_metadata
- List available metricsget_prometheus_labels
- Get label namesget_prometheus_label_values
- Get values for specific labelsget_prometheus_series
- Find time seriesbuild_prometheus_query
- Interactive query builder
Loki Tools (6 tools)
query_loki
- Execute LogQL queriesget_loki_labels
- Get log stream labelsget_loki_label_values
- Get label valuesget_loki_series
- Find log seriesbuild_logql_query
- LogQL query builderget_loki_stats
- Ingestion statistics
Data Source Tools (4 tools)
list_datasources
- List all configured data sourcesget_datasource_by_uid
- Get specific data source detailstest_datasource
- Test data source connectivityquery_datasource
- Execute queries against any data source
Admin Tools (8 tools)
list_users
- List organization usersget_current_user
- Get current user infolist_teams
- List teamsget_team_by_uid
- Get team detailslist_folders
- List dashboard foldersget_folder_by_uid
- Get folder detailslist_api_keys
- List API keyslist_service_accounts
- List service accounts
Alerting Tools (8 tools)
list_alert_rules
- List all alert rulesget_alert_rule_by_uid
- Get specific alert rulecreate_alert_rule
- Create new alert rulesupdate_alert_rule
- Update existing rulesdelete_alert_rule
- Delete alert ruleslist_notification_channels
- List notification channelstest_notification_channel
- Test notification deliveryget_alert_history
- Query alert history
Examples
Dashboard Search
Prometheus Query
Loki Log Search
Architecture
Core Components
- MCP Server (
src/main.ts
) - Protocol handler and tool registry - HTTP Client (
src/http-client.ts
) - Grafana API communication - Services (
src/services/
) - Business logic for each Grafana area - Tools (
src/tools/
) - MCP tool definitions and handlers - Security (
src/security-utils.ts
) - Credential sanitization and error handling
Security Features
- Automatic Data Sanitization - All logs and errors sanitize sensitive data
- Error Categorization - User-safe vs internal error messaging
- TLS Support - Full certificate validation and client certificates
- Minimal Privilege - Tools operate with least required permissions
Deployment
Docker
Docker Compose
Development
Project Structure
NPM Scripts
Code Standards
- TypeScript Strict Mode - Full type safety enforcement
- ESLint Rules - Zero-error policy with comprehensive rules
- Prettier Formatting - Consistent code style
- Zod Validation - Runtime type checking for all inputs
- Security First - Automatic credential sanitization in all outputs
Testing
Monitoring
Debug Mode
Enable comprehensive logging for troubleshooting:
Debug output includes:
- HTTP request/response details (sanitized)
- Tool execution traces
- Error categorization details
- Performance metrics
Health Checks
The server provides health information through:
- Process exit codes
- Error logs with categorization
- Connection status monitoring
Contributing
We welcome contributions! Please see our contributing guidelines:
- Fork and Clone - Create your feature branch
- Code Standards - Follow TypeScript strict mode and ESLint rules
- Testing - Add tests for new functionality
- Security - Include security impact assessment
- Documentation - Update docs for new features
Pull Request Checklist
- All tests pass (
npm test
) - No ESLint errors (
npm run lint
) - Code formatted (
npm run format
) - TypeScript compiles (
npm run type-check
) - Documentation updated
- Security considerations addressed
License
[License information to be added]
Support
Common Issues
Connection Errors
- Verify
GRAFANA_URL
is correct and accessible - Check network connectivity and firewall rules
Authentication Failures
- Verify
GRAFANA_TOKEN
is valid and has required permissions - Check token expiration and regenerate if needed
Tool Registration Errors
- Ensure all custom tools use proper Zod schema validation
- Check that
zodToJsonSchema()
wrapper is used correctly
Getting Help
- Check the troubleshooting guide
- Review API documentation
- Open an issue for bugs or feature requests
Built with TypeScript, Zod, and the Model Context Protocol
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables AI-powered integration with Grafana instances through 52 MCP tools for dashboard management, Prometheus/Loki queries, alerting, and administrative functions. Supports complete Grafana functionality including metrics exploration, log analysis, and incident response through natural language.