{
  "openapi": "3.1.1",
  "info": {
    "title": "Twinworks Queueing Check API",
    "version": "1.0.0",
    "summary": "M/M/1, M/M/c, M/D/1, M/G/1 and Kingman waiting times — optionally verified by simulation.",
    "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://twinworksqueueformulas.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "M/M/1, M/M/c, M/D/1, M/G/1 and Kingman waiting times — optionally verified by simulation.",
        "description": "Closed-form queueing results for a single workstation: utilization, mean waiting time, queue length and time in system for M/M/1, M/M/c (Erlang C), M/D/1, M/G/1 (Pollaczek–Khinchine) and the Kingman G/G/1 approximation. Optionally runs the Twinworks simulation of the same station and reports whether the theory lies inside the simulated confidence interval.\n\nMethodology:\n- M/M/1: Wq = ρ/(μ−λ). M/M/c: Wq = C(c, a)/(cμ−λ) with the Erlang C probability C computed by a stable recursion. M/G/1: Wq = λE[S²]/(2(1−ρ)) (Pollaczek–Khinchine), M/D/1 is the special case SCV = 0. Kingman: Wq ≈ ((ca²+cs²)/2)·(ρ/(1−ρ))·te.\n- L = λW and Lq = λWq (Little’s law).\n- Verification builds a source → unlimited queue → station → sink model, simulates long replications (≈ 20 000 arrivals each, 5 % warm-up) and checks whether the theoretical Wq lies inside the Student-t interval of the simulated mean wait.\n\nFormulas assume steady state, infinite queue capacity and FIFO service. Kingman is an approximation.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "twinworks_queue_formulas",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TwinworksQueueFormulasInput"
              },
              "examples": {
                "example1": {
                  "summary": "M/M/1 at 80 % utilization, verified by simulation",
                  "value": {
                    "queue": "mm1",
                    "arrivalsPerHour": 60,
                    "serviceTime": 48,
                    "verify": true,
                    "replications": 10
                  }
                },
                "example2": {
                  "summary": "Two operators (M/M/2)",
                  "value": {
                    "queue": "mmc",
                    "arrivalsPerHour": 100,
                    "serviceTime": 60,
                    "servers": 2
                  }
                },
                "example3": {
                  "summary": "Kingman: low arrival variability, high process variability",
                  "value": {
                    "queue": "gg1",
                    "arrivalsPerHour": 50,
                    "serviceTime": 60,
                    "arrivalScv": 0.25,
                    "serviceScv": 1.5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TwinworksQueueFormulasResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "TwinworksQueueFormulasInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "queue": {
            "title": "Queue model",
            "type": "string",
            "enum": [
              "mm1",
              "mmc",
              "md1",
              "mg1",
              "gg1"
            ],
            "default": "mm1"
          },
          "arrivalsPerHour": {
            "title": "Arrival rate",
            "type": "number",
            "minimum": 0.0001,
            "maximum": 10000000,
            "default": 60,
            "x-unit": "parts/h"
          },
          "serviceTime": {
            "title": "Mean service (cycle) time",
            "type": "number",
            "minimum": 0.0001,
            "maximum": 10000000,
            "default": 48,
            "x-unit": "s"
          },
          "servers": {
            "title": "Servers (M/M/c)",
            "type": "integer",
            "minimum": 1,
            "maximum": 200,
            "default": 2
          },
          "serviceScv": {
            "title": "Service SCV (variance ÷ mean²)",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 1
          },
          "arrivalScv": {
            "title": "Inter-arrival SCV (G/G/1)",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 1
          },
          "verify": {
            "title": "Verify by simulation",
            "description": "Runs the same station in Twinworks (M/M/1, M/M/c, M/D/1 only).",
            "type": "boolean",
            "default": false
          },
          "replications": {
            "title": "Replications for the check",
            "type": "integer",
            "minimum": 3,
            "maximum": 20,
            "default": 10
          }
        },
        "required": [
          "arrivalsPerHour",
          "serviceTime"
        ]
      },
      "TwinworksQueueFormulasResult": {
        "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": [
              "model",
              "rho",
              "stable",
              "Wq",
              "W",
              "Lq",
              "L",
              "exact",
              "verification"
            ],
            "properties": {
              "model": {
                "type": "string"
              },
              "rho": {
                "type": "number"
              },
              "stable": {
                "type": "boolean"
              },
              "Wq": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "W": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "Lq": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "L": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "pWait": {
                "type": "number"
              },
              "exact": {
                "type": "boolean"
              },
              "verification": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "WqSim": {
                    "type": "object",
                    "required": [
                      "mean",
                      "lo",
                      "hi",
                      "halfWidth",
                      "n"
                    ],
                    "properties": {
                      "mean": {
                        "type": "number"
                      },
                      "lo": {
                        "type": "number"
                      },
                      "hi": {
                        "type": "number"
                      },
                      "halfWidth": {
                        "type": "number"
                      },
                      "n": {
                        "type": "integer"
                      }
                    }
                  },
                  "utilizationSim": {
                    "type": "object",
                    "required": [
                      "mean",
                      "lo",
                      "hi",
                      "halfWidth",
                      "n"
                    ],
                    "properties": {
                      "mean": {
                        "type": "number"
                      },
                      "lo": {
                        "type": "number"
                      },
                      "hi": {
                        "type": "number"
                      },
                      "halfWidth": {
                        "type": "number"
                      },
                      "n": {
                        "type": "integer"
                      }
                    }
                  },
                  "insideCi": {
                    "type": "boolean"
                  },
                  "replications": {
                    "type": "integer"
                  },
                  "horizonSeconds": {
                    "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"
              }
            }
          }
        }
      }
    }
  }
}