generate_chart
Run a read-only SQL query and render the results as a bar, line, or scatter chart image. Visualize data with optional series splitting for multi-trace comparisons.
Instructions
Run a read-only SQL query and render the result as a chart image (bar, line, or scatter). Subject to the same read-only safety guardrails as run_sql_query.
Returns an inline chart image on success. On failure (bad SQL, missing column, empty result, oversized render), returns an error dict instead -- check for an "error" key if the result isn't an image. (No static return-type annotation here: the mcp SDK's output-schema generation can't handle Image inside a Union type.)
Args: sql: A single read-only SQL statement producing the data to chart. Aggregate/group the data yourself for cleaner charts (e.g. GROUP BY category). chart_type: "bar", "line", or "scatter". x_column: Column name (from the query result) for the x-axis. y_column: Column name (from the query result) for the y-axis. series_column: Optional column to split into multiple series/ traces (e.g. one line per region). title: Optional chart title. Defaults to "{y_column} by {x_column}".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| title | No | ||
| x_column | Yes | ||
| y_column | Yes | ||
| chart_type | Yes | ||
| series_column | No |