Skip to main content
Glama
kdqed
by kdqed

bar_plot

Create bar charts from SQL query results on CSV, Parquet, or database sources to visualize data relationships and trends for analysis.

Instructions

Run query against specified source and make a bar 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
NameRequiredDescriptionDefault
source_idYesThe data source to run the query on
queryYesSQL query to run on the data source
xYesColumn name from SQL result to use for x-axis
yYesColumn name from SQL result to use for y-axis
colorNoOptional column name from SQL result to use as a 3rd dimension by splitting each bar into colored sections
orientationNoOrientation of the box plot, use 'v' for vertical (default) and 'h' for horizontal. Be mindful of choosing the correct X and Y columns as per orientationv

Implementation Reference

  • Core handler function for the 'bar_plot' tool. Runs an SQL query on a data source to fetch data, creates a bar plot using plotly.express with specified x, y columns, optional color and orientation, encodes the plot as a base64 PNG image, and returns it or an error string.
    def bar_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 as a 3rd dimension by splitting each bar into colored sections')
        ] = None,
        orientation: Annotated[
            str, Field(description="Orientation of the box plot, use 'v' for vertical (default) and 'h' for horizontal. Be mindful of choosing the correct X and Y columns as per orientation")
        ] = 'v',
    ) -> str | ImageContent:
        """
        Run query against specified source and make a bar 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.bar(df, x=x, y=y, color=color, orientation=orientation)
            fig.update_xaxes(autotickangles=[0, 45, 60, 90])
    
            return _fig_to_image(fig)
        except Exception as e:
            return str(e)
  • MCP server registration: Instantiates ZaturnTools and registers all its tools (including bar_plot) using FastMCP.add_tool.
    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
  • ZaturnTools class aggregates tools from core and visualizations.Visualizations (which includes bar_plot).
    def __init__(self, data_sources):
        self.tools = [
            *core.Core(data_sources).tools,
            *visualizations.Visualizations(data_sources).tools,
        ]
  • Visualizations class registers bar_plot in its self.tools list.
    def __init__(self, data_sources): 
        self.data_sources = data_sources
        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,
        ]
  • Helper function to convert plotly figure to MCP ImageContent (base64 PNG), used by bar_plot and other visualization tools.
    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,
        )
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it runs a query, creates a bar plot, uses DuckDB SQL syntax with specific table names, and returns an image. However, it lacks details on error handling, performance, or data size limitations that would be useful for an agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with four sentences, front-loaded with the core purpose, followed by technical details and output. It avoids redundancy, though the orientation parameter guidance could be more integrated, and every sentence contributes useful information.

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

Completeness3/5

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

Given the complexity of a 6-parameter tool with no annotations and no output schema, the description is moderately complete. It covers the main functionality and technical constraints, but lacks details on error cases, performance expectations, or how the image output is formatted, which would help an agent use it more effectively.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema by mentioning SQL syntax and table names, but does not provide additional meaning for parameters like x, y, or color beyond what's in their schema descriptions.

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 clearly states the tool's purpose with specific verbs ('run query', 'make a bar plot') and resources ('specified source', 'result'), and distinguishes it from siblings by focusing on bar plots specifically, unlike other visualization tools like scatter_plot or histogram.

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

Usage Guidelines3/5

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

The description implies usage by specifying SQL syntax and table names for different source types, but does not explicitly state when to use this tool versus alternatives like line_plot or histogram, nor does it provide exclusions or prerequisites beyond the technical details.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kdqed/zaturn'

If you have feedback or need assistance with the MCP directory API, please join our Discord server