Skip to main content
Glama
mgcrea

@mgcrea/mcp-grafana

by mgcrea

Grafana: Query

grafana_query
Read-only

Run raw queries against any Grafana datasource through /api/ds/query, including SQL, Elasticsearch, Tempo, and CloudWatch, or evaluate server-side expression queries over other results.

Instructions

Run raw queries against any datasource through /api/ds/query — for datasources with no dedicated tool (SQL, Elasticsearch, Tempo, CloudWatch…), or for server-side expressions over other queries ({"datasource": "__expr__", "type": "math", "expression": "$A / $B"}). Each query is the target object as it appears in a panel's JSON (grafana_get_dashboard view=panel shows one). Prefer grafana_query_prometheus / grafana_query_loki for those two, and grafana_run_panel_query to reproduce a panel. Dashboard variables are NOT filled in here.

Input Schema

NameRequiredDescriptionDefault
toNoRange end: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now.
fromNoRange start: now, now-1h, -30m, an RFC3339 timestamp (2026-01-31T12:00:00Z) or unix seconds/ms. Defaults to now-1h.
sortNoOrder of time series, applied before `limit` cuts: labels keeps the datasource's order; max/avg/last rank highest first, so a cut keeps the biggest.labels
viewNoFor time series. values: stats (min/max/avg/last) plus one value per step on a shared grid given by start and step, null where there was no sample. stats: the stats only, about a tenth of the size — use it to survey many series before reading a few.values
limitNoMaximum series, log lines or table rows per query (1-5000). Defaults to 100.
pointsNoTarget points per series (2-1000), from which the step is picked. Defaults to 60; a dashboard in a browser asks for ~1000, which is rarely worth the tokens.
queriesYesQuery objects, e.g. [{"refId": "A", "rawSql": "SELECT 1", "format": "table"}]. A query may carry its own "datasource" (uid string, or {"uid": ...}); refId defaults to A, B, C….
precisionNoSignificant digits to round fractional values to (whole numbers are never rounded). Defaults to 4; 0 returns the exact value.
datasourceNoDatasource uid or name, e.g. "prometheus" or "Loki". Defaults to the default datasource, for queries that name none. grafana_list_datasources lists them.
max_line_charsNoCut each log line at this many characters (50-20000). Defaults to 1000.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.7/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true and openWorldHint=true, so the core safety profile is covered. The description adds useful behavioral context: it names the raw endpoint, explains that queries are panel-JSON target objects, gives an expression example, and warns that dashboard variables are not substituted. It does not cover auth requirements or error behavior, but that is less critical given the annotations.

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 dense and front-loaded: it leads with the core action, then query-object semantics, then alternatives, then the variable caveat. Every sentence carries useful routing or behavioral information.

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

Completeness5/5

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

Given full parameter schema coverage, clear annotations, and no output schema, the description supplies what an agent needs: the endpoint behavior, query-object form, sibling alternatives, and the important variable-substitution limitation. No essential invocation context is missing.

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

Parameters4/5

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

Schema description coverage is 100%, so the baseline is 3. The description still adds conceptual meaning for the `queries` parameter by explaining that each query is the target object from a panel's JSON and by demonstrating server-side expressions with `__expr__`, which goes beyond the schema's example.

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

Purpose5/5

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

The description states a specific action (run raw queries), resource (any datasource), and endpoint (/api/ds/query), and clearly distinguishes this generic tool from dedicated siblings like grafana_query_prometheus and grafana_query_loki. It also calls out server-side expressions as a distinct use case.

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

Usage Guidelines5/5

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

It explicitly says when to use this tool (datasources with no dedicated tool, and __expr__ expressions) and when to prefer alternatives (grafana_query_prometheus, grafana_query_loki, grafana_run_panel_query). The caveat that dashboard variables are not filled in is a useful usage boundary.

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