{
  "openapi": "3.1.1",
  "info": {
    "title": "Ohmforge LED Resistor Calculator API",
    "version": "1.0.0",
    "summary": "Series resistor for LEDs, rounded to a standard value and checked with a real diode model.",
    "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://ohmforgeledresistor.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Series resistor for LEDs, rounded to a standard value and checked with a real diode model.",
        "description": "Calculates the series resistor for one or more LEDs in series: R = (Vs − n·Vf) / I, rounds up to the next E6/E12/E24 value, and then verifies the actual current, LED voltage and resistor dissipation by simulating the circuit with Ohmforge's diode model. Suggests a power rating with 2× margin.\n\nMethodology:\n- Exact value R = (Vs − n·Vf) / I with the typical forward voltage of the chosen colour at 20 mA.\n- Rounded UP to the next preferred value of the chosen E-series so the current never exceeds the target.\n- The circuit (supply, resistor, n LEDs) is then simulated with Ohmforge's LED diode model (n = 2, Rs = 4 Ω, fitted to Vf at 20 mA) to report the real current, which is slightly different because Vf depends on current.\n- Resistor rating: next of 0.125/0.25/0.5/1/2/5 W at or above twice the dissipation.\n\nForward voltages vary by LED type and batch (±0.2 V is common); check the datasheet of your LED. Mains-powered LED circuits need proper isolation – do not build them from this calculation.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ohmforge_led_resistor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OhmforgeLedResistorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Red LED on 9 V at 20 mA",
                  "value": {
                    "supply": 9,
                    "colour": "red",
                    "current": 20,
                    "count": 1,
                    "series": "E12"
                  }
                },
                "example2": {
                  "summary": "Three white LEDs on 12 V at 15 mA",
                  "value": {
                    "supply": 12,
                    "colour": "white",
                    "current": 15,
                    "count": 3,
                    "series": "E24"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OhmforgeLedResistorResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "OhmforgeLedResistorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "supply": {
            "title": "Supply voltage",
            "type": "number",
            "minimum": 0.5,
            "maximum": 400,
            "default": 9,
            "x-unit": "V"
          },
          "colour": {
            "title": "LED colour",
            "type": "string",
            "enum": [
              "red",
              "orange",
              "yellow",
              "green",
              "blue",
              "white",
              "ir",
              "custom"
            ],
            "default": "red"
          },
          "vf": {
            "title": "Forward voltage (custom)",
            "description": "Only used for \"Custom\".",
            "type": "number",
            "minimum": 0.5,
            "maximum": 50,
            "x-unit": "V"
          },
          "current": {
            "title": "LED current",
            "type": "number",
            "minimum": 0.1,
            "maximum": 1000,
            "default": 20,
            "x-unit": "mA"
          },
          "count": {
            "title": "LEDs in series",
            "type": "integer",
            "minimum": 1,
            "maximum": 50,
            "default": 1
          },
          "series": {
            "title": "Resistor series",
            "type": "string",
            "enum": [
              "E6",
              "E12",
              "E24"
            ],
            "default": "E12"
          }
        },
        "required": [
          "supply",
          "current"
        ]
      },
      "OhmforgeLedResistorResult": {
        "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": [
              "exactOhms",
              "standardOhms",
              "simulatedCurrent",
              "resistorPower",
              "recommendedRating"
            ],
            "properties": {
              "vf": {
                "type": "number"
              },
              "exactOhms": {
                "type": "number"
              },
              "standardOhms": {
                "type": "number"
              },
              "series": {
                "type": "string"
              },
              "simulatedCurrent": {
                "type": "number"
              },
              "simulatedLedVoltage": {
                "type": "number"
              },
              "resistorPower": {
                "type": "number"
              },
              "ledPower": {
                "type": "number"
              },
              "recommendedRating": {
                "type": "number"
              },
              "efficiency": {
                "type": "number"
              },
              "netlist": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}