{
  "openapi": "3.1.1",
  "info": {
    "title": "Math Workbench API",
    "version": "1.0.0",
    "summary": "Simplify, factor, differentiate, integrate, solve, take limits, series and plots in one box.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://mathworkbench.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Simplify, factor, differentiate, integrate, solve, take limits, series and plots in one box.",
        "description": "A small computer algebra system: type commands such as \"integrate x*e^x from 0 to 1\", \"derivative sin(x)^2\", \"solve x^2 - 5x + 6 = 0\", \"limit sin(x)/x as x -> 0\" or \"series cos(x) at 0 order 6\". Results are exact (fractions, roots, π) where possible, and the tool says clearly when it falls back to a numeric answer.\n\nMethodology:\n- Input is tokenised and parsed with a Pratt parser that understands implicit multiplication (2x, 3(x+1), x sin x), powers of functions (sin^2(x)), |x| and the usual functions; log means the natural logarithm, log10/log2 are explicit.\n- All numbers are exact fractions (BigInt rationals); expressions are kept in a canonical form (like terms collected, powers merged, exact values of roots and special angles).\n- Derivatives use the sum, product, power and chain rules. Integrals use a table of standard forms, linearity, substitution, integration by parts, partial fractions and the e^(ax)·sin(bx) formula; every antiderivative is verified by differentiating it numerically at several points.\n- Definite integrals use F(b) − F(a) when an antiderivative exists and the integrand has no singularity inside the interval, cross-checked by adaptive Simpson (or tanh–sinh quadrature for endpoint singularities and infinite ranges); otherwise the numeric value is shown and labelled as such.\n- Limits try direct substitution, then L’Hôpital’s rule on 0/0 and ∞/∞ quotients, degree comparison at infinity, and finally numeric one-sided evaluation with extrapolation (marked as numeric).\n- Equations: linear, quadratic, rational, radical and higher polynomial equations (rational root theorem, then Durand–Kerner for the rest); systems of linear equations by exact Gaussian elimination.\n\nA compact computer algebra system, not a full replacement for Mathematica or SymPy: some simplifications (e.g. most trigonometric identities) are not applied, and numeric fallbacks are approximations.",
        "tags": [
          "math"
        ],
        "x-mcp-tool": "math_workbench",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MathWorkbenchInput"
              },
              "examples": {
                "example1": {
                  "summary": "Definite integral by parts",
                  "value": {
                    "query": "integrate x*e^x from 0 to 1"
                  }
                },
                "example2": {
                  "summary": "Second derivative",
                  "value": {
                    "query": "d^2/dx^2 sin(x)^2"
                  }
                },
                "example3": {
                  "summary": "Solve a quadratic",
                  "value": {
                    "query": "solve 2x^2 + 3x - 4 = 0"
                  }
                },
                "example4": {
                  "summary": "Classic limit",
                  "value": {
                    "query": "limit (1 - cos(x))/x^2 as x -> 0"
                  }
                },
                "example5": {
                  "summary": "Taylor series",
                  "value": {
                    "query": "series ln(1+x) at 0 order 5"
                  }
                },
                "example6": {
                  "summary": "Factor a polynomial",
                  "value": {
                    "query": "factor x^4 - 5x^2 + 4"
                  }
                },
                "example7": {
                  "summary": "Plot two functions",
                  "value": {
                    "query": "plot sin(x), x - x^3/6 from -4 to 4"
                  }
                },
                "example8": {
                  "summary": "Integral without elementary antiderivative",
                  "value": {
                    "query": "integrate e^(-x^2) from 0 to 2"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MathWorkbenchResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "MathWorkbenchInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "query": {
            "title": "Command",
            "description": "Commands: simplify, expand, factor, derivative (or d/dx), integrate [from a to b], solve, limit … as x -> a, evaluate … at x = 2, series … at a order n, plot f, g from a to b. Use * or juxtaposition for products (2x), ^ for powers, sqrt(), ln(), log10(), sin(), e, pi.",
            "type": "string",
            "maxLength": 2000
          }
        },
        "required": [
          "query"
        ]
      },
      "MathWorkbenchResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "command",
              "input",
              "variable",
              "result",
              "latex",
              "numeric",
              "symbolic",
              "method",
              "steps",
              "items",
              "notes"
            ],
            "properties": {
              "command": {
                "type": "string",
                "enum": [
                  "simplify",
                  "expand",
                  "factor",
                  "derivative",
                  "integrate",
                  "solve",
                  "limit",
                  "evaluate",
                  "series",
                  "plot"
                ]
              },
              "input": {
                "type": "string",
                "description": "The parsed input in canonical plain-text form."
              },
              "variable": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "result": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Main result as plain text (null when nothing could be computed)."
              },
              "latex": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Main result as LaTeX."
              },
              "numeric": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Decimal value when the result is a single real number."
              },
              "symbolic": {
                "type": "boolean",
                "description": "True when the result is exact/symbolic, false for numeric approximations."
              },
              "method": {
                "type": "string"
              },
              "steps": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "items": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "label",
                    "text",
                    "latex",
                    "numeric"
                  ],
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "text": {
                      "type": "string"
                    },
                    "latex": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "numeric": {
                      "type": [
                        "number",
                        "null"
                      ]
                    }
                  }
                }
              },
              "notes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}