Skip to main content
Glama

Query a datasource

query_datasource
Read-onlyIdempotent

Run read-only queries against Grafana datasources using unified API. Supports PromQL, LogQL, and SQL to retrieve result frames.

Instructions

Run a query against a datasource through Grafana's unified query API and return the result frames. For Prometheus/Loki set expr (PromQL / LogQL); for SQL datasources set rawSql. Reading data only — this never mutates anything. Use a bounded time range and a small maxDataPoints to keep results manageable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toNoRange end, e.g. 'now'. Default now.
exprNoPromQL or LogQL expression, e.g. 'up' or 'rate(http_requests_total[5m])'.
fromNoRange start, e.g. 'now-1h' or an epoch ms string. Default now-1h.
rawSqlNoSQL for SQL datasources (a single read-only SELECT).
datasourceUidYesDatasource UID (from list_datasources).
maxDataPointsNoCap on returned points. Default 100.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.0

TDQS

A4.2/5.0
Behavior3/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true and destructiveHint=false, so 'Reading data only — this never mutates anything' largely restates structured data. It does add one useful behavioral fact (results come back as result frames) and performance guidance about bounding time range/maxDataPoints, but says nothing about auth needs, rate limits, or error behavior for a mutating-adjacent remote call.

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?

Three sentences, front-loaded with the core action, then dialect-specific parameter selection, then a practical constraint. No filler; every clause carries actionable information.

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

Completeness4/5

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

For a query tool with full schema coverage and read-only/idempotent annotations, the description covers purpose, parameter selection, and safety sufficiently; with no output schema, the brief mention of 'result frames' is adequate but thin. Minor omission: no guidance on result size, pagination, or failure modes.

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, but the description adds the conditional mapping between expr (PromQL/LogQL) and rawSql (SQL) that the schema documents only in isolation. It does not clarify from/to formatting or maxDataPoints tradeoffs beyond what the schema already states.

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?

States a specific verb and resource ('Run a query against a datasource through Grafana's unified query API and return the result frames'), and the sibling set (list_*/get_* tools) is clearly non-overlapping, so the agent can route here without ambiguity. It also names the two query dialects it supports, which sharpens what 'query' means.

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

Usage Guidelines4/5

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

Explicitly tells the agent which parameter to use per datasource family ('for Prometheus/Loki set expr ... for SQL datasources set rawSql') and advises a bounded time range with small maxDataPoints. It lacks any when-not-to-use or alternative-tool routing, but no sibling overlaps this capability.

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