{
  "openapi": "3.1.1",
  "info": {
    "title": "Aquarium Water Change and Dosing API",
    "version": "1.0.0",
    "summary": "Nitrate after each partial water change and the dose of conditioner or medication from the label.",
    "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://hearthwaterchange.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Nitrate after each partial water change and the dose of conditioner or medication from the label.",
        "description": "Shows how the nitrate level falls with repeated partial water changes — including the nitrate in your tap water and how much builds up between changes — how many changes reach your target, and how much water conditioner, fertiliser or medication to add for the tank or the new water, from the label values you type.\n\nMethodology:\n- Mass balance with complete mixing: after a change of the fraction f, nitrate = before × (1 − f) + f × nitrate of the new water. Between two changes the build-up you enter is added. The series settles at new-water nitrate + build-up × (1 − f) / f after each change.\n- One change to reach the target: f = (now − target) / (now − new water). n equal changes without build-up: f = 1 − ((target − new water) / (now − new water))^(1/n). A target at or below the new water’s nitrate cannot be reached by water changes.\n- Dose = label amount × litres ÷ label litres, for the whole water volume or for the new water of one change (water conditioners are usually dosed for the new water; follow the label).\n\nEstimates for planning water changes; measure with a test kit. Always follow the product label, and ask a vet or an aquarium specialist before medicating fish, shrimp or snails.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "hearth_water_change",
        "x-owner-app": "hearth",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HearthWaterChangeInput"
              },
              "examples": {
                "example1": {
                  "summary": "96 L tank, 40 → 20 mg/L with 25 % changes",
                  "value": {
                    "tankLitres": 96,
                    "changePercent": 25,
                    "changes": 4,
                    "currentNitrate": 40,
                    "tapNitrate": 10,
                    "targetNitrate": 20,
                    "buildUp": 5,
                    "products": [
                      {
                        "name": "Water conditioner",
                        "amount": 5,
                        "unit": "ml",
                        "perLitres": 100,
                        "basis": "new"
                      }
                    ]
                  }
                },
                "example2": {
                  "summary": "Medication for the whole tank",
                  "value": {
                    "tankLitres": 240,
                    "changePercent": 30,
                    "changes": 3,
                    "currentNitrate": 25,
                    "tapNitrate": 5,
                    "targetNitrate": 15,
                    "buildUp": 0,
                    "products": [
                      {
                        "name": "Medication",
                        "amount": 1,
                        "unit": "tablets",
                        "perLitres": 20,
                        "basis": "tank"
                      },
                      {
                        "name": "Conditioner",
                        "amount": 2,
                        "unit": "drops",
                        "perLitres": 4,
                        "basis": "new"
                      }
                    ]
                  }
                },
                "example3": {
                  "summary": "Tap water above the target",
                  "value": {
                    "tankLitres": 60,
                    "changePercent": 50,
                    "changes": 2,
                    "currentNitrate": 50,
                    "tapNitrate": 30,
                    "targetNitrate": 25,
                    "buildUp": 0,
                    "products": []
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HearthWaterChangeResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "HearthWaterChangeInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "tankLitres": {
            "title": "Water in the tank (litres)",
            "description": "The real water volume — the Aquarium Volume and Weight tool works it out.",
            "type": "number",
            "minimum": 0.5,
            "maximum": 100000,
            "default": 96
          },
          "changePercent": {
            "title": "Water changed each time (%)",
            "type": "number",
            "minimum": 1,
            "maximum": 100,
            "default": 25
          },
          "changes": {
            "title": "Number of changes to plan",
            "type": "integer",
            "minimum": 1,
            "maximum": 52,
            "default": 4
          },
          "currentNitrate": {
            "title": "Nitrate now (mg/L NO₃)",
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "default": 40
          },
          "tapNitrate": {
            "title": "Nitrate in the new water (mg/L NO₃)",
            "description": "Your water supplier publishes it; test kits show it too.",
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "default": 10
          },
          "targetNitrate": {
            "title": "Target nitrate (mg/L NO₃)",
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "default": 20
          },
          "buildUp": {
            "title": "Nitrate that builds up between two changes (mg/L)",
            "description": "Measure before and after a week; 0 ignores it.",
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "default": 5
          },
          "products": {
            "title": "Products to dose (from the label)",
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "title": "Product",
                  "type": "string",
                  "maxLength": 60
                },
                "amount": {
                  "title": "Label amount",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100000,
                  "default": 5
                },
                "unit": {
                  "title": "Unit",
                  "type": "string",
                  "enum": [
                    "ml",
                    "drops",
                    "g",
                    "tablets",
                    "capfuls",
                    "scoops"
                  ],
                  "default": "ml"
                },
                "perLitres": {
                  "title": "per … litres",
                  "type": "number",
                  "minimum": 0.01,
                  "maximum": 100000,
                  "default": 100
                },
                "basis": {
                  "title": "Dose for",
                  "type": "string",
                  "enum": [
                    "new",
                    "tank"
                  ],
                  "default": "new"
                }
              },
              "required": []
            },
            "default": [
              {
                "name": "Water conditioner",
                "amount": 5,
                "unit": "ml",
                "perLitres": 100,
                "basis": "new"
              }
            ]
          }
        },
        "required": []
      },
      "HearthWaterChangeResult": {
        "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": [
              "changeLitres",
              "series",
              "afterChanges",
              "levelsOffAt",
              "changesToTarget",
              "oneChangePercent",
              "equalPercentForTarget",
              "doses"
            ],
            "properties": {
              "changeLitres": {
                "type": "number"
              },
              "series": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "change",
                    "before",
                    "after"
                  ],
                  "properties": {
                    "change": {
                      "type": "integer"
                    },
                    "before": {
                      "type": "number"
                    },
                    "after": {
                      "type": "number"
                    }
                  }
                }
              },
              "afterChanges": {
                "type": "number"
              },
              "levelsOffAt": {
                "type": "number"
              },
              "changesToTarget": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "oneChangePercent": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "equalPercentForTarget": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "doses": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "amount",
                    "unit",
                    "basis",
                    "litres",
                    "dose"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    },
                    "unit": {
                      "type": "string"
                    },
                    "basis": {
                      "enum": [
                        "tank",
                        "new"
                      ]
                    },
                    "litres": {
                      "type": "number"
                    },
                    "dose": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}