{
  "openapi": "3.1.1",
  "info": {
    "title": "Pocketlab Slope Converter (degrees, %, 1:n, mm/m) API",
    "version": "1.0.0",
    "summary": "Convert a slope between degrees, percent grade, 1 : n ratio and millimetres per metre.",
    "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://pocketlabslopeconverter.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Convert a slope between degrees, percent grade, 1 : n ratio and millimetres per metre.",
        "description": "Converts a slope or tilt between the units builders, cyclists and DIYers use: degrees, percent grade, a 1 : n ratio, millimetres of rise per metre, or rise over run. Give a length to get the height difference over it and the length along the slope. The Pocketlab spirit level shows its readings in the same units.\n\nMethodology:\n- Every unit is turned into the angle θ: grade = tan θ × 100 %, a 1 : n ratio means tan θ = 1/n, millimetres per metre = tan θ × 1000, rise/run = tan θ.\n- Over a horizontal length L the height difference is L × tan θ and the length along the slope L / cos θ. The angle from the vertical (plumb) is 90° − |θ|.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "pocketlab_slope_converter",
        "x-owner-app": "pocketlab",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PocketlabSlopeConverterInput"
              },
              "examples": {
                "example1": {
                  "summary": "Wheelchair ramp 1 : 12 over 3.6 m",
                  "value": {
                    "unit": "ratio",
                    "value": 12,
                    "length": 3.6
                  }
                },
                "example2": {
                  "summary": "Spirit level reads 2.5° — what grade?",
                  "value": {
                    "unit": "deg",
                    "value": 2.5
                  }
                },
                "example3": {
                  "summary": "Drain fall 2 % over 8 m",
                  "value": {
                    "unit": "percent",
                    "value": 2,
                    "length": 8
                  }
                },
                "example4": {
                  "summary": "Stair: 18 cm rise over 28 cm tread",
                  "value": {
                    "unit": "riseRun",
                    "rise": 18,
                    "run": 28
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PocketlabSlopeConverterResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PocketlabSlopeConverterInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "unit": {
            "title": "I have the slope in",
            "type": "string",
            "enum": [
              "deg",
              "percent",
              "ratio",
              "mmPerM",
              "riseRun"
            ],
            "default": "deg"
          },
          "value": {
            "title": "Value",
            "description": "Degrees, percent, n of 1 : n or mm per metre — as chosen above. Not used for rise and run.",
            "type": "number",
            "minimum": -100000,
            "maximum": 100000,
            "default": 5
          },
          "rise": {
            "title": "Rise",
            "description": "Only for rise and run: height difference.",
            "type": "number",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "run": {
            "title": "Run",
            "description": "Only for rise and run: horizontal distance, same unit as the rise.",
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000
          },
          "length": {
            "title": "Horizontal length (optional)",
            "description": "Any unit; the height difference over it comes out in the same unit.",
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000
          }
        },
        "required": []
      },
      "PocketlabSlopeConverterResult": {
        "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": [
              "degrees",
              "percent",
              "ratioRun",
              "mmPerM",
              "riseOverLength",
              "slopeLength",
              "fromVertical"
            ],
            "properties": {
              "degrees": {
                "type": "number"
              },
              "percent": {
                "type": "number"
              },
              "ratioRun": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "mmPerM": {
                "type": "number"
              },
              "riseOverLength": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "slopeLength": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "fromVertical": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}