{
  "openapi": "3.1.1",
  "info": {
    "title": "Graphing Calculator API",
    "version": "1.0.0",
    "summary": "Plot up to 6 functions or parametric curves with roots, extrema, intersections and SVG/PNG export.",
    "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://graphingcalculator.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Plot up to 6 functions or parametric curves with roots, extrema, intersections and SVG/PNG export.",
        "description": "Graphs y = f(x) for up to six functions (or parametric curves x(t), y(t)) over the range you choose, lists the roots, local minima and maxima and the intersection points numerically, prints a table of values and offers the graph as SVG and PNG downloads.\n\nMethodology:\n- Each function is parsed by the shared CAS core and evaluated in double precision at 600 points; jumps across vertical asymptotes are broken instead of joined, and extreme values are clipped unless you set y min/max.\n- Roots: sign changes on a 4,000-point grid refined by bisection, plus touching roots (local minima of |f| that reach zero). Poles are excluded because |f| must be tiny at a root.\n- Extrema: the derivative is computed symbolically and its roots are found the same way; each critical point is classified by comparing neighbouring values (inflection points are skipped).\n- Intersections: roots of f_i − f_j for every pair of functions. All of these are numeric approximations (about 10 significant digits) and only cover the plotted range.\n- The graph is an accessible SVG (title, description, data table); the PNG is rasterised from the same SVG with ImageMagick.",
        "tags": [
          "math"
        ],
        "x-mcp-tool": "graphing_calculator",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GraphingCalculatorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Sine and a parabola",
                  "value": {
                    "functions": "y = sin(x)\ny = x^2/4 - 1",
                    "xMin": -5,
                    "xMax": 5
                  }
                },
                "example2": {
                  "summary": "Cubic with roots and extrema",
                  "value": {
                    "functions": "x^3 - 3x",
                    "xMin": -3,
                    "xMax": 3,
                    "tableStep": 0.5
                  }
                },
                "example3": {
                  "summary": "Parametric circle and Lissajous curve",
                  "value": {
                    "mode": "parametric",
                    "functions": "cos(t), sin(t)\nsin(3t), cos(2t)",
                    "tMin": 0,
                    "tMax": 6.283185307179586,
                    "png": false
                  }
                },
                "example4": {
                  "summary": "Rational function with asymptotes",
                  "value": {
                    "functions": "1/(x - 1)\nx/2",
                    "xMin": -4,
                    "xMax": 4,
                    "yMin": -6,
                    "yMax": 6,
                    "png": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GraphingCalculatorResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "GraphingCalculatorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "Graph type",
            "type": "string",
            "enum": [
              "functions",
              "parametric"
            ],
            "default": "functions"
          },
          "functions": {
            "title": "Functions (one per line)",
            "description": "Functions: \"y = x^2 - 2\" or just \"x^2 - 2\". Parametric: \"cos(t), sin(t)\" per line. Up to 6 lines.",
            "type": "string",
            "maxLength": 3000
          },
          "xMin": {
            "title": "x min",
            "type": "number",
            "default": -10
          },
          "xMax": {
            "title": "x max",
            "type": "number",
            "default": 10
          },
          "yMin": {
            "title": "y min",
            "description": "Optional; automatic (asymptotes are clipped) when empty.",
            "type": "number"
          },
          "yMax": {
            "title": "y max",
            "description": "Optional.",
            "type": "number"
          },
          "tMin": {
            "title": "t min (parametric)",
            "type": "number",
            "default": 0
          },
          "tMax": {
            "title": "t max (parametric)",
            "description": "Default 2π.",
            "type": "number",
            "default": 6.283185307179586
          },
          "tableStep": {
            "title": "Table step",
            "description": "Optional step for the table of values (default: a tenth of the range; at most 41 rows).",
            "type": "number",
            "minimum": 0
          },
          "analyze": {
            "title": "Find roots, extrema and intersections",
            "type": "boolean",
            "default": true
          },
          "png": {
            "title": "Also create a PNG download",
            "type": "boolean",
            "default": true
          }
        },
        "required": [
          "functions"
        ]
      },
      "GraphingCalculatorResult": {
        "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": [
              "mode",
              "domain",
              "curves",
              "intersections",
              "table",
              "svg",
              "png"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "functions",
                  "parametric"
                ]
              },
              "domain": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "min",
                  "max",
                  "variable"
                ],
                "properties": {
                  "min": {
                    "type": "number"
                  },
                  "max": {
                    "type": "number"
                  },
                  "variable": {
                    "type": "string"
                  }
                }
              },
              "curves": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "index",
                    "input",
                    "expression",
                    "latex",
                    "derivative",
                    "roots",
                    "extrema",
                    "yIntercept"
                  ],
                  "properties": {
                    "index": {
                      "type": "integer"
                    },
                    "input": {
                      "type": "string"
                    },
                    "expression": {
                      "type": "string"
                    },
                    "latex": {
                      "type": "string"
                    },
                    "derivative": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "roots": {
                      "type": "array",
                      "items": {
                        "type": "number"
                      }
                    },
                    "extrema": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "x",
                          "y",
                          "kind"
                        ],
                        "properties": {
                          "x": {
                            "type": "number"
                          },
                          "y": {
                            "type": "number"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "minimum",
                              "maximum"
                            ]
                          }
                        }
                      }
                    },
                    "yIntercept": {
                      "type": [
                        "number",
                        "null"
                      ]
                    }
                  }
                }
              },
              "intersections": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "a",
                    "b",
                    "x",
                    "y"
                  ],
                  "properties": {
                    "a": {
                      "type": "integer"
                    },
                    "b": {
                      "type": "integer"
                    },
                    "x": {
                      "type": "number"
                    },
                    "y": {
                      "type": "number"
                    }
                  }
                }
              },
              "table": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "columns",
                  "rows"
                ],
                "properties": {
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "rows": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": [
                          "number",
                          "null"
                        ]
                      }
                    }
                  }
                }
              },
              "svg": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "png": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}