{
  "openapi": "3.1.1",
  "info": {
    "title": "Paperwell PDF Page Planner API",
    "version": "1.0.0",
    "summary": "Plan a PDF merge, split, reorder, removal or rotation and see every resulting page first.",
    "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://paperwellpageplan.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Plan a PDF merge, split, reorder, removal or rotation and see every resulting page first.",
        "description": "Resolves page selections such as \"1-3,5,8-end\", \"odd\" or \"10-1\" against the page counts of your PDFs and lists the exact output files and page sequences of a merge, split, reorder, removal or rotation — before any file is uploaded. It returns the parameters for the pdf-merge-split-reorder tool, so scripts and AI agents can check a plan first.\n\nMethodology:\n- Page selections use the syntax of the site’s PDF tools: numbers and ranges (\"1-3,5\"), \"end\"/\"last\", descending ranges (\"10-1\"), \"reverse\", \"odd\"/\"even\" and range filters (\"1-9:odd\"). Order and duplicates are kept for selecting/reordering; removal and rotation use the sorted set.\n- Merging appends whole files in the given order; file numbers not listed keep their original order after the listed ones.\n- Splitting creates one file per group of N pages or per range; output names follow the pdf-merge-split-reorder tool (\"report-part-2-p4-6.pdf\").\n- The plan is computed from page counts only; no PDF is opened. The real tool re-checks everything against the files.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "paperwell_page_plan",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaperwellPagePlanInput"
              },
              "examples": {
                "example1": {
                  "summary": "Merge three PDFs, appendix first",
                  "value": {
                    "mode": "merge",
                    "files": [
                      {
                        "name": "report.pdf",
                        "pages": 12
                      },
                      {
                        "name": "appendix.pdf",
                        "pages": 3
                      },
                      {
                        "name": "cover.pdf",
                        "pages": 1
                      }
                    ],
                    "order": "3,1,2"
                  }
                },
                "example2": {
                  "summary": "Split a 10-page scan into chapters",
                  "value": {
                    "mode": "split-ranges",
                    "files": [
                      {
                        "name": "scan.pdf",
                        "pages": 10
                      }
                    ],
                    "ranges": "1-2; 3-7; 8-end"
                  }
                },
                "example3": {
                  "summary": "Reverse a back-to-front scan",
                  "value": {
                    "mode": "pages",
                    "files": [
                      {
                        "name": "backwards.pdf",
                        "pages": 6
                      }
                    ],
                    "pages": "reverse"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaperwellPagePlanResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PaperwellPagePlanInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "Operation",
            "type": "string",
            "enum": [
              "merge",
              "split-every",
              "split-ranges",
              "pages",
              "remove",
              "rotate"
            ],
            "default": "merge"
          },
          "files": {
            "title": "PDFs (name and page count)",
            "type": "array",
            "minItems": 1,
            "maxItems": 25,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "title": "File name",
                  "type": "string",
                  "maxLength": 160
                },
                "pages": {
                  "title": "Pages",
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 2000
                }
              },
              "required": [
                "name",
                "pages"
              ]
            }
          },
          "order": {
            "title": "Merge order",
            "description": "File numbers, e.g. \"2,1,3\". Files not listed follow in their original order.",
            "type": "string",
            "maxLength": 200
          },
          "pages": {
            "title": "Pages",
            "description": "Page numbers start at 1. Examples: \"1-3,5,8-end\", \"odd\", \"even\", \"reverse\", \"10-1\" (descending), \"1-9:odd\". Leave empty for all pages.",
            "type": "string",
            "maxLength": 2000
          },
          "everyN": {
            "title": "Pages per part (split every N)",
            "type": "integer",
            "minimum": 1,
            "maximum": 2000,
            "default": 1
          },
          "ranges": {
            "title": "Ranges (split by ranges)",
            "description": "One part per range, separated by \";\" or new lines, e.g. \"1-3; 4-end\".",
            "type": "string",
            "maxLength": 4000
          },
          "angle": {
            "title": "Rotation",
            "type": "string",
            "enum": [
              "90",
              "180",
              "270"
            ],
            "default": "90"
          }
        },
        "required": []
      },
      "PaperwellPagePlanResult": {
        "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",
              "pagesBefore",
              "pagesAfter",
              "outputs",
              "rotated",
              "removed",
              "toolInput",
              "notes"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "merge",
                  "split-every",
                  "split-ranges",
                  "pages",
                  "remove",
                  "rotate"
                ]
              },
              "pagesBefore": {
                "type": "integer"
              },
              "pagesAfter": {
                "type": "integer"
              },
              "outputs": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "pages",
                    "sources",
                    "sequence"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "pages": {
                      "type": "integer"
                    },
                    "sources": {
                      "type": "string"
                    },
                    "sequence": {
                      "type": "array",
                      "items": {
                        "type": "array",
                        "items": {
                          "type": "integer"
                        },
                        "minItems": 2,
                        "maxItems": 2
                      }
                    }
                  }
                }
              },
              "rotated": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "removed": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "toolInput": {
                "type": "object",
                "description": "Parameters for pdf-merge-split-reorder (add the files as file, file2 … in the same order)."
              },
              "notes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}