Skip to main content
Glama
nbiish
by nbiish

solve

Solve equations for specific variables using symbolic mathematics. Input an equation and target variable to get the solution.

Instructions

Solve an equation for a variable

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYesEquation to solve (e.g., "x^2 = 4")
variableYesVariable to solve for

Implementation Reference

  • Handler function that processes the input equation by normalizing it to zero form, parses it using math.parse, solves for the specified variable using math.solve, converts solutions to strings, and handles errors.
    async ({ expression, variable }) => {
      try {
        // Convert equation to standard form (expression = 0)
        const sides = expression.split('=').map(s => s.trim());
        if (sides.length !== 2) {
          throw new Error('Invalid equation format. Use "expression = value"');
        }
        
        const equationNode = math.parse(`${sides[0]}-(${sides[1]})`);
        const solutions = math.solve(equationNode, variable);
        return solutions.map(sol => sol.toString());
      } catch (e) {
        return [`Error: ${e.message}`];
      }
    }
  • Schema definition for the 'solve' tool: input requires 'expression' (equation string) and 'variable' (string to solve for); output is an array of solution strings.
    {
      name: 'solve',
      description: 'Solve an equation for a variable',
      inputSchema: z.object({
        expression: z.string().describe('Equation to solve (e.g., "x^2 = 4")'),
        variable: z.string().describe('Variable to solve for')
      }),
      outputSchema: z.array(z.string()),
    },
  • index.js:340-365 (registration)
    Registration of the 'solve' tool using ai.defineTool, providing name, description, input/output schemas, and inline handler implementation.
    ai.defineTool(
      {
        name: 'solve',
        description: 'Solve an equation for a variable',
        inputSchema: z.object({
          expression: z.string().describe('Equation to solve (e.g., "x^2 = 4")'),
          variable: z.string().describe('Variable to solve for')
        }),
        outputSchema: z.array(z.string()),
      },
      async ({ expression, variable }) => {
        try {
          // Convert equation to standard form (expression = 0)
          const sides = expression.split('=').map(s => s.trim());
          if (sides.length !== 2) {
            throw new Error('Invalid equation format. Use "expression = value"');
          }
          
          const equationNode = math.parse(`${sides[0]}-(${sides[1]})`);
          const solutions = math.solve(equationNode, variable);
          return solutions.map(sol => sol.toString());
        } catch (e) {
          return [`Error: ${e.message}`];
        }
      }
    );
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'solve' implies a computational operation, the description doesn't specify what type of equations are supported (linear, polynomial, etc.), whether symbolic or numeric solutions are returned, error handling for unsolvable equations, or computational limitations. For a mathematical tool with no annotation coverage, this leaves significant behavioral gaps.

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 at just 5 words, with zero wasted language. It's front-loaded with the core purpose and contains no unnecessary elaboration. Every word earns its place by contributing essential information about the tool's function.

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 mathematical complexity implied by the sibling tools and the absence of both annotations and output schema, the description is insufficiently complete. It doesn't explain what format the solution is returned in, whether multiple solutions are possible, error conditions, or limitations of the solving capability. For a mathematical solving tool in this context, more completeness is needed.

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

Parameters3/5

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

Schema description coverage is 100%, with both parameters ('expression' and 'variable') well-documented in the schema. The description adds no additional parameter information beyond what the schema already provides. The baseline score of 3 reflects adequate parameter documentation entirely through the schema, with no value added by the description.

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 ('solve') and resource ('an equation'), and specifies the target ('for a variable'). It distinguishes from siblings like 'derivative' or 'integral' by focusing on solving equations rather than calculus operations. However, it doesn't explicitly differentiate from all mathematical siblings, keeping it at 4 rather than 5.

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. With 16 sibling tools including 'derivative', 'integral', 'limit', and various financial calculators, there's no indication of when solving equations is appropriate versus using other mathematical operations. No exclusions, prerequisites, or context for selection are mentioned.

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/nbiish/mcp-calc-tools'

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