Skip to main content
Glama

validate_formula

Check mathematical formula syntax for errors and receive guidance on corrections to ensure accurate plotting and computation.

Instructions

Validates the syntax of a mathematical formula, offering intelligent help on failure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formulaYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'validate_formula' tool. It is registered via the @mcp.tool() decorator. Validates mathematical formulas using sympy, provides success message or user-friendly error explanation using LLM sampling on failure.
    @mcp.tool()
    async def validate_formula(ctx: MCPContext, formula: str) -> str:
        """Validates the syntax of a mathematical formula, offering intelligent help on failure."""
        try:
            sympy.sympify(formula)
            return f"Formula '{formula}' is syntactically valid."
        except (sympy.SympifyError, SyntaxError) as e:
            technical_error = f"Details: {e}"
            ctx.info(f"Validation failed with technical error: {technical_error}")
    
            # Use LLM Sampling to get a user-friendly explanation
            try:
                sample_result = await ctx.sample(f"Please explain this Python sympy error in simple terms for a non-programmer: {technical_error}")
                user_friendly_error = sample_result.text
            except Exception as sample_err:
                ctx.error(f"LLM Sampling failed: {sample_err}")
                user_friendly_error = technical_error # Fallback to technical error
    
            # Elicit user confirmation with the friendly error
            return f"The formula '{formula}' is invalid. Here is an explanation: {user_friendly_error}"

Tool Definition Quality

Score is being calculated. Check back soon.

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