{
  "openapi": "3.1.1",
  "info": {
    "title": "Personal Archive Search API",
    "version": "1.0.0",
    "summary": "Search across your own text files and keep document, line and excerpt with every hit.",
    "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://paperwellarchivesearch.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Search across your own text files and keep document, line and excerpt with every hit.",
        "description": "Search your own text collection by phrase or multiple terms, with word/case/accent controls, file filters and exact source references.\n\nMethodology:\n- At most 100 documents and two million characters. Phrase, all-terms-per-line or any-term search; every non-overlapping occurrence is counted and the first 500 are returned.\n- Grapheme-based normalization maps case/accent-insensitive matches back to original UTF-16 source offsets. File index disambiguates duplicate names. No arbitrary regular expressions, PDF extraction or OCR in this tool.\n- The enhanced interface searches locally. Direct API/MCP and the no-JavaScript form process supplied text on the server.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "paperwell_archive_search",
        "x-owner-app": "paperwell",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaperwellArchiveSearchInput"
              },
              "examples": {
                "example1": {
                  "summary": "Try an example",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaperwellArchiveSearchResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PaperwellArchiveSearchInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "documents": {
            "title": "Documents",
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "title": "File name",
                  "type": "string",
                  "maxLength": 100000
                },
                "body": {
                  "title": "Text",
                  "type": "string",
                  "maxLength": 2000000
                }
              },
              "required": [
                "name",
                "body"
              ]
            },
            "default": [
              {
                "name": "notes.md",
                "body": "Project notes\nThe blue cabinet is 600 mm wide."
              }
            ]
          },
          "query": {
            "title": "Search phrase",
            "type": "string",
            "maxLength": 200,
            "default": "cabinet"
          },
          "mode": {
            "title": "Match mode",
            "type": "string",
            "enum": [
              "phrase",
              "all",
              "any"
            ],
            "default": "phrase"
          },
          "caseSensitive": {
            "title": "Match case",
            "type": "boolean",
            "default": false
          },
          "wholeWord": {
            "title": "Whole words only",
            "type": "boolean",
            "default": false
          },
          "ignoreAccents": {
            "title": "Ignore accents",
            "type": "boolean",
            "default": false
          },
          "nameFilter": {
            "title": "File name contains",
            "type": "string",
            "maxLength": 100,
            "default": ""
          }
        },
        "required": [
          "query"
        ]
      },
      "PaperwellArchiveSearchResult": {
        "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": [
              "documents",
              "hits",
              "truncated",
              "totalMatches",
              "matchedDocuments",
              "characters"
            ],
            "properties": {
              "documents": {
                "type": "number"
              },
              "hits": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "document",
                    "documentIndex",
                    "line",
                    "column",
                    "endColumn",
                    "excerpt",
                    "match"
                  ],
                  "properties": {
                    "document": {
                      "type": "string"
                    },
                    "documentIndex": {
                      "type": "number"
                    },
                    "line": {
                      "type": "number"
                    },
                    "column": {
                      "type": "number"
                    },
                    "endColumn": {
                      "type": "number"
                    },
                    "excerpt": {
                      "type": "string"
                    },
                    "match": {
                      "type": "string"
                    }
                  }
                }
              },
              "truncated": {
                "type": "boolean"
              },
              "totalMatches": {
                "type": "number"
              },
              "matchedDocuments": {
                "type": "number"
              },
              "characters": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}