{
  "openapi": "3.1.1",
  "info": {
    "title": "Pattern Matrix Puzzle Generator API",
    "version": "1.0.0",
    "summary": "Generate a 3 × 3 figure-matrix puzzle with 8 options and a checked, unique answer.",
    "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://mindquarrymatrixpuzzle.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Generate a 3 × 3 figure-matrix puzzle with 8 options and a checked, unique answer.",
        "description": "Builds a 3 × 3 matrix of figures whose last cell is missing, in the style of progressive-matrix puzzles: shape, number, fill and size follow rules along the rows (constant, step-by-step progression or each value once per row). Eight answer options are generated and the puzzle is only returned when an independent check finds exactly one option that fits every reading of the rules. Returns the puzzle as SVG, the answer, and the rules in plain words. These are practice puzzles, not an intelligence test.\n\nMethodology:\n- Attributes: shape (circle, square, triangle), number (1–3), fill (outline, striped, solid) and size (small, medium, large). Level 1–2 vary one attribute, 3–4 two, 5–7 three, 8–10 all four; “each value once per row” (a Latin square) appears from level 2 (alone) and from level 4.\n- Rules per attribute: the same within each row (rows may differ), a progression by one step from left to right, or each of the three values once per row. Attributes that do not vary are the same in every cell.\n- Uniqueness check: for every attribute, each reading that fits the 8 visible cells — constant, progression with steps −2 … +2 or each value once, read along rows AND along columns — predicts the missing value; all readings must agree. Exactly one of the 8 distinct options may match the prediction; otherwise the puzzle is rebuilt.\n- Wrong options change one (later two) attributes of the right answer, mostly attributes that vary, so they cannot be spotted by ignoring the pattern.\n\nPractice puzzles only: they are not a validated test and give no IQ or ability score. Practising these tasks makes you better at these tasks; it does not prove that memory, intelligence or everyday life improve.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "mindquarry_matrix_puzzle",
        "x-owner-app": "mindquarry",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MindquarryMatrixPuzzleInput"
              },
              "examples": {
                "example1": {
                  "summary": "Medium puzzle (level 5)",
                  "value": {
                    "level": 5,
                    "seed": "mindquarry"
                  }
                },
                "example2": {
                  "summary": "Easy puzzle with the answer marked",
                  "value": {
                    "level": 1,
                    "seed": "easy",
                    "showAnswer": true
                  }
                },
                "example3": {
                  "summary": "Hard puzzle (level 10)",
                  "value": {
                    "level": 10,
                    "seed": "hard-1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MindquarryMatrixPuzzleResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "MindquarryMatrixPuzzleInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "level": {
            "title": "Difficulty (1–10)",
            "description": "Higher levels vary more attributes at once and use the “each value once per row” rule.",
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 5
          },
          "seed": {
            "title": "Seed (same seed = same puzzle)",
            "type": "string",
            "maxLength": 64,
            "default": "mindquarry"
          },
          "showAnswer": {
            "title": "Mark the answer in the picture",
            "type": "boolean",
            "default": false
          }
        },
        "required": []
      },
      "MindquarryMatrixPuzzleResult": {
        "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": [
              "level",
              "seed",
              "cells",
              "options",
              "answer",
              "rules",
              "verified",
              "svg"
            ],
            "properties": {
              "level": {
                "type": "integer"
              },
              "seed": {
                "type": "string"
              },
              "cells": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Descriptions of the 8 visible cells, row by row."
              },
              "options": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "n",
                    "description",
                    "shape",
                    "count",
                    "fill",
                    "size"
                  ],
                  "properties": {
                    "n": {
                      "type": "integer"
                    },
                    "description": {
                      "type": "string"
                    },
                    "shape": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "fill": {
                      "type": "string"
                    },
                    "size": {
                      "type": "string"
                    }
                  }
                }
              },
              "answer": {
                "type": "integer",
                "description": "Number (1–8) of the correct option."
              },
              "rules": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "verified": {
                "type": "boolean"
              },
              "svg": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}