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}"
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool validates syntax and provides 'intelligent help on failure', which adds behavioral context about error responses. However, it doesn't mention other traits like performance characteristics, rate limits, or authentication needs. The description adds some value but leaves gaps for a tool with mutation-like validation behavior.

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 a single, well-constructed sentence that efficiently communicates the core functionality and error-handling behavior. Every word earns its place, with no redundancy or unnecessary elaboration. It's appropriately sized for a simple validation tool.

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 has an output schema (which should document return values), the description doesn't need to explain outputs. However, with no annotations and incomplete parameter documentation, the description provides adequate but minimal context for a validation tool. It covers the 'what' and error behavior but lacks details on formula requirements or validation rules.

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, with only one parameter 'formula' of type string. The description doesn't add any parameter-specific semantics beyond the tool's overall purpose. It doesn't explain what constitutes a valid formula, expected format, or examples. With low schema coverage, the description fails to compensate adequately.

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: 'Validates the syntax of a mathematical formula' with the specific verb 'validates' and resource 'mathematical formula'. It distinguishes from siblings like 'analyze_formula' (which might check semantics) and 'plot_math_function' (which visualizes), but doesn't explicitly name these alternatives. The addition of 'offering intelligent help on failure' adds useful context about error handling.

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 implies usage context through 'validates the syntax' and 'on failure', suggesting it should be used to check formula correctness before further processing. However, it doesn't explicitly state when to use this vs. alternatives like 'analyze_formula' or provide clear exclusions. The guidance is present but not comprehensive.

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