{
  "openapi": "3.1.0",
  "info": {
    "title": "High Water Index API",
    "version": "1.0.0",
    "description": "Coastal flood and homeowners insurance data from federal policy-level records. Historical medians, not quotes; not insurance advice. Attribution required: 'High Water Index, from FEMA OpenFEMA NFIP policy data'. Keys for the v1 routes are issued by request; this document lists no prices. Human-readable reference: https://highwaterindex.com/api/",
    "contact": {"url": "https://highwaterindex.com"}
  },
  "servers": [{"url": "https://highwaterindex.com"}],
  "components": {
    "securitySchemes": {
      "apiKey": {"type": "apiKey", "in": "header", "name": "x-api-key"}
    },
    "schemas": {
      "EstimateResponse": {
        "type": "object",
        "properties": {
          "zip": {"type": "string", "example": "08247"},
          "year": {"type": "integer", "description": "Last full year of data"},
          "dateModified": {"type": "string", "format": "date"},
          "match": {
            "type": "object",
            "properties": {
              "ptype": {"type": "string"},
              "residence": {"type": "string"},
              "elevated": {"type": "string"},
              "exact": {"type": "boolean"}
            }
          },
          "premium": {
            "type": "object",
            "properties": {
              "p25": {"type": "integer", "description": "25th percentile annual premium"},
              "p50": {"type": "integer", "description": "Median annual premium"},
              "p75": {"type": "integer", "description": "75th percentile annual premium"},
              "n": {"type": "integer", "description": "Policy count in this cell. The MCP tool names this field policies."}
            }
          },
          "projection_18pct_cap": {
            "type": "object",
            "properties": {
              "next_year": {"type": "integer"},
              "three_years": {"type": "integer"}
            }
          },
          "source": {"type": "string", "example": "FEMA OpenFEMA NFIP Redacted Policies v2"},
          "attribution": {"type": "string"}
        }
      },
      "TownTrendResponse": {
        "type": "object",
        "properties": {
          "county": {"type": "string"},
          "state": {"type": "string"},
          "dateModified": {"type": "string", "format": "date"},
          "years": {"type": "array", "items": {"type": "integer"}},
          "median_premium": {"type": "array", "items": {"type": "integer"}},
          "policies": {"type": "array", "items": {"type": "integer"}},
          "nonrenewal_rate": {"type": "object", "additionalProperties": {"type": "number"}},
          "sources": {"type": "object"},
          "attribution": {"type": "string"}
        }
      },
      "ContextResponse": {
        "type": "object",
        "properties": {
          "zip": {"type": "string"},
          "homeowners": {"type": "object", "description": "Treasury FIO ZIP-level metrics 2018-2022"},
          "county": {"type": "object", "properties": {
            "state": {"type": "string"},
            "county": {"type": "string"},
            "nonrenewal_rate_pct_by_year": {"type": "object"}
          }},
          "attribution": {"type": "string"}
        }
      }
    }
  },
  "paths": {
    "/api/v1/estimate": {
      "get": {
        "operationId": "estimate_flood_premium",
        "summary": "Typical NFIP flood premium for homes like this (covered counties)",
        "description": "Returns p25/p50/p75 median annual flood premium from FEMA policy-level data, policy count, and 18%-cap projection. Not a quote.",
        "security": [{"apiKey": []}],
        "parameters": [
          {"name": "zip", "in": "query", "required": true, "schema": {"type": "string"}, "description": "5-digit ZIP code"},
          {"name": "ptype", "in": "query", "schema": {"type": "string", "enum": ["sf", "multi", "unit"]}, "description": "sf=single-family, multi=2-4 family, unit=condo"},
          {"name": "residence", "in": "query", "schema": {"type": "string", "enum": ["primary", "second"]}},
          {"name": "elevated", "in": "query", "schema": {"type": "string", "enum": ["elev", "ground"]}, "description": "elev=on pilings"}
        ],
        "responses": {
          "200": {"description": "Estimate with provenance", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/EstimateResponse"}}}},
          "401": {"description": "Missing or invalid API key"},
          "404": {"description": "ZIP not in a covered county"}
        }
      }
    },
    "/api/v1/context": {
      "get": {
        "operationId": "insurance_context",
        "summary": "Homeowners metrics by ZIP (Treasury FIO, 2018-2022) and county non-renewal rate (Senate, 2018-2023)",
        "security": [{"apiKey": []}],
        "parameters": [
          {"name": "zip", "in": "query", "schema": {"type": "string"}, "description": "5-digit ZIP for homeowners data"},
          {"name": "state", "in": "query", "schema": {"type": "string"}, "description": "2-letter state for non-renewal"},
          {"name": "county", "in": "query", "schema": {"type": "string"}, "description": "County name for non-renewal"}
        ],
        "responses": {
          "200": {"description": "Context with provenance. Treasury ZIP figures exclude FAIR Plan and surplus lines; a single ZIP can be thin.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ContextResponse"}}}},
          "400": {"description": "Neither zip nor state+county was passed"},
          "401": {"description": "Missing or invalid API key"}
        }
      }
    },
    "/api/v1/town": {
      "get": {
        "operationId": "town_trend",
        "summary": "Town or county flood premium trend (covered counties)",
        "security": [{"apiKey": []}],
        "parameters": [
          {"name": "state", "in": "query", "required": true, "schema": {"type": "string"}},
          {"name": "county", "in": "query", "required": true, "schema": {"type": "string"}},
          {"name": "town", "in": "query", "schema": {"type": "string"}, "description": "Omit for county-wide data"}
        ],
        "responses": {
          "200": {"description": "Trend with provenance", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/TownTrendResponse"}}}},
          "401": {"description": "Missing or invalid API key"},
          "404": {"description": "County or town is not covered"}
        }
      }
    },
    "/data/index.json": {
      "get": {
        "operationId": "feed_index",
        "summary": "Free static feed index — all covered counties, trend/estimator file paths (no key required; attribution required)",
        "responses": {
          "200": {"description": "County list with file paths and source metadata"}
        }
      }
    },
    "/api/parcel": {
      "get": {
        "operationId": "parcel_lookup",
        "summary": "Cape May County parcel lookup (no key, 10 per IP per day)",
        "description": "Tax assessment (the municipality's figures, not market value or an insurance price), FEMA flood zone, and an elevation certificate with freeboard and the town's published premium band when one is on file and not flagged needs_review. No owner name or mailing address. No dollar estimate for the parcel.",
        "parameters": [
          {"name": "address", "in": "query", "required": true, "schema": {"type": "string"}},
          {"name": "town", "in": "query", "schema": {"type": "string"}},
          {"name": "lat", "in": "query", "schema": {"type": "number"}},
          {"name": "lng", "in": "query", "schema": {"type": "number"}}
        ],
        "responses": {
          "200": {"description": "Parcel, assessment, flood zone, and elevation certificate when published"},
          "400": {"description": "address missing or shorter than 3 characters"},
          "404": {"description": "No parcel match"},
          "422": {"description": "Outside Cape May County, or the address could not be geocoded"},
          "429": {"description": "Daily lookup limit reached"}
        }
      }
    },
    "/api/mcp": {
      "post": {
        "operationId": "mcp_server",
        "summary": "MCP server (JSON-RPC 2.0, streamable HTTP). Tools: estimate_flood_premium, town_trend, insurance_context, parcel_report, request_quotes",
        "description": "Read tools are open and return attribution fields. request_quotes requires explicit user consent. GET returns tool list.",
        "responses": {
          "200": {"description": "JSON-RPC 2.0 response with structured content"}
        }
      }
    }
  }
}
