{
  "openapi": "3.1.1",
  "info": {
    "title": "Erasure-Coding Playground API",
    "version": "1.0.0",
    "summary": "Reed–Solomon over GF(256): encode data into k + m shards, lose some, rebuild it.",
    "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://erasurecodingplayground.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Reed–Solomon over GF(256): encode data into k + m shards, lose some, rebuild it.",
        "description": "Splits your text or bytes into k data shards, adds m Reed–Solomon parity shards computed over GF(256), lets you drop any shards and reconstructs the original from any k survivors. Shows the generator and decoding matrices, the shard bytes in hex, and compares storage overhead and fault tolerance with replication and RAID-5 style XOR parity.\n\nMethodology:\n- Arithmetic is in the finite field GF(2^8) with the primitive polynomial x^8 + x^4 + x^3 + x^2 + 1 (0x11d): addition is XOR, multiplication uses log/antilog tables of the generator 2.\n- The data is split into k equal shards (zero-padded at the end). The n × k generator matrix is the k × k identity (so data shards are stored as is: a systematic code) on top of an m × k Cauchy matrix C[i][j] = 1 / (x_i + y_j) with x_i = k + i and y_j = j.\n- Every k × k submatrix of this generator is invertible, so any k of the n = k + m shards are enough (the code is MDS). Reconstruction inverts the rows of the surviving shards by Gauss–Jordan elimination over GF(256) and multiplies the survivors by that inverse.\n- RAID-5 style parity is the XOR of all data shards: it survives exactly one lost shard. Replication keeps m + 1 full copies, survives m losses, but costs (m + 1)× storage.",
        "tags": [
          "math"
        ],
        "x-mcp-tool": "erasure_coding_playground",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ErasureCodingPlaygroundInput"
              },
              "examples": {
                "example1": {
                  "summary": "RS(4,2): lose two data shards",
                  "value": {
                    "data": "Hello, erasure coding!",
                    "encoding": "text",
                    "k": 4,
                    "m": 2,
                    "lost": "D1, D3"
                  }
                },
                "example2": {
                  "summary": "RS(6,3) like many object stores, three shards lost",
                  "value": {
                    "data": "The quick brown fox jumps over the lazy dog",
                    "encoding": "text",
                    "k": 6,
                    "m": 3,
                    "lost": "D2, P1, D6"
                  }
                },
                "example3": {
                  "summary": "Too many losses (3 of RS(3,2))",
                  "value": {
                    "data": "00 01 02 03 04 05 06 07 08",
                    "encoding": "hex",
                    "k": 3,
                    "m": 2,
                    "lost": "1 2 4"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErasureCodingPlaygroundResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "ErasureCodingPlaygroundInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "data": {
            "title": "Data",
            "description": "Up to 4,096 bytes. Text is encoded as UTF-8.",
            "type": "string",
            "maxLength": 8192,
            "default": "Hello, erasure coding!"
          },
          "encoding": {
            "title": "Data is",
            "type": "string",
            "enum": [
              "text",
              "hex"
            ],
            "default": "text"
          },
          "k": {
            "title": "Data shards (k)",
            "type": "integer",
            "minimum": 1,
            "maximum": 32,
            "default": 4
          },
          "m": {
            "title": "Parity shards (m)",
            "type": "integer",
            "minimum": 0,
            "maximum": 16,
            "default": 2
          },
          "lost": {
            "title": "Lost shards",
            "description": "Shards to delete before reconstruction: D1…Dk (data), P1…Pm (parity) or numbers 1…k+m. Leave empty to only encode.",
            "type": "string"
          }
        },
        "required": [
          "data"
        ]
      },
      "ErasureCodingPlaygroundResult": {
        "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",
            "required": [
              "k",
              "m",
              "n",
              "inputBytes",
              "shardSize",
              "storageOverhead",
              "lost",
              "recoverable",
              "shards",
              "generatorMatrix",
              "comparison",
              "xorParity"
            ],
            "properties": {
              "k": {
                "type": "integer"
              },
              "m": {
                "type": "integer"
              },
              "n": {
                "type": "integer"
              },
              "inputBytes": {
                "type": "integer"
              },
              "shardSize": {
                "type": "integer",
                "description": "Bytes per shard (data zero-padded to k × shardSize)."
              },
              "storageOverhead": {
                "type": "number",
                "description": "n / k"
              },
              "lost": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "recoverable": {
                "type": "boolean"
              },
              "usedShards": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "reconstructedHex": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reconstructedText": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "matchesOriginal": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "shards": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "name",
                    "role",
                    "lost",
                    "hex"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "data",
                        "parity"
                      ]
                    },
                    "lost": {
                      "type": "boolean"
                    },
                    "hex": {
                      "type": "string"
                    }
                  }
                }
              },
              "generatorMatrix": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              },
              "decodeMatrix": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              },
              "xorParity": {
                "type": "object",
                "required": [
                  "parityHex",
                  "recoverable"
                ],
                "properties": {
                  "parityHex": {
                    "type": "string"
                  },
                  "recoverable": {
                    "type": "boolean"
                  }
                }
              },
              "comparison": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "scheme",
                    "storageOverhead",
                    "toleratedLosses",
                    "bytesStored"
                  ],
                  "properties": {
                    "scheme": {
                      "type": "string"
                    },
                    "storageOverhead": {
                      "type": "number"
                    },
                    "toleratedLosses": {
                      "type": "integer"
                    },
                    "bytesStored": {
                      "type": "integer"
                    },
                    "repairReads": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}