Skip to main content
Glama

solve

Solve equations for specific variables by inputting expressions and variables. Part of the MCP Calc Tools server, enabling AI assistants to handle complex mathematical calculations directly.

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

  • The handler function for the 'solve' tool. It processes the input equation by splitting on '=', parsing into a mathjs node as left - right = 0, solves for the variable using math.solve, maps solutions to strings, or returns error.
    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 including name, description, input schema (expression and variable strings), and output as array of 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 schema 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}`]; } } );

Other Tools

Related 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