{
  "openapi": "3.1.1",
  "info": {
    "title": "Sortbay Inbox Triage Rules API",
    "version": "1.0.0",
    "summary": "Test inbox rules on real mail: which labels, assignee, status and due date each message gets.",
    "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://sortbaytriagerules.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Test inbox rules on real mail: which labels, assignee, status and due date each message gets.",
        "description": "Runs deterministic triage rules — conditions on sender, recipients, subject, text, attachment names or source, actions that add labels, assign, set a status or a due date — over e-mails from an .eml/.mbox file and explains for every message which rule matched and what it set. The same evaluator sorts new mail in the Sortbay shared inbox.\n\nMethodology:\n- A rule matches when all (match: all) or any (match: any) of its conditions hold. Comparisons ignore case and accents; there are no user regular expressions, so a rule can never hang the evaluator.\n- Rules run in order. Labels of every matching rule are collected; assignee, status and due date come from the FIRST matching rule that sets them; a matching rule with stop ends the evaluation for that message.\n- Due dates are the message date (UTC day) plus dueInDays; messages without a date use “today”. “text” means subject and body together; “to” covers To and Cc; domain_is also matches subdomains.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "sortbay_triage_rules",
        "x-owner-app": "sortbay",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SortbayTriageRulesInput"
              },
              "examples": {
                "example1": {
                  "summary": "Support, invoice and sales mail",
                  "value": {}
                },
                "example2": {
                  "summary": "One invoice with a PDF",
                  "value": {
                    "source": "From: =?UTF-8?Q?J=C3=BCrgen_M=C3=BCller?= \u003cbuchhaltung@example.de\u003e\nTo: \"Example Ltd, Accounts\" \u003caccounts@example.org\u003e\nSubject: =?UTF-8?B?UmVjaG51bmcgTnIuIDIwMjYtMTE4IOKAkyBiaXR0ZSBwcsO8ZmVu?=\nDate: Tue, 1 Dec 2026 08:03:10 +0000\nMessage-ID: \u003cinv-118@example.de\u003e\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"mix-1\"\n\n--mix-1\nContent-Type: multipart/alternative; boundary=\"alt-1\"\n\n--alt-1\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\nGuten Tag,\n\nanbei die Rechnung f=FCr November. Zahlbar innerhalb von 14 Tagen.\n\nGr=FC=DFe\nJ=FCrgen M=FCller\n--alt-1\nContent-Type: text/html; charset=utf-8\n\n\u003chtml\u003e\u003cbody\u003e\u003cp\u003eGuten Tag,\u003c/p\u003e\u003cp\u003eanbei die Rechnung f\u0026uuml;r November.\u003c/p\u003e\u003cscript\u003ealert(1)\u003c/script\u003e\u003c/body\u003e\u003c/html\u003e\n--alt-1--\n\n--mix-1\nContent-Type: application/pdf; name=\"Rechnung-2026-118.pdf\"\nContent-Disposition: attachment; filename=\"Rechnung-2026-118.pdf\"\nContent-Transfer-Encoding: base64\n\nJVBERi0xLjQKJcfsj6IKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c+PgplbmRvYmoKdHJhaWxlcgo8\nPC9Sb290IDEgMCBSPj4KJSVFT0YK\n--mix-1--\n"
                  }
                },
                "example3": {
                  "summary": "Route by sender domain",
                  "value": {
                    "source": "From: 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",
                    "rules": "[{\"name\":\"Shop customers\",\"conditions\":[{\"field\":\"from\",\"op\":\"domain_is\",\"value\":\"shop.example\"}],\"actions\":{\"labels\":[\"Customer\"],\"assignee\":\"Sam\",\"dueInDays\":2}}]"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SortbayTriageRulesResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "SortbayTriageRulesInput": {
        "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 buchhaltung@example.de Tue Dec  1 08:03:10 2026\nFrom: =?UTF-8?Q?J=C3=BCrgen_M=C3=BCller?= \u003cbuchhaltung@example.de\u003e\nTo: \"Example Ltd, Accounts\" \u003caccounts@example.org\u003e\nSubject: =?UTF-8?B?UmVjaG51bmcgTnIuIDIwMjYtMTE4IOKAkyBiaXR0ZSBwcsO8ZmVu?=\nDate: Tue, 1 Dec 2026 08:03:10 +0000\nMessage-ID: \u003cinv-118@example.de\u003e\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"mix-1\"\n\n--mix-1\nContent-Type: multipart/alternative; boundary=\"alt-1\"\n\n--alt-1\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\nGuten Tag,\n\nanbei die Rechnung f=FCr November. Zahlbar innerhalb von 14 Tagen.\n\nGr=FC=DFe\nJ=FCrgen M=FCller\n--alt-1\nContent-Type: text/html; charset=utf-8\n\n\u003chtml\u003e\u003cbody\u003e\u003cp\u003eGuten Tag,\u003c/p\u003e\u003cp\u003eanbei die Rechnung f\u0026uuml;r November.\u003c/p\u003e\u003cscript\u003ealert(1)\u003c/script\u003e\u003c/body\u003e\u003c/html\u003e\n--alt-1--\n\n--mix-1\nContent-Type: application/pdf; name=\"Rechnung-2026-118.pdf\"\nContent-Disposition: attachment; filename=\"Rechnung-2026-118.pdf\"\nContent-Transfer-Encoding: base64\n\nJVBERi0xLjQKJcfsj6IKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c+PgplbmRvYmoKdHJhaWxlcgo8\nPC9Sb290IDEgMCBSPj4KJSVFT0YK\n--mix-1--\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"
              }
            }
          },
          "rules": {
            "title": "Rules (JSON list)",
            "description": "Each rule: name, match (all | any), conditions [{ field, op, value }], actions { labels, assignee, status (open | waiting | done), dueInDays, stop }. Fields: from, to, subject, body, text, attachment, source. Comparisons: contains, not_contains, equals, starts_with, ends_with, domain_is, any_word, is_empty, has_attachment.",
            "type": "string",
            "maxLength": 60000,
            "default": "[\n {\n  \"name\": \"Invoices to accounts\",\n  \"match\": \"all\",\n  \"conditions\": [\n   {\n    \"field\": \"attachment\",\n    \"op\": \"ends_with\",\n    \"value\": \".pdf\"\n   },\n   {\n    \"field\": \"text\",\n    \"op\": \"any_word\",\n    \"value\": \"invoice, rechnung, receipt\"\n   }\n  ],\n  \"actions\": {\n   \"labels\": [\n    \"Billing\"\n   ],\n   \"assignee\": \"Accounts\",\n   \"dueInDays\": 14\n  }\n },\n {\n  \"name\": \"Login problems\",\n  \"conditions\": [\n   {\n    \"field\": \"text\",\n    \"op\": \"any_word\",\n    \"value\": \"log in, login, password\"\n   }\n  ],\n  \"actions\": {\n   \"labels\": [\n    \"Bug\"\n   ],\n   \"assignee\": \"Alex\",\n   \"dueInDays\": 1\n  }\n },\n {\n  \"name\": \"Quote requests\",\n  \"conditions\": [\n   {\n    \"field\": \"text\",\n    \"op\": \"any_word\",\n    \"value\": \"quote, pricing\"\n   }\n  ],\n  \"actions\": {\n   \"labels\": [\n    \"Lead\"\n   ],\n   \"status\": \"open\",\n   \"stop\": true\n  }\n },\n {\n  \"name\": \"Thank-you replies\",\n  \"conditions\": [\n   {\n    \"field\": \"subject\",\n    \"op\": \"starts_with\",\n    \"value\": \"re:\"\n   },\n   {\n    \"field\": \"body\",\n    \"op\": \"any_word\",\n    \"value\": \"thank you, thanks\"\n   }\n  ],\n  \"actions\": {\n   \"status\": \"done\"\n  }\n }\n]"
          },
          "today": {
            "title": "Today (YYYY-MM-DD, base for due dates of undated mail)",
            "type": "string",
            "maxLength": 10,
            "default": "2026-12-02"
          }
        },
        "required": []
      },
      "SortbayTriageRulesResult": {
        "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": [
              "messages",
              "rules",
              "unmatched"
            ],
            "properties": {
              "messages": {
                "type": "array"
              },
              "rules": {
                "type": "array"
              },
              "unmatched": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}