{
  "openapi": "3.1.1",
  "info": {
    "title": "Molar Mass & Composition Calculator API",
    "version": "1.0.0",
    "summary": "Molar mass with uncertainty, mass % per element and the empirical formula from percentages.",
    "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://prooflinemolarmass.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Molar mass with uncertainty, mass % per element and the empirical formula from percentages.",
        "description": "Type a chemical formula — with nested brackets, hydrate water, charges or isotopes — and get its molar mass from the current IUPAC standard atomic weights with the combined uncertainty, the formula in Hill order and the mass and atom percentage of every element. Up to ten formulas at once. The second mode turns mass percentages from an elemental analysis into the empirical formula and, with a molar mass, the molecular formula. Part of the Proofline math notebook.\n\nMethodology:\n- The formula is read by Proofline’s own parser: element symbols, counts, nested ( ) and [ ] groups, hydrate parts after · * or a dot (5H2O counts five times), a trailing charge, isotopes written ^13C (D and T for ²H and ³H) and state symbols, which are dropped.\n- Molar mass M = Σ nᵢ·Aᵢ with the CIAAW abridged standard atomic weights Aᵢ (five significant figures where nature allows). Its uncertainty is √Σ(nᵢ·Uᵢ)²: atoms of one element share the same weight (fully correlated), different elements are independent. The value is rounded to the first significant digit of that uncertainty, as CIAAW does.\n- Ions subtract z electron masses (0.000549 g/mol each). Isotopes use AME2020 nuclide masses for common nuclides, otherwise the mass number with a warning. Elements without stable isotopes (Tc, Pm, Po … ) have no standard atomic weight and must be written as a specific isotope.\n- Empirical formula: moles per 100 g are mass % ÷ Aᵢ, divided by the smallest; the smallest multiplier from 1 to 12 that brings every ratio within 0.1 of a whole number gives the counts. With a molar mass, the molecular formula is the nearest whole multiple of the empirical formula.\n\nStandard atomic weights describe normal terrestrial materials; isotopically enriched or unusual geological samples can differ beyond the stated uncertainty. Nothing here is advice on handling chemicals safely.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "proofline_molar_mass",
        "x-owner-app": "proofline",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProoflineMolarMassInput"
              },
              "examples": {
                "example1": {
                  "summary": "Water",
                  "value": {
                    "formulas": "H2O"
                  }
                },
                "example2": {
                  "summary": "Copper(II) sulfate pentahydrate",
                  "value": {
                    "formulas": "CuSO4·5H2O"
                  }
                },
                "example3": {
                  "summary": "Several formulas: complex salt, phosphate, labelled CO₂",
                  "value": {
                    "formulas": "K4[Fe(CN)6]\nCa3(PO4)2\n^13CO2"
                  }
                },
                "example4": {
                  "summary": "Ions: permanganate and sulfate",
                  "value": {
                    "formulas": "MnO4-\nSO4^2-"
                  }
                },
                "example5": {
                  "summary": "Glucose from its elemental analysis",
                  "value": {
                    "mode": "empirical",
                    "percentages": "C 40.0, H 6.71, O 53.29",
                    "molarMass": 180.16
                  }
                },
                "example6": {
                  "summary": "Iron oxide from 69.94 % iron",
                  "value": {
                    "mode": "empirical",
                    "percentages": "Fe 69.94, O 30.06"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProoflineMolarMassResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "ProoflineMolarMassInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "Calculation",
            "type": "string",
            "enum": [
              "formula",
              "empirical"
            ],
            "default": "formula"
          },
          "formulas": {
            "title": "Formulas (one per line)",
            "description": "Element symbols with counts (H2O), brackets ( ) and [ ] that may nest (K4[Fe(CN)6]), hydrates with · or * or a dot (CuSO4·5H2O), charges at the end (SO4^2-, Fe+3, NH4+), isotopes (^13C, D, T) and state symbols such as (aq), which are ignored. At most 10 lines.",
            "type": "string",
            "maxLength": 2000,
            "default": ""
          },
          "percentages": {
            "title": "Mass percentages",
            "description": "Empirical formula: each element with its mass percentage, separated by commas or lines.",
            "type": "string",
            "maxLength": 1000,
            "default": ""
          },
          "molarMass": {
            "title": "Molar mass of the compound (optional)",
            "description": "Empirical formula: with a measured molar mass the molecular formula is the nearest whole multiple.",
            "type": "number",
            "minimum": 0,
            "x-unit": "g/mol"
          }
        },
        "required": []
      },
      "ProoflineMolarMassResult": {
        "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",
              "formulas",
              "empirical"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "formula",
                  "empirical"
                ]
              },
              "formulas": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "formula",
                    "hill",
                    "pretty",
                    "charge",
                    "molarMass",
                    "uncertainty",
                    "atoms",
                    "electronCorrection",
                    "composition",
                    "molarMassRounded",
                    "uncertaintyRounded"
                  ],
                  "properties": {
                    "formula": {
                      "type": "string"
                    },
                    "hill": {
                      "type": "string"
                    },
                    "pretty": {
                      "type": "string"
                    },
                    "charge": {
                      "type": "integer"
                    },
                    "molarMass": {
                      "type": "number",
                      "description": "g/mol"
                    },
                    "uncertainty": {
                      "type": "number",
                      "description": "Combined CIAAW uncertainty, g/mol."
                    },
                    "atoms": {
                      "type": "integer"
                    },
                    "electronCorrection": {
                      "type": "number"
                    },
                    "composition": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "key",
                          "label",
                          "name",
                          "count",
                          "atomicWeight",
                          "uncertainty",
                          "massContribution",
                          "massPercent",
                          "atomPercent"
                        ],
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          },
                          "atomicWeight": {
                            "type": "number"
                          },
                          "uncertainty": {
                            "type": "number"
                          },
                          "massContribution": {
                            "type": "number"
                          },
                          "massPercent": {
                            "type": "number"
                          },
                          "atomPercent": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "molarMassRounded": {
                      "type": "string"
                    },
                    "uncertaintyRounded": {
                      "type": "string"
                    }
                  }
                }
              },
              "empirical": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "empirical",
                  "empiricalMass",
                  "multiplier",
                  "maxDeviation",
                  "molecular",
                  "molecularMass",
                  "factor",
                  "total",
                  "ratios"
                ],
                "properties": {
                  "empirical": {
                    "type": "string"
                  },
                  "empiricalMass": {
                    "type": "number"
                  },
                  "multiplier": {
                    "type": "integer"
                  },
                  "maxDeviation": {
                    "type": "number"
                  },
                  "molecular": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "molecularMass": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "factor": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "total": {
                    "type": "number"
                  },
                  "ratios": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "symbol",
                        "percent",
                        "moles",
                        "ratio",
                        "scaled",
                        "count"
                      ],
                      "properties": {
                        "symbol": {
                          "type": "string"
                        },
                        "percent": {
                          "type": "number"
                        },
                        "moles": {
                          "type": "number"
                        },
                        "ratio": {
                          "type": "number"
                        },
                        "scaled": {
                          "type": "number"
                        },
                        "count": {
                          "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"
              }
            }
          }
        }
      }
    }
  }
}