{
  "openapi": "3.1.1",
  "info": {
    "title": "Sortbay E-mail Thread Grouper API",
    "version": "1.0.0",
    "summary": "Group an mbox into conversations by Message-ID, In-Reply-To and References, like a mail program.",
    "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://sortbaythreadgroup.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Group an mbox into conversations by Message-ID, In-Reply-To and References, like a mail program.",
        "description": "Sorts the messages of an mbox file (or several pasted .eml sources) into conversations: replies are linked through Message-ID, In-Reply-To and References, missing parents still connect their replies, and messages without those headers join a thread only when the subject matches after removing Re:/Fwd:/AW:/WG: prefixes and they share a participant.\n\nMethodology:\n- Union-find over Message-ID ↔ In-Reply-To/References (RFC 5322 §3.6.4); a reference to a message that is not in the file still links every message that names it.\n- Messages without header links are merged by normalised subject only when one of them is a reply/forward (Re:, Fwd:, AW:, WG:, SV:, Antw:, Tr: … and [list] tags removed) and they share an address — so unrelated mails with the same subject stay apart.\n- Threads are sorted newest first by their latest message; messages inside a thread by date. Thread ids are a stable hash of the first message.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "sortbay_thread_group",
        "x-owner-app": "sortbay",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SortbayThreadGroupInput"
              },
              "examples": {
                "example1": {
                  "summary": "Support conversation and a sales mail",
                  "value": {}
                },
                "example2": {
                  "summary": "Reply without headers, joined by subject",
                  "value": {
                    "source": "From a Mon Nov 30 09:00:00 2026\nFrom: \"Maria Lopez\" \u003cmaria.lopez@example.com\u003e\nTo: Support \u003csupport@example.org\u003e\nSubject: Can't log in after the update\nDate: Mon, 30 Nov 2026 09:12:44 +0100\nMessage-ID: \u003ca1-login@example.com\u003e\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\nHi there,\n\nsince yesterday's update I can't log in any more. The page says =E2=80=9Cs=\nession expired=E2=80=9D right after I type my password.\n\nI'm on Firefox on Windows 11. Could you have a look?\n\nThanks,\nMaria\n\nFrom b Tue Dec  1 10:00:00 2026\nFrom: support@example.org\nTo: maria.lopez@example.com\nSubject: AW: Can't log in after the update\nDate: Tue, 1 Dec 2026 10:00:00 +0100\n\nWe reset your session. Please try again.\n"
                  }
                },
                "example3": {
                  "summary": "Two messages, two threads",
                  "value": {
                    "source": "From a Mon Nov 30 09:00:00 2026\nFrom: Maria Lopez \u003cmaria.lopez@example.com\u003e\nTo: support@example.org\nSubject: Re: Can't log in after the update\nDate: Mon, 30 Nov 2026 11:40:02 +0100\nMessage-ID: \u003ca2-login@example.com\u003e\nIn-Reply-To: \u003ca1-login@example.com\u003e\nReferences: \u003ca1-login@example.com\u003e\nContent-Type: text/plain; charset=us-ascii\n\nClearing the cookies helped, thank you! Still strange that it happened.\n\nMaria\n\nFrom b Tue Dec  1 08:00:00 2026\nFrom: Priya Natarajan \u003cpriya@shop.example\u003e\nTo: sales@example.org\nCc: Tom Becker \u003ctom@shop.example\u003e\nSubject: Quote for 40 seats?\nDate: Tue, 01 Dec 2026 14:05:00 +0530\nMessage-ID: \u003clead-40@shop.example\u003e\nContent-Type: text/plain; charset=utf-8\n\nHello,\n\nwe are a team of 40 and would like a quote for annual licences, ideally with\na training session in January. Can you send pricing by Friday?\n\nBest regards,\nPriya\n"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SortbayThreadGroupResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "SortbayThreadGroupInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source": {
            "title": "E-mail source (.eml text) or mbox",
            "description": "Paste the full source of a message (headers, a blank line, then the body) — in most mail programs “Show original” or “View source”. Several messages: paste an mbox (each starts with a “From ” line).",
            "type": "string",
            "maxLength": 2000000,
            "default": "From maria.lopez@example.com Mon Nov 30 09:12:44 2026\nFrom: \"Maria Lopez\" \u003cmaria.lopez@example.com\u003e\nTo: Support \u003csupport@example.org\u003e\nSubject: Can't log in after the update\nDate: Mon, 30 Nov 2026 09:12:44 +0100\nMessage-ID: \u003ca1-login@example.com\u003e\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: quoted-printable\n\nHi there,\n\nsince yesterday's update I can't log in any more. The page says =E2=80=9Cs=\nession expired=E2=80=9D right after I type my password.\n\nI'm on Firefox on Windows 11. Could you have a look?\n\nThanks,\nMaria\n\nFrom maria.lopez@example.com Mon Nov 30 11:40:02 2026\nFrom: Maria Lopez \u003cmaria.lopez@example.com\u003e\nTo: support@example.org\nSubject: Re: Can't log in after the update\nDate: Mon, 30 Nov 2026 11:40:02 +0100\nMessage-ID: \u003ca2-login@example.com\u003e\nIn-Reply-To: \u003ca1-login@example.com\u003e\nReferences: \u003ca1-login@example.com\u003e\nContent-Type: text/plain; charset=us-ascii\n\nClearing the cookies helped, thank you! Still strange that it happened.\n\nMaria\n\nFrom priya@shop.example Tue Dec  1 08:35:00 2026\nFrom: Priya Natarajan \u003cpriya@shop.example\u003e\nTo: sales@example.org\nCc: Tom Becker \u003ctom@shop.example\u003e\nSubject: Quote for 40 seats?\nDate: Tue, 01 Dec 2026 14:05:00 +0530\nMessage-ID: \u003clead-40@shop.example\u003e\nContent-Type: text/plain; charset=utf-8\n\nHello,\n\nwe are a team of 40 and would like a quote for annual licences, ideally with\na training session in January. Can you send pricing by Friday?\n\n\u003eFrom the team side we are flexible.\n\nBest regards,\nPriya\n"
          },
          "file": {
            "title": "E-mail file (.eml or .mbox, optional)",
            "description": "Up to 10 MB. Used instead of the pasted text when given. Export single mails as .eml or a folder as .mbox from your mail program. Upload as {filename, contentType?, contentBase64}. Max 9766 KiB. Accepts .eml,.mbox,.mbx,.txt,message/rfc822,application/mbox,text/plain.",
            "type": "object",
            "additionalProperties": false,
            "required": [
              "filename",
              "contentBase64"
            ],
            "properties": {
              "filename": {
                "type": "string"
              },
              "contentType": {
                "type": "string"
              },
              "contentBase64": {
                "type": "string"
              }
            }
          }
        },
        "required": []
      },
      "SortbayThreadGroupResult": {
        "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": [
              "threads",
              "messages"
            ],
            "properties": {
              "threads": {
                "type": "array"
              },
              "messages": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}