{
  "openapi": "3.1.1",
  "info": {
    "title": "The Compatibility Engine API",
    "version": "1.0.0",
    "summary": "Will this charger, cable, version or PC part work together? Rule-based checks with margins.",
    "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://compatibilityengine.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Will this charger, cable, version or PC part work together? Rule-based checks with margins.",
        "description": "Three deterministic checks: (1) USB-C charging – the real maximum power from charger, cable and device per the USB Power Delivery rules; (2) software versions – whether versions satisfy an npm-style semver range (^, ~, x-ranges, hyphen ranges, ||); (3) PC builds – CPU socket, RAM generation, slots and power-supply headroom.\n\nMethodology:\n- Charging: with USB PD on both sides the standard power range allows 5/9/15/20 V at 3 A (≤ 60 W with a standard cable) and 20 V at 5 A (≤ 100 W) with a 5 A e-marked cable; above 100 W (28/36/48 V, ≤ 240 W) needs charger, device AND cable to support PD 3.1 EPR. Without PD on both sides the assumed ceiling is USB-C 5 V / 3 A = 15 W. Expected maximum = minimum of charger, device and that limit.\n- Semver: npm range semantics (^ caret, ~ tilde, x-ranges, hyphen ranges, || alternatives, comparator sets); prereleases only match ranges that mention a prerelease of the same version.\n- PC: sockets must match exactly (case-insensitive); RAM generation must match; modules ≤ slots; recommended PSU = (CPU + GPU + other) × (1 + headroom%).",
        "tags": [
          "high-value"
        ],
        "x-mcp-tool": "compatibility_engine",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompatibilityEngineInput"
              },
              "examples": {
                "example1": {
                  "summary": "140 W laptop on a 100 W charger",
                  "value": {
                    "mode": "charging",
                    "chargerW": 100,
                    "chargerPd": true,
                    "deviceW": 140,
                    "devicePd": true,
                    "deviceEpr": true,
                    "cable": "usb-c-3a"
                  }
                },
                "example2": {
                  "summary": "Node.js engine range",
                  "value": {
                    "mode": "semver",
                    "range": "^18.17.0 || >=20.5.0",
                    "versions": [
                      "18.16.1",
                      "18.20.4",
                      "20.4.0",
                      "20.11.1",
                      "22.0.0-rc.1",
                      "22.1.0"
                    ]
                  }
                },
                "example3": {
                  "summary": "AM5 gaming PC",
                  "value": {
                    "mode": "pc",
                    "cpuSocket": "AM5",
                    "boardSocket": "AM5",
                    "ramType": "DDR5",
                    "boardRamType": "DDR5",
                    "ramModules": 2,
                    "boardSlots": 4,
                    "cpuW": 120,
                    "gpuW": 285,
                    "otherW": 75,
                    "psuW": 650
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompatibilityEngineResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "CompatibilityEngineInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "What do you want to check?",
            "type": "string",
            "enum": [
              "charging",
              "semver",
              "pc"
            ],
            "default": "charging"
          },
          "chargerW": {
            "title": "Charger maximum output",
            "description": "Charging mode.",
            "type": "number",
            "minimum": 1,
            "maximum": 1000,
            "x-unit": "W"
          },
          "chargerPd": {
            "title": "Charger supports USB Power Delivery (USB PD)",
            "type": "boolean",
            "default": true
          },
          "chargerEpr": {
            "title": "Charger supports PD 3.1 EPR (above 100 W)",
            "type": "boolean",
            "default": false
          },
          "deviceW": {
            "title": "Device maximum charging input",
            "type": "number",
            "minimum": 1,
            "maximum": 1000,
            "x-unit": "W"
          },
          "devicePd": {
            "title": "Device charges via USB PD",
            "type": "boolean",
            "default": true
          },
          "deviceEpr": {
            "title": "Device supports PD 3.1 EPR",
            "type": "boolean",
            "default": false
          },
          "cable": {
            "title": "USB-C cable",
            "type": "string",
            "enum": [
              "usb-c-3a",
              "usb-c-5a",
              "usb-c-epr"
            ],
            "default": "usb-c-3a"
          },
          "range": {
            "title": "Required version range",
            "description": "Semver mode. npm syntax.",
            "type": "string"
          },
          "versions": {
            "title": "Installed / candidate versions (one per line)",
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 50
          },
          "cpuSocket": {
            "title": "CPU socket",
            "description": "PC mode.",
            "type": "string"
          },
          "boardSocket": {
            "title": "Motherboard socket",
            "type": "string"
          },
          "ramType": {
            "title": "RAM type",
            "type": "string",
            "enum": [
              "DDR3",
              "DDR4",
              "DDR5"
            ],
            "default": "DDR5"
          },
          "boardRamType": {
            "title": "Motherboard RAM type",
            "type": "string",
            "enum": [
              "DDR3",
              "DDR4",
              "DDR5"
            ],
            "default": "DDR5"
          },
          "ramModules": {
            "title": "RAM modules",
            "type": "integer",
            "minimum": 1,
            "maximum": 16
          },
          "boardSlots": {
            "title": "Motherboard RAM slots",
            "type": "integer",
            "minimum": 1,
            "maximum": 16
          },
          "cpuW": {
            "title": "CPU power (TDP/PPT)",
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "x-unit": "W"
          },
          "gpuW": {
            "title": "Graphics card power",
            "type": "number",
            "minimum": 0,
            "maximum": 2000,
            "x-unit": "W"
          },
          "otherW": {
            "title": "Everything else",
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "default": 75,
            "x-unit": "W"
          },
          "psuW": {
            "title": "Power supply rating",
            "type": "number",
            "minimum": 100,
            "maximum": 3000,
            "x-unit": "W"
          },
          "headroomPercent": {
            "title": "Desired PSU headroom",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 30,
            "x-unit": "%"
          }
        },
        "required": []
      },
      "CompatibilityEngineResult": {
        "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": [
              "mode",
              "compatible",
              "checks"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "charging",
                  "semver",
                  "pc"
                ]
              },
              "compatible": {
                "type": "boolean"
              },
              "checks": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "check",
                    "pass",
                    "detail"
                  ],
                  "properties": {
                    "check": {
                      "type": "string"
                    },
                    "pass": {
                      "type": "boolean"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "marginW": {
                      "type": "number"
                    }
                  }
                }
              },
              "charging": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "expectedMaxW",
                  "bottleneck",
                  "usbPd",
                  "epr",
                  "limits"
                ],
                "properties": {
                  "expectedMaxW": {
                    "type": "number"
                  },
                  "bottleneck": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "usbPd": {
                    "type": "boolean"
                  },
                  "epr": {
                    "type": "boolean"
                  },
                  "limits": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "part",
                        "watts"
                      ],
                      "properties": {
                        "part": {
                          "type": "string"
                        },
                        "watts": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              },
              "semver": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "range",
                  "results",
                  "highestSatisfying"
                ],
                "properties": {
                  "range": {
                    "type": "string"
                  },
                  "highestSatisfying": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "results": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "version",
                        "satisfies"
                      ],
                      "properties": {
                        "version": {
                          "type": "string"
                        },
                        "satisfies": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              },
              "pc": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "estimatedLoadW",
                  "recommendedPsuW"
                ],
                "properties": {
                  "estimatedLoadW": {
                    "type": "number"
                  },
                  "recommendedPsuW": {
                    "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"
              }
            }
          }
        }
      }
    }
  }
}