{
  "openapi": "3.1.1",
  "info": {
    "title": "Repair or Replace API",
    "version": "1.0.0",
    "summary": "Fix it or buy new? The 50% rule plus a cost-per-year check, with a clear verdict.",
    "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://repairorreplace.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Fix it or buy new? The 50% rule plus a cost-per-year check, with a clear verdict.",
        "description": "Enter the age and expected lifespan of a broken item, the repair quote, the replacement price and running costs. The tool applies the common 50% rule of thumb and compares the cost per remaining year of repairing versus replacing, including the risk of another failure, and gives a reasoned verdict.\n\nMethodology:\n- 50% rule of thumb: if the repair quote is more than the threshold (default 50%) of the replacement price, replace; otherwise repair. This is a common heuristic, not a law or standard.\n- Expected extra repair cost = P(another failure) × next repair cost (defaults to the current quote).\n- Repair cost per year = (repair quote + expected extra repair cost) ÷ expected extra life + running cost of the old item per year.\n- Replace cost per year = replacement price ÷ lifespan of the new item + running cost of the new item per year.\n- Break-even repair quote = (replace cost per year − old running cost) × extra life − expected extra repair cost (floored at 0).\n- Final verdict follows the cost-per-year comparison, because it accounts for remaining life, failure risk and running costs; the 50% rule is shown as a cross-check.",
        "tags": [
          "everyday"
        ],
        "x-mcp-tool": "repair_or_replace",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RepairOrReplaceInput"
              },
              "examples": {
                "example1": {
                  "summary": "Washing machine with a failed drum bearing",
                  "value": {
                    "itemName": "Washing machine",
                    "currency": "EUR",
                    "itemAgeYears": 8,
                    "expectedLifespanYears": 11,
                    "replacementPrice": 550,
                    "repairQuote": 320,
                    "lifeAfterRepairYears": 3,
                    "runningCostOldPerYear": 75,
                    "runningCostNewPerYear": 55,
                    "failureProbabilityPercent": 35,
                    "ruleThresholdPercent": 50
                  }
                },
                "example2": {
                  "summary": "Laptop with a dead battery",
                  "value": {
                    "itemName": "Laptop",
                    "currency": "USD",
                    "itemAgeYears": 3,
                    "expectedLifespanYears": 6,
                    "replacementPrice": 1200,
                    "repairQuote": 150,
                    "lifeAfterRepairYears": 3,
                    "runningCostOldPerYear": 0,
                    "runningCostNewPerYear": 0,
                    "failureProbabilityPercent": 15,
                    "ruleThresholdPercent": 50
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepairOrReplaceResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "RepairOrReplaceInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "itemName": {
            "title": "Item",
            "type": "string",
            "maxLength": 80,
            "default": "Appliance"
          },
          "currency": {
            "title": "Currency",
            "description": "Shown in results only; no conversion is performed.",
            "type": "string",
            "maxLength": 8,
            "default": "EUR"
          },
          "itemAgeYears": {
            "title": "Age of the item",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 6,
            "x-unit": "years"
          },
          "expectedLifespanYears": {
            "title": "Typical lifespan",
            "description": "Typical total life of this kind of item; also used for the new one unless set below.",
            "type": "number",
            "minimum": 0.5,
            "maximum": 100,
            "default": 10,
            "x-unit": "years"
          },
          "replacementPrice": {
            "title": "Price of a new replacement",
            "type": "number",
            "minimum": 0.01,
            "default": 600
          },
          "repairQuote": {
            "title": "Repair quote",
            "type": "number",
            "minimum": 0,
            "default": 200
          },
          "lifeAfterRepairYears": {
            "title": "Expected extra life after repair",
            "type": "number",
            "minimum": 0.1,
            "maximum": 100,
            "default": 3,
            "x-unit": "years"
          },
          "newItemLifespanYears": {
            "title": "Lifespan of the new item (optional)",
            "type": "number",
            "minimum": 0.5,
            "maximum": 100,
            "x-unit": "years"
          },
          "runningCostOldPerYear": {
            "title": "Running cost of the old item",
            "description": "Energy, water, consumables.",
            "type": "number",
            "minimum": 0,
            "default": 0,
            "x-unit": "per year"
          },
          "runningCostNewPerYear": {
            "title": "Running cost of the new item",
            "type": "number",
            "minimum": 0,
            "default": 0,
            "x-unit": "per year"
          },
          "failureProbabilityPercent": {
            "title": "Chance of another failure after repair",
            "description": "Your estimate for the extra life period; an assumption, not a statistic.",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 30,
            "x-unit": "%"
          },
          "nextRepairCost": {
            "title": "Cost of that next repair (optional)",
            "description": "Defaults to the current repair quote.",
            "type": "number",
            "minimum": 0
          },
          "ruleThresholdPercent": {
            "title": "Rule-of-thumb threshold",
            "type": "number",
            "minimum": 1,
            "maximum": 100,
            "default": 50,
            "x-unit": "%"
          }
        },
        "required": [
          "replacementPrice",
          "repairQuote"
        ]
      },
      "RepairOrReplaceResult": {
        "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": [
              "itemName",
              "currency",
              "verdict",
              "rule50",
              "costPerYear",
              "breakEvenRepairQuote",
              "lifespanUsedPercent",
              "rulesAgree",
              "reasoning"
            ],
            "properties": {
              "itemName": {
                "type": "string"
              },
              "currency": {
                "type": "string"
              },
              "verdict": {
                "type": "string",
                "enum": [
                  "repair",
                  "replace"
                ]
              },
              "rule50": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "thresholdPercent",
                  "repairShareOfReplacementPercent",
                  "verdict"
                ],
                "properties": {
                  "thresholdPercent": {
                    "type": "number"
                  },
                  "repairShareOfReplacementPercent": {
                    "type": "number"
                  },
                  "verdict": {
                    "type": "string",
                    "enum": [
                      "repair",
                      "replace"
                    ]
                  }
                }
              },
              "costPerYear": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "repair",
                  "replace",
                  "difference",
                  "verdict",
                  "expectedExtraRepairCost",
                  "newItemLifespanYears"
                ],
                "properties": {
                  "repair": {
                    "type": "number",
                    "description": "(repair quote + P(failure) × next repair cost) ÷ extra life + old running cost per year."
                  },
                  "replace": {
                    "type": "number",
                    "description": "replacement price ÷ new lifespan + new running cost per year."
                  },
                  "difference": {
                    "type": "number",
                    "description": "replace − repair (positive = repairing is cheaper per year)."
                  },
                  "verdict": {
                    "type": "string",
                    "enum": [
                      "repair",
                      "replace"
                    ]
                  },
                  "expectedExtraRepairCost": {
                    "type": "number"
                  },
                  "newItemLifespanYears": {
                    "type": "number"
                  }
                }
              },
              "breakEvenRepairQuote": {
                "type": "number",
                "description": "Highest repair quote at which repairing still costs no more per year than replacing (0 if repairing never pays)."
              },
              "lifespanUsedPercent": {
                "type": "number"
              },
              "rulesAgree": {
                "type": "boolean"
              },
              "reasoning": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}