Skip to main content
Glama

mpl_mcp_eqn_chart

Plot mathematical equations to visualize functions and relationships between variables. Generate charts with customizable axes, gridlines, and legends for analysis and presentation.

Instructions

Plots mathematical equations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
equationsYes
x_minNo
x_maxNo
num_pointsNo
titleNoEquation Plot
xlabelNox
ylabelNoy
gridNo
legendNo
figsizeNo
linewidthNo
linestyleNo-
alphaNo
dpiNo
saveNo

Implementation Reference

  • The eqn_chart function is the main handler for the mpl_mcp_eqn_chart tool, plotting mathematical equations using matplotlib and returning a PNG image.
    def eqn_chart(
        equations: Union[str, List[str]],
        x_min: Union[float, int] = -10.0,
        x_max: Union[float, int] = 10.0,
        num_points: Union[int, float] = 1000,
        title: str = "Equation Plot",
        xlabel: str = "x",
        ylabel: str = "y",
        grid: bool = True,
        legend: bool = True,
        figsize: List[Union[int, float]] = [10, 6],
        linewidth: Union[float, int] = 2.0,
        linestyle: str = "-",
        alpha: Union[float, int] = 1.0,
        dpi: Union[int, float] = 200,
        save: bool = False,
    ) -> Image:
        """
        Plot one or more mathematical equations on the same chart.
    
        Args:
            equations: Single equation string or list of equation strings (e.g., "x**2" or ["x**2", "sin(x)"])
            x_min: Minimum x-value for the plot
            x_max: Maximum x-value for the plot
            num_points: Number of points to generate for the plot
            title: Title of the plot
            xlabel: Label for the x-axis
            ylabel: Label for the y-axis
            grid: Whether to show grid lines
            legend: Whether to show legend
            figsize: Figure size (width, height) in inches
            linewidth: Width of the plot lines
            linestyle: Style of the plot lines
            alpha: Transparency of the plot lines
            dpi: Dots per inch for the output image
            save: If True, save the figure to a buffer
    
        Returns:
            Image: The image object containing the plot
        """
        # Create a config instance to allow arbitrary types
        _ = PlotConfig()
    
        # Rest of your function remains the same
        if isinstance(equations, str):
            equations = [equations]
    
        fig, ax = plt.subplots(figsize=(float(figsize[0]), float(figsize[1])), dpi=int(dpi))
        x = np.linspace(float(x_min), float(x_max), int(num_points))
    
        for eq in equations:
            eq_py = eq.replace("^", "**")
            eq_py = re.sub(r"(\W|^)([a-z]+)\(", r"\1np.\2(", eq_py)
    
            try:
                y = eval(
                    eq_py,
                    {
                        "x": x,
                        "np": np,
                        "sin": np.sin,
                        "cos": np.cos,
                        "tan": np.tan,
                        "exp": np.exp,
                        "log": np.log,
                        "sqrt": np.sqrt,
                        "pi": np.pi,
                        "e": np.e,
                    },
                )
    
                # Convert numpy arrays to lists for Pydantic compatibility
                if isinstance(y, np.ndarray):
                    y = y.tolist()
    
                ax.plot(
                    x,
                    y,
                    label=f"y = {eq}",
                    linewidth=float(linewidth),
                    linestyle=linestyle,
                    alpha=float(alpha),
                )
    
            except Exception as e:
                print(f"Error plotting equation '{eq}': {str(e)}")
                continue
    
        ax.set_title(title)
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
        ax.grid(grid)
    
        if (len(equations) > 1 or legend) and any(ax.lines):
            ax.legend()
    
        plt.tight_layout()
    
        # Always save to buffer for the return value
        buf = io.BytesIO()
        plt.savefig(buf, format="png", dpi=int(dpi))
        plt.close()
        buf.seek(0)
    
        # If save is True, also save to a file
        if save:
            with open("equation_plot.png", "wb") as f:
                f.write(buf.getvalue())
            buf.seek(0)  # Reset buffer position after reading
    
        return Image(data=buf.read(), format="png")
  • The eqn_chart function is registered as a tool in the FastMCP server named mpl_mcp, likely resulting in the tool name mpl_mcp_eqn_chart.
    mpl_mcp.tool(eqn_chart, description="Plots mathematical equations")
  • Import of the eqn_chart handler into the server module for registration.
    from .core.eqn_chart import eqn_chart
Behavior1/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 but provides almost none. 'Plots mathematical equations' doesn't indicate whether this generates visual output, returns data, saves files, or has side effects. The 15 parameters suggest complex behavior, but the description gives no insight into what the tool actually produces, how it handles errors, whether it's idempotent, or any performance characteristics. For a tool with this many parameters and no annotations, the description is completely inadequate.

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 maximally concise at just two words. While this represents severe under-specification rather than ideal conciseness, from a pure structural perspective, there's no wasted language or unnecessary elaboration. Every word ('Plots mathematical equations') directly addresses the tool's function, making it technically efficient if inadequate in content.

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

Completeness1/5

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

The description is completely inadequate given the tool's complexity. With 15 parameters, no annotations, no output schema, and 11 sibling tools, the two-word description fails to provide the necessary context for an agent to understand when and how to use this tool effectively. It doesn't explain what the tool produces, how it differs from alternatives, what the parameters mean, or any behavioral characteristics. This is a high-complexity tool with minimal description.

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

Parameters1/5

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

With 15 parameters and 0% schema description coverage, the description provides zero information about any parameters. The schema has titles but no descriptions, so parameters like 'equations', 'x_min', 'figsize', 'save', etc. have no semantic explanation. The description doesn't mention any parameters, their purposes, or how they interact. For a tool with this many undocumented parameters, the description fails completely to compensate for the schema coverage gap.

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

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Plots mathematical equations' is a tautology that essentially restates the tool name 'mpl_mcp_eqn_chart'. While it indicates the general domain (plotting equations), it lacks specificity about what distinguishes this tool from its many siblings, particularly other plotting tools like 'mpl_mcp_plot_chart' or equation-related tools like 'sympy_mcp_equation_operation'. The description doesn't clarify if this is for 2D plots, what types of equations it handles, or how it differs from other visualization tools.

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

Usage Guidelines1/5

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

The description provides absolutely no guidance on when to use this tool versus alternatives. With 11 sibling tools including multiple plotting tools (barchart, scatter, stack, stem, general chart) and equation operation tools, the agent has no information about when this specific equation plotting tool is appropriate versus other visualization or mathematical tools. There's no mention of prerequisites, typical use cases, or comparison to siblings.

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