Skip to main content
Glama

plot_multiple_functions

Plot multiple mathematical functions simultaneously on a single graph to compare relationships and visualize interactions between equations.

Instructions

Plots multiple functions on the same graph.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formulasYes
x_rangeNo
y_rangeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • src/main.py:198-198 (registration)
    Registers the 'plot_multiple_functions' tool using the @mcp.tool() decorator.
    @mcp.tool()
  • The main handler function that plots multiple mathematical functions on a single graph using SymPy's plotting capabilities. It processes each formula, appends series to a plot, saves to desktop, encodes as base64 data URI, and returns the image.
    async def plot_multiple_functions(
        ctx: MCPContext,
        formulas: List[str],
        x_range: Optional[List[float]] = [-10, 10],
        y_range: Optional[List[float]] = None,
    ) -> str:
        """Plots multiple functions on the same graph."""
        try:
            await ctx.progress.start(total=len(formulas) + 1, message="Starting multi-plot...")
            x = sympy.symbols('x')
            p = sympy.plot(show=False)
            
            for i, formula in enumerate(formulas):
                await ctx.progress.report(i + 1, message=f"Processing formula {i+1}: {formula}")
                expr = sympy.sympify(formula)
                line_label = formula
                line_color = f"C{i}"
                series = sympy.plot(expr, (x, x_range[0], x_range[1]), show=False, line_color=line_color, label=line_label)[0]
                p.append(series)
    
            if x_range:
                p.xlim = x_range
            if y_range:
                p.ylim = y_range
            
            p.legend = True
    
            # Save the plot to a file
            desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop')
            save_dir = os.path.join(desktop_path, 'Desmos-MCP')
            os.makedirs(save_dir, exist_ok=True)
            timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
            filename = f"multi_plot_{timestamp}.png"
            p.save(os.path.join(save_dir, filename))
    
            await ctx.progress.report(len(formulas) + 1, message="Encoding image...")
            buf = io.BytesIO()
            p.save(buf)
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            data_uri = f"data:image/png;base64,{img_base64}"
            
            await ctx.progress.end()
            return f"Successfully plotted {len(formulas)} functions. Image: {data_uri}"
    
        except Exception as e:
            await ctx.progress.end()
            return f"Error plotting multiple functions. Details: {e}"
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 but only states the basic action without details on output format, error handling, or performance traits. It doesn't mention whether the plot is interactive, saved, or displayed, nor does it cover rate limits or authentication needs, which are critical for a plotting tool.

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 sentence that directly states the tool's function without any fluff or redundancy. It is front-loaded and wastes no words, making it efficient for quick comprehension, though this brevity contributes to gaps in other dimensions.

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 tool's moderate complexity (3 parameters, no annotations, but with an output schema), the description is incomplete. It lacks details on parameter usage, behavioral traits, and differentiation from siblings, though the presence of an output schema mitigates the need to explain return values. This results in a minimally adequate but insufficiently informative description.

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?

The input schema has 0% description coverage, so the description must compensate but adds no parameter semantics beyond implying 'formulas' are plotted. It doesn't explain what 'formulas' entail (e.g., mathematical expressions), the format of 'x_range' and 'y_range' (e.g., arrays of two numbers), or default behaviors, leaving significant gaps in understanding.

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 with a specific verb ('plots') and resource ('multiple functions on the same graph'), making it immediately understandable. However, it doesn't explicitly distinguish itself from sibling tools like 'plot_math_function', which might handle single functions, leaving some ambiguity about when to choose one over the other.

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?

The description provides no guidance on when to use this tool versus alternatives, such as 'plot_math_function' for single functions or 'analyze_formula' for non-graphical analysis. It lacks explicit instructions on prerequisites, context, or exclusions, leaving the agent to infer usage based on the tool name 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/TheGrSun/Desmos-MCP'

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