{
  "openapi": "3.1.1",
  "info": {
    "title": "Tolerance Stack-up Calculator API",
    "version": "1.0.0",
    "summary": "Estimate the worst-case and statistical range of an assembly gap.",
    "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://kerfwisetolerancestack.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Estimate the worst-case and statistical range of an assembly gap.",
        "description": "Add and subtract dimension chains with asymmetric deviations to calculate the worst-case and root-sum-square range of a clearance or overlap.\n\nMethodology:\n- Add each nominal dimension with its direction. For the worst-case minimum, use lower deviations for added dimensions and upper deviations for subtracted dimensions; reverse for the maximum.\n- For the statistical (RSS) interval, centre every contributor in its band, add the centres with their directions, and combine the half bands as the square root of the sum of squares. This assumes independent, normally distributed sizes whose bands are ±3σ, so about 99.7 % of assemblies fall inside the interval.\n- All dimensions use the same unit. Neither interval accounts for geometric tolerances, temperature or assembly deformation.\n\nPlanning estimate only. Confirm tolerances for the actual design and manufacturing process.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "kerfwise_tolerance_stack",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KerfwiseToleranceStackInput"
              },
              "examples": {
                "example1": {
                  "summary": "Clearance between two parts",
                  "value": {
                    "dimensions": "Opening,100,-0.2,0.2,1\nPart A,40,-0.1,0.1,-1\nPart B,59,-0.1,0.1,-1"
                  }
                },
                "example2": {
                  "summary": "Asymmetric fit",
                  "value": {
                    "dimensions": "Slot,30,-0.1,0.2,1\nInsert,29.8,-0.05,0.1,-1"
                  }
                },
                "example3": {
                  "summary": "Hole H7 and shaft g6 (20 mm)",
                  "value": {
                    "dimensions": "Hole 20 H7,20,0,0.021,1\nShaft 20 g6,20,-0.020,-0.007,-1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KerfwiseToleranceStackResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "KerfwiseToleranceStackInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "dimensions": {
            "title": "Dimensions: name, nominal, lower deviation, upper deviation, direction",
            "description": "One row per dimension. Use the same unit for every row. Deviations are signed (for example -0.2 and 0.2, or -0.020 and -0.007 for a shaft). Direction is +1 for additions and -1 for subtractions.",
            "type": "string",
            "maxLength": 20000,
            "default": "Opening,100,-0.2,0.2,1\nPart A,40,-0.1,0.1,-1\nPart B,59,-0.1,0.1,-1"
          }
        },
        "required": []
      },
      "KerfwiseToleranceStackResult": {
        "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": [
              "rows",
              "nominal",
              "minimum",
              "maximum",
              "worstCaseSpread",
              "mean",
              "rssHalfRange",
              "rssMinimum",
              "rssMaximum"
            ],
            "properties": {
              "rows": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "nominal",
                    "lower",
                    "upper",
                    "direction"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "nominal": {
                      "type": "number"
                    },
                    "lower": {
                      "type": "number"
                    },
                    "upper": {
                      "type": "number"
                    },
                    "direction": {
                      "type": "number"
                    }
                  }
                }
              },
              "nominal": {
                "type": "number"
              },
              "minimum": {
                "type": "number"
              },
              "maximum": {
                "type": "number"
              },
              "worstCaseSpread": {
                "type": "number"
              },
              "mean": {
                "type": "number",
                "description": "Stack value with every contributor centred in its tolerance band."
              },
              "rssHalfRange": {
                "type": "number"
              },
              "rssMinimum": {
                "type": "number"
              },
              "rssMaximum": {
                "type": "number"
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}