line_plot
Visualize SQL query results as line plots on Zaturn. Input source ID, query, and axis columns; generate plots directly from CSV or Parquet data sources using DuckDB SQL syntax.
Instructions
Run query against specified source and make a line plot using result For both csv and parquet sources, use DuckDB SQL syntax Use 'CSV' as the table name in the SQL query for csv sources. Use 'PARQUET' as the table name in the SQL query for parquet sources.
This will return an image of the plot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| color | No | Optional; column name from SQL result to use for drawing multiple colored lines representing another dimension | |
| query | Yes | SQL query to run on the data source | |
| source_id | Yes | The data source to run the query on | |
| x | Yes | Column name from SQL result to use for x-axis | |
| y | Yes | Column name from SQL result to use for y-axis |
Implementation Reference
- zaturn/tools/visualizations.py:87-121 (handler)The core handler function for the 'line_plot' tool. It runs a SQL query on the specified data source, generates a line plot using Plotly Express (px.line), updates x-axis ticks, converts the figure to a base64 PNG image using _fig_to_image, and returns the ImageContent or an error string.def line_plot(self, source_id: Annotated[ str, Field(description='The data source to run the query on') ], query: Annotated[ str, Field(description='SQL query to run on the data source') ], x: Annotated[ str, Field(description='Column name from SQL result to use for x-axis') ], y: Annotated[ str, Field(description='Column name from SQL result to use for y-axis') ], color: Annotated[ str | None, Field(description='Optional; column name from SQL result to use for drawing multiple colored lines representing another dimension') ] = None, ) -> str | ImageContent: """ Run query against specified source and make a line plot using result For both csv and parquet sources, use DuckDB SQL syntax Use 'CSV' as the table name in the SQL query for csv sources. Use 'PARQUET' as the table name in the SQL query for parquet sources. This will return an image of the plot """ try: df = self._get_df_from_source(source_id, query) fig = px.line(df, x=x, y=y, color=color) fig.update_xaxes(autotickangles=[0, 45, 60, 90]) return _fig_to_image(fig) except Exception as e: return str(e)
- Input schema for the line_plot tool, defined using Pydantic Annotated and Field for MCP tool introspection, including parameters: source_id, query, x, y, color.def line_plot(self, source_id: Annotated[ str, Field(description='The data source to run the query on') ], query: Annotated[ str, Field(description='SQL query to run on the data source') ], x: Annotated[ str, Field(description='Column name from SQL result to use for x-axis') ], y: Annotated[ str, Field(description='Column name from SQL result to use for y-axis') ], color: Annotated[ str | None, Field(description='Optional; column name from SQL result to use for drawing multiple colored lines representing another dimension') ] = None, ) -> str | ImageContent:
- zaturn/tools/visualizations.py:29-40 (registration)The line_plot method is registered by being included in the Visualizations class's self.tools list, making it available as an MCP tool when the instance is used.self.tools = [ self.scatter_plot, self.line_plot, self.histogram, self.strip_plot, self.box_plot, self.bar_plot, self.density_heatmap, self.polar_scatter, self.polar_line, ]
- zaturn/tools/__init__.py:6-10 (registration)Higher-level registration in ZaturnTools class, which aggregates tools from core and visualizations.Visualizations, including line_plot.def __init__(self, data_sources): self.tools = [ *core.Core(data_sources).tools, *visualizations.Visualizations(data_sources).tools, ]
- zaturn/mcp/__init__.py:89-95 (registration)Final MCP server registration: Instantiates ZaturnTools and adds all its tools (including line_plot) to the FastMCP server using Tool.from_function for schema inference.def ZaturnMCP(sources): zaturn_tools = ZaturnTools(sources) zaturn_mcp = FastMCP() for tool_function in zaturn_tools.tools: zaturn_mcp.add_tool(Tool.from_function(tool_function)) return zaturn_mcp
- zaturn/tools/visualizations.py:13-22 (helper)Helper function used by line_plot (and other plot tools) to convert Plotly figure to MCP ImageContent with base64 PNG data.def _fig_to_image(fig): fig_encoded = b64encode(fig.to_image(format='png')).decode() img_b64 = "data:image/png;base64," + fig_encoded return ImageContent( type = 'image', data = fig_encoded, mimeType = 'image/png', annotations = None, )