{
  "openapi": "3.1.0",
  "info": {
    "title": "Klusvang API",
    "version": "1.0.0",
    "description": "Municipal permit publications with source provenance. Requires an active Landelijk subscription. Empty fields represent unavailable extraction, not a negative fact. No private applicant contacts are provided."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/v1/permits": {
      "get": {
        "summary": "List permit publications",
        "description": "60 requests per minute per account; 100 records per page. Deterministic published-date and ID ordering. Use publication ID to deduplicate in your own system.",
        "parameters": [
          {
            "name": "municipality",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional municipality URL slug, e.g. nijmegen, to filter to one municipality. Omit this parameter or use alle for all municipalities available to the active Landelijk subscription, independent of saved work-area settings."
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 300
            },
            "description": "One or more comma-separated categories: nieuwbouw, aanbouw, verbouwing, dakkapel, dakwerk, verduurzaming, warmtepomp, zonnepanelen, functiewijziging, bedrijfspand, terrein, sloop, kap, overig."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "aangevraagd",
                "verleend",
                "deels_verleend",
                "ontwerp",
                "verlengd",
                "ingetrokken",
                "geweigerd",
                "buiten_behandeling",
                "vergunningvrij",
                "rectificatie",
                "onbekend"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 120
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["nieuwste", "oudste"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated publications",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "pagination"],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Permit"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "page": {
                          "type": "integer"
                        },
                        "pages": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "per_page": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid filters"
          },
          "401": {
            "description": "Missing or revoked API access"
          },
          "429": {
            "description": "Rate limit exceeded; respect Retry-After"
          },
          "500": {
            "description": "Transient server failure"
          }
        }
      }
    },
    "/api/v1/mcp": {
      "post": {
        "summary": "Model Context Protocol endpoint (read only)",
        "description": "For AI assistants (Claude, ChatGPT, any MCP client). Stateless Streamable HTTP: one JSON-RPC 2.0 message per POST, one JSON answer. Same API key, rights and rate limit as /api/v1/permits. Tools: search_permits, get_permit, list_municipalities, list_saved_projects, coverage_and_freshness. See docs/MCP.md.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response"
          },
          "202": {
            "description": "Notification accepted"
          },
          "400": {
            "description": "Invalid JSON or unsupported MCP-Protocol-Version"
          },
          "401": {
            "description": "Missing or revoked API access"
          },
          "403": {
            "description": "Requests with an Origin header (browsers) are refused"
          },
          "405": {
            "description": "Only POST is accepted"
          },
          "413": {
            "description": "Body larger than 64 KB"
          },
          "415": {
            "description": "Send application/json"
          },
          "429": {
            "description": "Rate limit exceeded; respect Retry-After"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Permit": {
        "type": "object",
        "required": ["id", "published", "municipality", "status", "category", "source_url", "quality"],
        "properties": {
          "id": {
            "type": "string"
          },
          "published": {
            "type": "string",
            "format": "date"
          },
          "municipality": {
            "type": "string"
          },
          "municipality_slug": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "postcode": {
            "type": "string"
          },
          "locality": {
            "type": "string"
          },
          "latitude": {
            "type": ["number", "null"]
          },
          "longitude": {
            "type": ["number", "null"]
          },
          "location_method": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "extracted_at": {
            "type": "string",
            "format": "date-time"
          },
          "quality": {
            "type": "object"
          }
        }
      }
    }
  }
}
