{
  "openapi": "3.1.1",
  "info": {
    "title": "Weekly Meal Planner API",
    "version": "1.0.0",
    "summary": "Turn your pantry and its expiry dates into a 7-day dinner plan and a shopping list.",
    "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://weeklymealplanner.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Turn your pantry and its expiry dates into a 7-day dinner plan and a shopping list.",
        "description": "List what is in your fridge and cupboards (with quantities and best-before dates) and your preferences (vegetarian, vegan, pescatarian, maximum cooking time, ingredients to avoid). The planner picks one dinner per day from about 60 simple home-cooking recipes, using food that expires soonest first, and adds up a shopping list of everything still missing.\n\nMethodology:\n- Recipes come from a bundled editorial dataset of about 60 simple home-cooking dinners with ingredient quantities, cooking time and diet. Quantities are scaled linearly to the number of people.\n- Recipes are filtered by diet (vegan ⊂ vegetarian ⊂ pescatarian ⊂ everything), maximum cooking time and the ingredients to avoid.\n- Pantry names are matched to recipe ingredients after normalising plurals and common synonyms (e.g. eggs → egg, courgette → zucchini, spaghetti → pasta). kg and l are converted to g and ml.\n- Day by day, every remaining recipe gets a score: for each ingredient, the share covered by the pantry × an urgency weight (expires within 1 day: 6, 3 days: 4, 7 days: 2, later: 1, no date: 0.5) × 10, plus the share of that pantry item used up × urgency × 5, minus 3 for every ingredient that must be bought. The highest score wins (ties: dataset order); the pantry is then reduced by what the recipe uses.\n- Items past their best-before date on the cooking day are not used. A recipe is repeated only when every eligible recipe has already been planned.\n- The shopping list adds up all missing amounts per ingredient (pieces rounded up to whole pieces). Salt, pepper, cooking oil and water are assumed to be at home.",
        "tags": [
          "home-travel"
        ],
        "x-mcp-tool": "weekly_meal_planner",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WeeklyMealPlannerInput"
              },
              "examples": {
                "example1": {
                  "summary": "Use up spinach, eggs and chicken this week",
                  "value": {
                    "startDate": "2026-10-19",
                    "days": 7,
                    "servings": 2,
                    "diet": "any",
                    "maxMinutes": 45,
                    "pantry": [
                      {
                        "item": "Spinach",
                        "quantity": 250,
                        "unit": "g",
                        "expires": "2026-10-20"
                      },
                      {
                        "item": "Eggs",
                        "quantity": 6,
                        "unit": "pcs",
                        "expires": "2026-10-28"
                      },
                      {
                        "item": "Chicken breast",
                        "quantity": 300,
                        "unit": "g",
                        "expires": "2026-10-21"
                      },
                      {
                        "item": "Rice",
                        "quantity": 1,
                        "unit": "kg"
                      },
                      {
                        "item": "Onions",
                        "quantity": 4,
                        "unit": "pcs"
                      },
                      {
                        "item": "Canned tomatoes",
                        "quantity": 800,
                        "unit": "g"
                      },
                      {
                        "item": "Feta",
                        "quantity": 200,
                        "unit": "g",
                        "expires": "2026-10-23"
                      },
                      {
                        "item": "Pasta",
                        "quantity": 500,
                        "unit": "g"
                      }
                    ]
                  }
                },
                "example2": {
                  "summary": "Vegan, 5 days, max 30 minutes",
                  "value": {
                    "startDate": "2026-11-02",
                    "days": 5,
                    "servings": 3,
                    "diet": "vegan",
                    "maxMinutes": 30,
                    "pantry": [
                      {
                        "item": "Chickpeas",
                        "quantity": 800,
                        "unit": "g"
                      },
                      {
                        "item": "Broccoli",
                        "quantity": 400,
                        "unit": "g",
                        "expires": "2026-11-04"
                      },
                      {
                        "item": "Tofu",
                        "quantity": 400,
                        "unit": "g",
                        "expires": "2026-11-05"
                      },
                      {
                        "item": "Rice",
                        "quantity": 500,
                        "unit": "g"
                      }
                    ],
                    "exclude": [
                      "mushrooms"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WeeklyMealPlannerResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "WeeklyMealPlannerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "startDate": {
            "title": "First day",
            "description": "Default: today.",
            "type": "string",
            "format": "date"
          },
          "days": {
            "title": "Number of days",
            "type": "integer",
            "minimum": 1,
            "maximum": 14,
            "default": 7
          },
          "servings": {
            "title": "People per meal",
            "type": "integer",
            "minimum": 1,
            "maximum": 12,
            "default": 2
          },
          "diet": {
            "title": "Diet",
            "type": "string",
            "enum": [
              "any",
              "vegetarian",
              "vegan",
              "pescatarian"
            ],
            "default": "any"
          },
          "maxMinutes": {
            "title": "Maximum cooking time",
            "type": "integer",
            "minimum": 10,
            "maximum": 240,
            "default": 45,
            "x-unit": "min"
          },
          "pantry": {
            "title": "Pantry and fridge",
            "description": "Leave the quantity empty if you are not sure (counted as enough). Best-before dates make the planner use those items first.",
            "type": "array",
            "maxItems": 40,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "item": {
                  "title": "Item",
                  "type": "string",
                  "maxLength": 60
                },
                "quantity": {
                  "title": "Quantity",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100000
                },
                "unit": {
                  "title": "Unit",
                  "type": "string",
                  "enum": [
                    "g",
                    "kg",
                    "ml",
                    "l",
                    "pcs"
                  ],
                  "default": "pcs"
                },
                "expires": {
                  "title": "Best before",
                  "type": "string",
                  "format": "date"
                }
              },
              "required": [
                "item"
              ]
            }
          },
          "exclude": {
            "title": "Avoid these ingredients",
            "description": "One per line, e.g. mushrooms or feta. Recipes containing them are skipped.",
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 30
          }
        },
        "required": []
      },
      "WeeklyMealPlannerResult": {
        "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": [
              "startDate",
              "days",
              "servings",
              "diet",
              "plan",
              "shoppingList",
              "pantryUse",
              "stats",
              "datasetVersion"
            ],
            "properties": {
              "startDate": {
                "type": "string",
                "format": "date"
              },
              "days": {
                "type": "integer"
              },
              "servings": {
                "type": "integer"
              },
              "diet": {
                "type": "string"
              },
              "plan": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "day",
                    "date",
                    "weekday",
                    "recipeId",
                    "recipe",
                    "minutes",
                    "diet",
                    "usesFromPantry",
                    "toBuy",
                    "score"
                  ],
                  "properties": {
                    "day": {
                      "type": "integer"
                    },
                    "date": {
                      "type": "string"
                    },
                    "weekday": {
                      "type": "string"
                    },
                    "recipeId": {
                      "type": "string"
                    },
                    "recipe": {
                      "type": "string"
                    },
                    "minutes": {
                      "type": "integer"
                    },
                    "diet": {
                      "type": "string"
                    },
                    "usesFromPantry": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "item",
                          "amount",
                          "unit",
                          "daysToExpiry"
                        ],
                        "properties": {
                          "item": {
                            "type": "string"
                          },
                          "amount": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "unit": {
                            "type": "string"
                          },
                          "daysToExpiry": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          }
                        }
                      }
                    },
                    "toBuy": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "item",
                          "amount",
                          "unit"
                        ],
                        "properties": {
                          "item": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number"
                          },
                          "unit": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "score": {
                      "type": "number"
                    }
                  }
                }
              },
              "shoppingList": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "item",
                    "amount",
                    "unit",
                    "forDays"
                  ],
                  "properties": {
                    "item": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    },
                    "unit": {
                      "type": "string"
                    },
                    "forDays": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    }
                  }
                }
              },
              "pantryUse": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "item",
                    "unit",
                    "start",
                    "used",
                    "left",
                    "expires",
                    "status"
                  ],
                  "properties": {
                    "item": {
                      "type": "string"
                    },
                    "unit": {
                      "type": "string"
                    },
                    "start": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "used": {
                      "type": "number"
                    },
                    "left": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "expires": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "used up",
                        "partly used",
                        "not used",
                        "expires unused",
                        "expired before start",
                        "no recipe uses it"
                      ]
                    }
                  }
                }
              },
              "stats": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "candidateRecipes",
                  "expiringItems",
                  "expiringItemsUsed",
                  "shoppingItems",
                  "repeats"
                ],
                "properties": {
                  "candidateRecipes": {
                    "type": "integer"
                  },
                  "expiringItems": {
                    "type": "integer"
                  },
                  "expiringItemsUsed": {
                    "type": "integer"
                  },
                  "shoppingItems": {
                    "type": "integer"
                  },
                  "repeats": {
                    "type": "integer"
                  }
                }
              },
              "datasetVersion": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}