Skip to main content
Glama

mpl_mcp_plot_chart

Create line, scatter, or bar charts from numerical data to visualize trends and patterns for analysis.

Instructions

Plots line/scatter/bar chart of given datavalues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
x_dataYes
y_dataYes
plot_typeNoline
labelsNo
titleNo
xlabelNo
ylabelNo
colorNoskyblue
saveNo
dpiNo
figsizeNo
gridNo
legendNo

Implementation Reference

  • The handler function `plot_chart` that implements the core logic for plotting line, scatter, or bar charts using matplotlib. It processes input data, creates the plot, customizes it, and returns a PNG image as FastMCP Image object.
    def plot_chart(
        x_data: List[Union[float, int]],
        y_data: Union[List[Union[float, int]], List[List[Union[float, int]]]],
        plot_type: str = "line",  # "line", "scatter", or "bar"
        labels: Optional[Union[str, List[str]]] = None,
        title: str = "",
        xlabel: str = "",
        ylabel: str = "",
        color: Union[str, List[str]] = "skyblue",
        save: bool = False,
        dpi: int = 200,
        figsize: Optional[List[Union[int, float]]] = None,
        grid: bool = True,
        legend: bool = False,
    ) -> Image:
        """
        Create a customizable plot with support for multiple plot types.
    
        Args:
            x_data: X-axis data points (1D array-like)
            y_data: Y-axis data points (1D or 2D array-like for multiple series)
            plot_type: Type of plot to create ("line", "scatter", or "bar")
            labels: Label or list of labels for the data series
            title: Plot title
            xlabel: Label for the x-axis
            ylabel: Label for the y-axis
            color: Color or list of colors for the plot elements
            save: If True, save the figure to a buffer
            dpi: Output image resolution (dots per inch, default: 200)
            figsize: List of width and height in inches
            grid: Whether to show grid lines
            legend: Whether to show legend
    
    
        Returns:
            FastMCP Image object with the plotted chart
        """
        # Convert inputs to numpy arrays for processing
        x = np.asarray(x_data, dtype=float)
        y = np.asarray(y_data, dtype=float)
    
        # Handle 1D y_data case by adding an extra dimension
        if y.ndim == 1:
            y = y.reshape(-1, 1)
    
        # Ensure x matches the number of data points in y
        if x.ndim == 1 and len(x) != y.shape[0]:
            x = np.tile(x, (y.shape[1], 1)).T
    
        # Handle labels — normalize to a list of strings
        if labels is None:
            labels_list: List[str] = [""] * y.shape[1]
        elif isinstance(labels, str):
            labels_list = [labels]
        else:
            labels_list = list(labels)
    
        # Handle colors
        if isinstance(color, str):
            color = [color] * y.shape[1]
    
        # Create figure with specified size using OO interface
        # Normalize figsize to a tuple of floats (matplotlib accepts floats or ints)
        if figsize and len(figsize) >= 2:
            figsize_vals = (float(figsize[0]), float(figsize[1]))
        else:
            figsize_vals = (6.0, 4.0)
    
        fig, ax = plt.subplots(figsize=figsize_vals, dpi=dpi)
    
        # Create the appropriate plot type
        for i in range(y.shape[1]):
            current_label = labels_list[i] if i < len(labels_list) else f"Series {i+1}"
            current_color = color[i % len(color)]
    
            if plot_type == "line":
                ax.plot(x, y[:, i], label=current_label, color=current_color)
            elif plot_type == "scatter":
                ax.scatter(x, y[:, i], label=current_label, color=current_color)
            elif plot_type == "bar":
                ax.bar(x, y[:, i], label=current_label, color=current_color)
            else:
                plt.close(fig)
                raise ValueError(f"Unsupported plot type: {plot_type}")
    
        # Customize the plot
        ax.set_title(title)
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
    
        if grid:
            ax.grid(True, linestyle="--", alpha=0.7)
    
        if legend and any(labels_list):
            ax.legend()
    
        # Save the plot to a buffer and close the figure
        buf = io.BytesIO()
        fig.savefig(buf, format="png", dpi=dpi, bbox_inches="tight")
        plt.close(fig)
        buf.seek(0)
    
        return Image(data=buf.read(), format="png")
  • Registration of the `plot_chart` tool in the FastMCP server instance `mpl_mcp`, which likely names it `mpl_mcp_plot_chart`.
    mpl_mcp.tool(plot_chart, description="Plots line/scatter/bar chart of given datavalues")
  • Type annotations and docstring in the `plot_chart` function define the input schema and output type (Image). Likely used by FastMCP for tool schema generation.
    def plot_chart(
        x_data: List[Union[float, int]],
        y_data: Union[List[Union[float, int]], List[List[Union[float, int]]]],
        plot_type: str = "line",  # "line", "scatter", or "bar"
        labels: Optional[Union[str, List[str]]] = None,
        title: str = "",
        xlabel: str = "",
        ylabel: str = "",
        color: Union[str, List[str]] = "skyblue",
        save: bool = False,
        dpi: int = 200,
        figsize: Optional[List[Union[int, float]]] = None,
        grid: bool = True,
        legend: bool = False,
    ) -> Image:
  • Import of the `plot_chart` handler function into the server.py for registration.
    from .core.plot_chart import plot_chart
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions plotting but doesn't explain what happens (e.g., displays plot, saves file, returns image data), whether it's interactive, what permissions are needed, or any side effects. For a tool with 13 parameters and no annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is extremely concise with a single, efficient sentence that front-loads the core functionality. There's no wasted verbiage, though this brevity comes at the cost of completeness.

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

Completeness2/5

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

Given the complexity (13 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain what the tool returns (plot display, file path, image data), how to interpret parameters, or behavioral details. This is inadequate for a multi-parameter plotting tool with specialized siblings.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for all 13 parameters. It only mentions 'datavalues' (implied x_data and y_data) and chart types (plot_type), ignoring 11 other parameters like labels, title, save, dpi, etc. This leaves most parameters undocumented and their purposes unclear.

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 verb ('plots') and resource ('chart of given datavalues'), specifying the chart types (line/scatter/bar). However, it doesn't explicitly differentiate from sibling tools like mpl_mcp_plot_barchart or mpl_mcp_plot_scatter, which appear to be specialized versions of this general plotting tool.

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

Usage Guidelines2/5

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

No guidance is provided about when to use this tool versus the specialized sibling tools (mpl_mcp_plot_barchart, mpl_mcp_plot_scatter, etc.). The description doesn't mention any prerequisites, context for usage, or alternatives, leaving the agent to guess based on tool names alone.

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/abhiphile/fermat-mcp'

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