query_sql
Run raw SQL queries against ClickHouse, Postgres, MySQL, or MSSQL through Grafana and retrieve result rows. Use datasource UID from list_datasources to specify the target.
Instructions
Run raw SQL against a SQL-family datasource (ClickHouse, Postgres, MySQL, MSSQL) through Grafana and get rows back. Use list_datasources first to get the uid. Read-only by convention — use a Viewer credential.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"datasourceUid": "<datasourceUid>",
"sql": "<sql>"
},
"name": "query_sql"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | Range end, e.g. "now" | now |
| sql | Yes | The SQL to run. Use the database column names, e.g. snake_case, not the app-level ones. | |
| from | No | Range start for $__timeFilter-style macros, e.g. "now-30d" or epoch ms | now-6h |
| datasourceUid | Yes | Datasource uid (or exact name) from list_datasources |