Home/Tools/solve_equation

Solve equation

Analytically solve a single equation for a variable. Accepts 'lhs = rhs' or an expression equal to zero.

Endpoint: POST /api/v1/solve_equation

When to use

Solve a single algebraic or transcendental equation for one variable. Accepts `lhs = rhs` or an expression assumed equal to zero.

Input schema

Validated server-side with Zod. The same schema feeds OpenAPI and the MCP tool list.

{
  "type": "object",
  "properties": {
    "equation": {
      "type": "string",
      "minLength": 1,
      "description": "Equation to solve, e.g. 'x^2 - 5x + 6 = 0' or 'x^2 - 4'"
    },
    "variable": {
      "type": "string",
      "minLength": 1,
      "description": "Variable to solve for, e.g. 'x'"
    }
  },
  "required": [
    "equation",
    "variable"
  ],
  "additionalProperties": false
}

Response shape

All tools return { ok: true, result } on success and { ok: false, error } on failure. The result object contains:

FieldTypeDescription
solutionsstring[]All solutions found, each as an expression string. Complex roots use `i`.

Example

Request

{
  "equation": "x^2 - 5*x + 6 = 0",
  "variable": "x"
}

Response

{
  "ok": true,
  "result": {
    "solutions": [
      "2",
      "3"
    ]
  }
}

curl

curl -X POST https://tools.aieo.se/api/v1/solve_equation \
  -H 'Content-Type: application/json' \
  -d '{"equation":"x^2 - 5*x + 6 = 0","variable":"x"}'

MCP call (JSON-RPC)

MCP clients call this tool as tools/call against /api/mcp:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "solve_equation",
    "arguments": {
      "equation": "x^2 - 5*x + 6 = 0",
      "variable": "x"
    }
  }
}

Common errors

  • Equation is unsolvable in closed form.
    Empty `solutions` array or a numerical approximation only.
  • Variable does not appear in the equation.
    `solutions` is empty.
    {
      "equation": "y + 1 = 0",
      "variable": "x"
    }
  • A required field is missing or has the wrong type.
    Zod validation error, e.g. `Required` or `Expected string, received number`.
  • Nerdamer cannot parse the expression (unbalanced parens, unknown function, stray characters).
    `Unexpected token …` or `… is not a valid expression`.