Skip to main content
Glama
kdqed
by kdqed

histogram

Create histogram visualizations from SQL query results on CSV, Parquet, or database sources. Generate distribution plots for data analysis and business intelligence.

Instructions

Run query against specified source and make a histogram 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
columnYesColumn name from SQL result to use for the histogram
colorNoOptional; column name from SQL result to use for drawing multiple colored histograms representing another dimension
nbinsNoOptional; number of bins

Implementation Reference

  • The main handler function for the 'histogram' tool. It takes source_id, query, column, optional color and nbins; executes the query, generates a histogram with plotly.express, converts to PNG image, returns ImageContent or error string.
    def histogram(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')
        ],
        column: Annotated[
            str, Field(description='Column name from SQL result to use for the histogram')
        ],
        color: Annotated[
            str | None, Field(description='Optional; column name from SQL result to use for drawing multiple colored histograms representing another dimension')
        ] = None,
        nbins: Annotated[
            int | None, Field(description='Optional; number of bins')
        ] = None,
    ) -> str | ImageContent:
        """
        Run query against specified source and make a histogram 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.histogram(df, x=column, color=color, nbins=nbins)
            fig.update_xaxes(autotickangles=[0, 45, 60, 90])
    
            return _fig_to_image(fig)
        except Exception as e:
            return str(e)
  • Pydantic Field descriptions and types defining the input schema for the histogram tool.
    def histogram(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')
        ],
        column: Annotated[
            str, Field(description='Column name from SQL result to use for the histogram')
        ],
        color: Annotated[
            str | None, Field(description='Optional; column name from SQL result to use for drawing multiple colored histograms representing another dimension')
        ] = None,
        nbins: Annotated[
            int | None, Field(description='Optional; number of bins')
        ] = None,
    ) -> str | ImageContent:
        """
  • Final MCP registration: creates ZaturnTools instance and registers all its tools (including histogram) to FastMCP server.
    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
  • Intermediate registration: adds histogram method to Visualizations.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,
        ]
  • Aggregates tools from Core and Visualizations (including histogram) into ZaturnTools.tools.
    from zaturn.tools import core, visualizations
    
    
    class ZaturnTools:
    
        def __init__(self, data_sources):
            self.tools = [
                *core.Core(data_sources).tools,
                *visualizations.Visualizations(data_sources).tools,
            ]
  • Helper function to convert Plotly figure to base64-encoded ImageContent for all 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,
        )
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the return format ('image of the plot') but doesn't describe error conditions, performance characteristics, data size limitations, or what happens with invalid queries. For a data visualization tool with complex parameters, this leaves significant behavioral gaps.

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 concise with 4 sentences that each serve a purpose: stating the core function, providing SQL syntax guidance, specifying table naming conventions, and describing the return value. It's front-loaded with the main purpose and avoids unnecessary repetition.

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 5 parameters with 100% schema coverage but no annotations and no output schema, the description provides adequate but incomplete context. It covers the basic operation and return format, but for a data visualization tool with sibling alternatives, it should better explain when this specific visualization type is appropriate and what behavioral constraints exist.

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 5 parameters thoroughly. The description adds minimal parameter semantics beyond the schema - it mentions using 'CSV'/'PARQUET' as table names which relates to source_id usage, but doesn't explain parameter interactions or provide additional context about how column, color, and nbins work together.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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: 'Run query against specified source and make a histogram using result' and 'This will return an image of the plot'. It specifies the verb (run query, make histogram) and resource (data source), but doesn't explicitly differentiate from siblings like bar_plot or density_heatmap beyond the histogram focus.

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 provides some usage context with SQL syntax details for csv/parquet sources and table naming conventions, which implies when to use this tool for histogram generation. However, it doesn't explicitly state when to choose histogram over alternatives like density_heatmap or bar_plot, nor does it mention prerequisites or exclusions.

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