Skip to main content
Glama
DrDroidLab

Grafana MCP Server

grafana_query_dashboard_panels

Query specific panels on Grafana dashboards to retrieve metrics data, supporting template variables and up to four panels simultaneously.

Instructions

Executes queries for specific dashboard panels. Can query up to 4 panels at once, supports template variables, optimizes metrics data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dashboard_uidYesDashboard UID
panel_idsYesList of panel IDs to query (max 4)
template_variablesNoTemplate variables for the dashboard

Implementation Reference

  • The core logic for querying Grafana dashboard panels, which fetches the dashboard definition, filters for requested panels, and executes panel-specific queries.
    def grafana_query_dashboard_panels(
        self,
        dashboard_uid: str,
        panel_ids: list[int],
        template_variables: Optional[dict[str, str]] = None,
    ) -> dict[str, Any]:
        """
        Executes queries for specific dashboard panels.
    
        Args:
            dashboard_uid: Dashboard UID
            panel_ids: List of panel IDs to query (max 4)
            template_variables: Template variables for the dashboard
    
        Returns:
            Dict containing panel data with optimized metrics
        """
        try:
            if len(panel_ids) > 4:
                raise ValueError("Maximum 4 panels can be queried at once")
    
            logger.info(f"Querying dashboard panels: {dashboard_uid}, panel_ids: {panel_ids}")
    
            # First get dashboard configuration
            dashboard_url = f"{self.__host}/api/dashboards/uid/{dashboard_uid}"
            dashboard_response = requests.get(
                dashboard_url,
                headers=self.headers,
                verify=self.__ssl_verify,
                timeout=20,
            )
    
            if dashboard_response.status_code != 200:
                raise Exception(f"Failed to fetch dashboard. Status: {dashboard_response.status_code}")
    
            dashboard_data = dashboard_response.json()
            dashboard = dashboard_data.get("dashboard", {})
    
            # Handle both old and new dashboard structures
            panels = dashboard.get("panels", [])
            if not panels:
                # Try to get panels from rows (newer dashboard structure)
                rows = dashboard.get("rows", [])
                for row in rows:
                    row_panels = row.get("panels", [])
                    panels.extend(row_panels)
    
            logger.info(f"Found {len(panels)} panels in dashboard")
    
            # Filter panels by requested IDs
            target_panels = [panel for panel in panels if panel.get("id") in panel_ids]
    
            if not target_panels:
                logger.warning(f"No panels found with IDs: {panel_ids}")
                logger.info(f"Available panel IDs: {[panel.get('id') for panel in panels]}")
                raise Exception(f"No panels found with IDs: {panel_ids}")
    
            logger.info(f"Found {len(target_panels)} target panels")
    
            # Execute queries for each panel
            panel_results = []
            for panel in target_panels:
                logger.info(f"Processing panel {panel.get('id')}: {panel.get('title', 'Unknown')}")
                panel_result = self._execute_panel_query(panel, template_variables or {})
                panel_results.append(
                    {
                        "panel_id": panel.get("id"),
                        "title": panel.get("title"),
                        "type": panel.get("type"),
                        "data": panel_result,
                    }
                )
    
            return {
                "status": "success",
                "dashboard_uid": dashboard_uid,
                "panel_ids": panel_ids,
                "template_variables": template_variables,
                "results": panel_results,
            }
    
        except Exception as e:
            logger.error(f"Error querying dashboard panels: {e!s}")
            raise e
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses behavioral traits such as batch querying ('up to 4 panels at once'), support for template variables, and optimization for metrics data. However, it lacks details on permissions, rate limits, error handling, or what 'optimizes metrics data' entails, leaving gaps in behavioral understanding.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and front-loaded, consisting of a single sentence that efficiently conveys key information: action, resource, constraints (max 4 panels), and features (template variables, optimization). Every part earns its place without redundancy or waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 parameters, nested objects, no output schema) and no annotations, the description is somewhat complete but has gaps. It covers the basic purpose and some behavioral aspects but lacks details on output format, error cases, or integration with sibling tools, making it adequate but not fully comprehensive for an agent to use correctly without trial.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents all parameters well. The description adds minimal value beyond the schema by implying the purpose of parameters (e.g., 'supports template variables' relates to template_variables), but doesn't provide additional syntax, format details, or constraints beyond what's in the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('Executes queries') and resources ('dashboard panels'), and distinguishes it from siblings like grafana_loki_query or grafana_promql_query by specifying it queries dashboard panels. However, it doesn't explicitly differentiate from grafana_get_dashboard_config, which might retrieve configuration rather than query data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by mentioning 'up to 4 panels at once' and 'supports template variables', suggesting it's for querying multiple panels with variables. However, it lacks explicit guidance on when to use this tool versus alternatives like grafana_promql_query for direct queries or grafana_fetch_dashboard_variables for variable retrieval, and no exclusions are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/DrDroidLab/grafana-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server