{
  "openapi": "3.1.1",
  "info": {
    "title": "N-back Sequence Generator API",
    "version": "1.0.0",
    "summary": "N-back stimulus lists with an exact number of targets and lures, and a CSV answer key.",
    "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://mindquarrynbacksequence.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "N-back stimulus lists with an exact number of targets and lures, and a CSV answer key.",
        "description": "Builds the item list for an n-back task: positions on a 3 × 3 grid, digits or shapes, with an exact number of targets (the item equals the one N steps back) and optional lures (equal to the item N−1 or N+1 back, a common source of false alarms). Every item is checked so that no accidental targets or lures sneak in. The result is the answer key as a table and CSV — the same generator Mindquarry uses for its n-back exercise.\n\nMethodology:\n- Targets: round(target share × (items − N)) positions after the first N items are drawn at random; a target copies the item N steps back.\n- Lures: drawn from the remaining positions; a lure copies the item N−1 or N+1 back but never equals the item N back. If no such value is free at a position, the lure moves to the next free position.\n- Every other item (a filler) is drawn from the stimuli that are neither N back nor N±1 back, so the key never contains accidental targets or lures; the counts in the result are recounted from the final list.\n- Randomness comes from a seeded sfc32 generator, so the same inputs always give the same sequence.\n\nPractising 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_n_back_sequence",
        "x-owner-app": "mindquarry",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MindquarryNBackSequenceInput"
              },
              "examples": {
                "example1": {
                  "summary": "2-back, 30 positions, 30 % targets, 10 % lures",
                  "value": {
                    "n": 2,
                    "length": 30,
                    "targetPercent": 30,
                    "lurePercent": 10,
                    "stimuli": "positions"
                  }
                },
                "example2": {
                  "summary": "3-back digits without lures",
                  "value": {
                    "n": 3,
                    "length": 40,
                    "targetPercent": 25,
                    "lurePercent": 0,
                    "stimuli": "digits",
                    "seed": "digits-3"
                  }
                },
                "example3": {
                  "summary": "1-back shapes for a warm-up",
                  "value": {
                    "n": 1,
                    "length": 20,
                    "targetPercent": 30,
                    "lurePercent": 10,
                    "stimuli": "shapes",
                    "seed": "warm-up"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MindquarryNBackSequenceResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "MindquarryNBackSequenceInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "n": {
            "title": "N (steps back)",
            "type": "integer",
            "minimum": 1,
            "maximum": 9,
            "default": 2
          },
          "length": {
            "title": "Number of items",
            "type": "integer",
            "minimum": 5,
            "maximum": 500,
            "default": 30
          },
          "targetPercent": {
            "title": "Targets",
            "description": "Share of the items after the first N that are targets.",
            "type": "number",
            "minimum": 0,
            "maximum": 50,
            "default": 30,
            "x-unit": "%"
          },
          "lurePercent": {
            "title": "Lures",
            "description": "Items equal to the one N−1 or N+1 back (but not N back). With N = 1 only N+1 lures exist.",
            "type": "number",
            "minimum": 0,
            "maximum": 30,
            "default": 10,
            "x-unit": "%"
          },
          "stimuli": {
            "title": "Stimuli",
            "type": "string",
            "enum": [
              "positions",
              "digits",
              "shapes"
            ],
            "default": "positions"
          },
          "seed": {
            "title": "Seed (same seed = same sequence)",
            "type": "string",
            "maxLength": 64,
            "default": "mindquarry"
          }
        },
        "required": []
      },
      "MindquarryNBackSequenceResult": {
        "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": [
              "n",
              "length",
              "stimuli",
              "seed",
              "scorable",
              "targets",
              "lures",
              "items",
              "csv"
            ],
            "properties": {
              "n": {
                "type": "integer"
              },
              "length": {
                "type": "integer"
              },
              "stimuli": {
                "enum": [
                  "positions",
                  "digits",
                  "shapes"
                ]
              },
              "seed": {
                "type": "string"
              },
              "scorable": {
                "type": "integer"
              },
              "targets": {
                "type": "integer"
              },
              "lures": {
                "type": "integer"
              },
              "items": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "index",
                    "value",
                    "stimulus",
                    "target",
                    "lure"
                  ],
                  "properties": {
                    "index": {
                      "type": "integer"
                    },
                    "value": {
                      "type": "integer"
                    },
                    "stimulus": {
                      "type": "string"
                    },
                    "target": {
                      "type": "boolean"
                    },
                    "lure": {
                      "type": "boolean"
                    }
                  }
                }
              },
              "csv": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}