# POST /v1/search

Wyszukaj w obszarze Polygon według cech i warstw, ze skrótem danych w wierszu oraz eksportem CSV.

Operation ID: `search_polygon`.

## Description

Wyszukiwanie obszarem Polygon obsługuje płaskie filtry cech i warstw. GET przyjmuje te same warunki oraz administracyjny teryt. Nieznane dane nie spełniają filtra i są liczone niezależnie w search_facets przed stronicowaniem. Wiersze zawierają skrót danych ze źródłami i ograniczoną długością list. format=csv zwraca result.export.content; Accept: text/csv pozwala pobrać plik HTTP po rozliczeniu. Eksport kosztuje ceil(rows/100) zamiast ceny strony. Nie przyjmuje kursora; limity wynoszą 2000 wierszy i 4000000 bajtów UTF-8. Większy wynik daje bezpłatną odmowę. Brak zapisanych danych MPZP daje bezpłatną odmowę wskazującą MPZP. Osobny format SearchRequestV2 z area i podpisany eksport GeoJSON pozostają niedostępne.

## Current runtime boundary

Polygon search accepts 17 flat feature/layer predicates in filters. GET accepts the same predicates and administrative teryt. Facets independently count matches, known exclusions and unknown exclusions over the full scope before pagination. Missing stored MPZP inputs refuse free. format=csv returns inline CSV in result.export.content; Accept: text/csv downloads the same content after settlement. CSV costs ceil(rows/100) replacing page cost, with a 2000-row and 4000000-byte cap; cursor is rejected and larger selections are refused free. Typed SearchRequestV2 area/filters and GeoJSON exports are rejected before source work.

## Cost

`x-request-cost`: 1 request per call.

## Inputs

Path/query inputs: none declared.

`q | id | point | lat+lng` at operation level: not specified in the source contract. See declared parameters and request body.

## Parameters

| Name | In | Required | Schema | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | false | `{"maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+$", "type": "string"}` | Opcjonalny klucz płatnego odczytu, przypisany do konta na 24 godziny. Ponowienie zwraca zapisaną odpowiedź bez kolejnej opłaty, z billing.replayed=true. Zmiana danych lub trwające przetwarzanie powoduje bezpłatne HTTP 409. Trwające żądanie ponów z tym samym kluczem. |

## Request body

```json
{
  "content": {
    "application/json": {
      "example": {
        "filters": {
          "flood_q100": "outside",
          "protected": "none"
        },
        "format": "csv",
        "polygon": {
          "coordinates": [
            [
              [
                20.92,
                52.07
              ],
              [
                20.93,
                52.07
              ],
              [
                20.93,
                52.08
              ],
              [
                20.92,
                52.07
              ]
            ]
          ],
          "type": "Polygon"
        }
      },
      "schema": {
        "anyOf": [
          {
            "properties": {
              "cursor": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "filters": {
                "$ref": "./envelope.json#/$defs/FeatureSearchFilters"
              },
              "format": {
                "enum": [
                  "json",
                  "csv"
                ],
                "type": "string"
              },
              "limit": {
                "description": "JSON: domyślnie 100, maksymalnie 1000 wierszy. CSV: domyślnie i maksymalnie 2000 wierszy.",
                "maximum": 2000,
                "minimum": 1,
                "type": "integer"
              },
              "polygon": {
                "WGS84": null,
                "description": "Obiekt GeoJSON typu Polygon lub MultiPolygon.",
                "type": "object"
              }
            },
            "required": [
              "polygon"
            ],
            "type": "object"
          }
        ]
      }
    }
  },
  "required": true
}
```

## Operation credit rule

page: 1; export: ceil(rows/100), replaces page cost; max 2000 results; no charge for refused/unavailable answers

## Authentication

```json
[
  {
    "ApiKey": []
  },
  {
    "OAuthConnector": []
  }
]
```

```json
{
  "ApiKey": {
    "description": "Klucz API konta korzystający z tych samych kredytów co wywołania przez połączenie OAuth.",
    "in": "header",
    "name": "X-Api-Key",
    "type": "apiKey"
  },
  "OAuthConnector": {
    "bearerFormat": "OAuth 2.1 access token",
    "description": "Autoryzacja połączenia OAuth ze wspólnymi kredytami konta. Wykrywanie konfiguracji i zgodę obsługuje usługa uwierzytelniania.",
    "scheme": "bearer",
    "type": "http"
  }
}
```

## Responses

| Status | Description | Billing rule |
| --- | --- | --- |
| 200 | Odpowiedź Envelope: strony JSON zawierają ParcelSummary z opcjonalnym highlights. Eksport CSV zawiera SearchCsvResult; Accept: text/csv pozwala pobrać plik. | See billing.rule and the verbatim Billing policy below (answers, coverage, ambiguity, and batch). |
| 400 | Bezpłatne HTTP 400. Odpowiedź Envelope ze statusem error, error.code=invalid_input, error.hint, error.example_id i billing {charged 0, rule free_invalid_input}. | free_invalid_input |
| 401 | Odpowiedź Envelope ze statusem not_found lub error, result=null i wypełnionym error (hint, docs, example_id przy danych wejściowych dotyczących działki; signup_url przy HTTP 401). Zwrot opłaty albo bezpłatne przy HTTP 401. | free_unauthorized |
| 409 | Bezpłatna odmowa: zmieniono dane dla tego klucza Idempotency-Key lub żądanie jest jeszcze przetwarzane. Trwające żądanie ponów z tymi samymi danymi i kluczem. | refunded_client_error |

### HTTP 200: headers and body schemas

```json
{
  "content": {
    "application/json": {
      "schema": {
        "allOf": [
          {
            "$ref": "./envelope.json"
          },
          {
            "properties": {
              "result": {
                "oneOf": [
                  {
                    "type": "null"
                  },
                  {
                    "items": {
                      "$ref": "#/components/schemas/ParcelSummary"
                    },
                    "type": "array"
                  },
                  {
                    "$ref": "./envelope.json#/$defs/SearchResultV2"
                  },
                  {
                    "$ref": "./envelope.json#/$defs/SearchCsvResult"
                  }
                ]
              }
            }
          }
        ]
      }
    },
    "text/csv": {
      "schema": {
        "type": "string"
      }
    }
  },
  "description": "Odpowiedź Envelope: strony JSON zawierają ParcelSummary z opcjonalnym highlights. Eksport CSV zawiera SearchCsvResult; Accept: text/csv pozwala pobrać plik.",
  "headers": {
    "Cache-Control": {
      "$ref": "#/components/headers/CacheControl"
    },
    "ETag": {
      "$ref": "#/components/headers/ETag"
    },
    "X-Credits-Charged": {
      "$ref": "#/components/headers/XCreditsCharged"
    },
    "X-Credits-Refunded": {
      "$ref": "#/components/headers/XCreditsRefunded"
    },
    "X-Request-Cost": {
      "$ref": "#/components/headers/XRequestCost"
    }
  }
}
```

### HTTP 400: headers and body schemas

```json
{
  "content": {
    "application/json": {
      "schema": {
        "$ref": "./envelope.json"
      }
    }
  },
  "description": "Bezpłatne HTTP 400. Odpowiedź Envelope ze statusem error, error.code=invalid_input, error.hint, error.example_id i billing {charged 0, rule free_invalid_input}.",
  "headers": {
    "Cache-Control": {
      "$ref": "#/components/headers/CacheControl"
    },
    "X-Credits-Charged": {
      "$ref": "#/components/headers/XCreditsCharged"
    },
    "X-Request-Cost": {
      "$ref": "#/components/headers/XRequestCost"
    }
  }
}
```

### HTTP 401: headers and body schemas

```json
{
  "content": {
    "application/json": {
      "schema": {
        "$ref": "./envelope.json"
      }
    }
  },
  "description": "Odpowiedź Envelope ze statusem not_found lub error, result=null i wypełnionym error (hint, docs, example_id przy danych wejściowych dotyczących działki; signup_url przy HTTP 401). Zwrot opłaty albo bezpłatne przy HTTP 401.",
  "headers": {
    "Cache-Control": {
      "$ref": "#/components/headers/CacheControl"
    },
    "ETag": {
      "$ref": "#/components/headers/ETag"
    },
    "X-Credits-Charged": {
      "$ref": "#/components/headers/XCreditsCharged"
    },
    "X-Credits-Refunded": {
      "$ref": "#/components/headers/XCreditsRefunded"
    },
    "X-Request-Cost": {
      "$ref": "#/components/headers/XRequestCost"
    }
  }
}
```

### HTTP 409: headers and body schemas

```json
{
  "content": {
    "application/json": {
      "schema": {
        "$ref": "./envelope.json"
      }
    }
  },
  "description": "Bezpłatna odmowa: zmieniono dane dla tego klucza Idempotency-Key lub żądanie jest jeszcze przetwarzane. Trwające żądanie ponów z tymi samymi danymi i kluczem.",
  "headers": {
    "Retry-After": {
      "schema": {
        "const": "1",
        "type": "string"
      }
    }
  }
}
```

## Layer answers and value schemas

When a response includes layer answers, their common frame is:

```json
{
  "additionalProperties": false,
  "allOf": [
    {
      "else": {
        "properties": {
          "value": {
            "type": "object"
          }
        }
      },
      "if": {
        "properties": {
          "coverage": {
            "enum": [
              "not_covered",
              "not_computed"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "value": {
            "type": "null"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "coverage": {
            "enum": [
              "covered",
              "covered_no_data"
            ]
          },
          "layer": {
            "const": "mpzp"
          }
        }
      },
      "then": {
        "properties": {
          "value": {
            "$ref": "#/$defs/MpzpValue"
          }
        }
      }
    }
  ],
  "description": "Wspólny format każdej odpowiedzi tematycznej. Pola właściwe dla danej kategorii znajdują się w value (schematy *Value w openapi.yaml).",
  "properties": {
    "as_of": {
      "format": "date",
      "type": [
        "string",
        "null"
      ]
    },
    "basis": {
      "description": "Przepis lub reguła będąca podstawą wyliczonej odpowiedzi, np. „u.p.z.p. art. 59 ust. 3”.",
      "type": [
        "string",
        "null"
      ]
    },
    "confidence": {
      "maximum": 1,
      "minimum": 0,
      "type": "number"
    },
    "coverage": {
      "$ref": "#/$defs/Coverage"
    },
    "hash": {
      "description": "Skrót sha256 w zapisie szesnastkowym z coverage + ':' + canonical(value) (nagłówek parcel_record.sql). Wartość null dla danych ustalanych podczas żądania.",
      "type": [
        "string",
        "null"
      ]
    },
    "layer": {
      "$ref": "#/$defs/LayerKey"
    },
    "layer_version": {
      "description": "Identyfikator obliczenia dla wcześniej obliczonych danych; live dla danych ustalanych podczas żądania.",
      "type": "string"
    },
    "licence": {
      "$ref": "#/$defs/Licence"
    },
    "method": {
      "$ref": "#/$defs/Method"
    },
    "note": {
      "description": "Jedno zdanie prostym językiem do przytoczenia przez agenta w każdym stanie: co oznacza wartość lub dlaczego jej brakuje. Bez określenia „bezpieczna” i bez „brak planu”, jeżeli nie wskazano rodzaju planu i źródła.",
      "minLength": 1,
      "type": "string"
    },
    "scope": {
      "$ref": "#/$defs/Scope"
    },
    "source": {
      "$ref": "#/$defs/SourceRef"
    },
    "threshold": {
      "maximum": 1,
      "minimum": 0,
      "type": "number"
    },
    "value": {
      "description": "Wartość null wtedy i tylko wtedy, gdy coverage wynosi not_covered lub not_computed.",
      "type": [
        "object",
        "null"
      ]
    }
  },
  "required": [
    "layer",
    "coverage",
    "value",
    "note",
    "source",
    "as_of",
    "layer_version"
  ],
  "type": "object"
}
```

Schema names correspond to the layer keys below. A schema dispatch constraint in `LayerAnswer` is not specified in v1.

| Layer key | LayerAnswer.value schema |
| --- | --- |
| `address` | [AddressValue](../layers/AddressValue.md) |
| `admin` | not specified in the source contract |
| `buildings` | [BuildingsValue](../layers/BuildingsValue.md) |
| `flood` | [FloodValue](../layers/FloodValue.md) |
| `landslide` | [LandslideValue](../layers/LandslideValue.md) |
| `mpzp` | [MpzpValue](../layers/MpzpValue.md) |
| `parcel` | not specified in the source contract |
| `permits` | [PermitsValue](../layers/PermitsValue.md) |
| `planning` | [PlanningValue](../layers/PlanningValue.md) |
| `pog` | [PogValue](../layers/PogValue.md) |
| `prices` | [PricesValue](../layers/PricesValue.md) |
| `protected` | [ProtectedValue](../layers/ProtectedValue.md) |
| `road_access` | [RoadAccessValue](../layers/RoadAccessValue.md) |
| `soil` | [SoilValue](../layers/SoilValue.md) |
| `wz` | [WzValue](../layers/WzValue.md) |

Referenced response definitions from `openapi.yaml`:

See [Schemas](../schemas.md) for all operation-specific definitions.

Envelope references are defined in [Envelope](../envelope.md).

## Coverage states

Cztery stany zakresu danych dla jednej kategorii w danym miejscu. covered: źródło obejmuje to miejsce i zawiera rekord; value zawiera ten rekord. covered_no_data: źródło obejmuje to miejsce, lecz nie zawiera rekordu; value ma określoną dla danej kategorii pustą wartość (false, 0, [], none), nigdy null; jest to potwierdzony brak rekordu, za który naliczana jest opłata. not_covered: źródło nie obejmuje miejsca albo państwo nie publikuje tych danych w postaci do odczytu maszynowego; value=null, agent nie może wyciągać wniosków, a opłata jest zwracana, gdy zapytanie dotyczy tych danych. not_computed: posiadamy źródło, lecz nie obliczyliśmy jeszcze wyniku dla tego miejsca, np. trwa ładowanie zbioru; value=null, opłata jest zwracana. Każdy stan zawiera uwagę napisaną prostym językiem.

States: `covered` | `covered_no_data` | `not_covered` | `not_computed`.

`LayerAnswer` required fields: `layer`, `coverage`, `value`, `note`, `source`, `as_of`, `layer_version`.

## Billing rule

Koszt żądania. charged: liczba naliczonych wywołań po zwrotach. refunded: liczba wywołań naliczonych, a następnie zwróconych. rule: zastosowana reguła. Płatne są odpowiedzi, potwierdzone braki rekordów (covered_no_data) i niejednoznaczne listy kandydatów. Bezpłatne są błędne dane wejściowe (400), brak uwierzytelnienia (401), odpowiedzi bez zmiany danych (304) i operacje bezpłatne. Zwrot obejmuje pozostałe 4xx, każde 5xx, status not_covered oraz odpowiedź dotyczącą jednej kategorii ze stanem not_covered lub not_computed. W operacjach zbiorczych liczby dotyczą poszczególnych elementów.

Rule values: `charged` | `free_operation` | `free_invalid_input` | `free_unauthorized` | `free_not_modified` | `free_idempotency_replay` | `refunded_client_error` | `refunded_server_error` | `refunded_not_covered` | `refunded_not_computed` | `batch_mixed`.

## Recorded example

No valid key supplied. Request UUID and response clock normalized. No database, socket, paid call or live coverage claim.

Recorded HTTP status: 401. The curl example reproduces this admission response with an unset API key. For supported authenticated operations, supply an account key and required permissions; data and billing then depend on that account. The Stripe receiver additionally requires a provider signature.

```sh
curl --silent --show-error --request POST "https://mcp.agentdzialek.pl/v1/search" \
  -H "X-Api-Key: ${LANDFEED_API_KEY}" \
  -H 'Idempotency-Key: docs-example-001' \
  -H 'Content-Type: application/json' \
  --data '{"polygon": {"type": "Polygon", "coordinates": [[[20.92, 52.07], [20.93, 52.07], [20.93, 52.08], [20.92, 52.07]]]}, "filters": {"flood_q100": "outside", "protected": "none"}, "format": "csv"}'
```

```json
{
  "billing": {
    "charged": 0,
    "cost": 1,
    "refunded": 0,
    "rule": "free_unauthorized"
  },
  "candidates": [],
  "error": {
    "code": "unauthorized",
    "docs": "https://landfeed.pl/docs",
    "example_id": "141803_2.0001.12/3",
    "hint": "Podaj wydany klucz w nagłówku Authorization: Bearer lub X-Api-Key albo połącz się z MCP przez OAuth.",
    "message": "Wymagany jest ważny klucz API lub token dostępu. Podaj go i ponów żądanie.",
    "signup_url": "https://landfeed.pl/signup"
  },
  "meta": {
    "api_version": "v1",
    "calls": 1,
    "generated_at": "2026-10-21T00:00:00Z",
    "request_id": "00000000-0000-4000-8000-000000000000"
  },
  "needs_obreb": false,
  "query": {
    "input": {
      "q": "[nieprawidłowe dane]"
    },
    "resolved": null
  },
  "result": null,
  "sources": [],
  "status": "error"
}
```

### Successful contract fixture

Recorded contract output, not a live service observation. Provenance: `landfeed/contracts/fixtures/v2/valid/envelope-search.json`. The parcel and dates belong to this fixture. Dormant operations remain unavailable.

```json
{
  "auth": {
    "kind": "api_key"
  },
  "billing": {
    "charged": 2,
    "cost": 2,
    "credits": 2,
    "refunded": 0,
    "rule": "charged"
  },
  "candidates": [],
  "error": null,
  "meta": {
    "api_version": "v1",
    "calls": 1,
    "contract_version": "2.0.0",
    "generated_at": "2026-10-16T12:00:00Z",
    "operation": "search",
    "request_id": "fixture"
  },
  "plan": "free",
  "query": {
    "input": {
      "area": {
        "kind": "gmina",
        "teryt": "1465011"
      },
      "cursor": null,
      "filters": {
        "area_m2": {
          "max": 1000,
          "min": 100
        },
        "building_present": false,
        "no_nature_protection": true,
        "outside_flood_q100": true,
        "plan_general_zones": [
          "SJ",
          "SW"
        ],
        "public_road_access": true
      },
      "format": "csv",
      "limit": 100
    },
    "kind": "search",
    "resolved": null
  },
  "result": {
    "export": {
      "format": "csv",
      "link": {
        "cost": 1,
        "expires_at": "2026-10-16T13:00:00Z",
        "href": "https://api.landfeed.pl/sheets/a?signature=fixture-signature"
      },
      "rows": 101
    },
    "items": [
      {
        "area_official_m2": 500,
        "centroid": [
          21,
          52
        ],
        "filter_evidence": {
          "area_m2": {
            "as_of": "2026-10-01",
            "coverage": "covered",
            "note": "Syntetyczne dane w zakresie tego filtra; przykład nie opisuje stanu rzeczywistej działki.",
            "scope": "parcel_polygon",
            "source": {
              "as_of": "2026-10-01",
              "attribution": "Źródło: Główny Urząd Geodezji i Kartografii (GUGiK), Ewidencja Gruntów i Budynków (EGiB)",
              "id": "egib_parcels",
              "title": "egib_parcels"
            },
            "value": 500
          },
          "building_present": {
            "as_of": "2026-10-01",
            "coverage": "covered",
            "note": "Syntetyczne dane w zakresie tego filtra; przykład nie opisuje stanu rzeczywistej działki.",
            "scope": "parcel_polygon",
            "source": {
              "as_of": "2026-10-01",
              "attribution": "Źródło: Główny Urząd Geodezji i Kartografii (GUGiK), Ewidencja Gruntów i Budynków (EGiB)",
              "id": "egib_buildings",
              "title": "egib_buildings"
            },
            "value": false
          },
          "no_nature_protection": {
            "as_of": "2026-10-01",
            "coverage": "covered",
            "note": "Syntetyczne dane w zakresie tego filtra; przykład nie opisuje stanu rzeczywistej działki.",
            "scope": "parcel_polygon",
            "source": {
              "as_of": "2026-10-01",
              "attribution": "Źródło: Generalna Dyrekcja Ochrony Środowiska (GDOŚ), Centralny Rejestr Form Ochrony Przyrody",
              "id": "gdos_protected",
              "title": "gdos_protected"
            },
            "value": true
          },
          "outside_flood_q100": {
            "as_of": "2026-10-01",
            "coverage": "covered",
            "note": "Syntetyczne dane w zakresie tego filtra; przykład nie opisuje stanu rzeczywistej działki.",
            "scope": "parcel_polygon",
            "source": {
              "as_of": "2026-10-01",
              "attribution": "Źródło: Państwowe Gospodarstwo Wodne Wody Polskie, mapy zagrożenia powodziowego (ISOK), licencja CC BY 4.0",
              "id": "mzp_flood",
              "title": "mzp_flood"
            },
            "value": true
          },
          "plan_general_zones": {
            "as_of": "2026-10-01",
            "coverage": "covered",
            "note": "Syntetyczne dane w zakresie tego filtra; przykład nie opisuje stanu rzeczywistej działki.",
            "scope": "parcel_polygon",
            "source": {
              "as_of": "2026-10-01",
              "attribution": "Źródło: uchwały rad gmin w sprawie planu ogólnego, wojewódzkie dzienniki urzędowe; zestawienie: Działkopedia",
              "id": "pog_sweep",
              "title": "pog_sweep"
            },
            "value": "SJ"
          },
          "public_road_access": {
            "as_of": "2026-10-01",
            "coverage": "covered",
            "note": "Syntetyczne dane w zakresie tego filtra; przykład nie opisuje stanu rzeczywistej działki.",
            "scope": "parcel_polygon",
            "source": {
              "as_of": "2026-10-01",
              "attribution": "Źródło: Główny Urząd Geodezji i Kartografii (GUGiK), BDOT10k",
              "id": "bdot_roads",
              "title": "bdot_roads"
            },
            "value": true
          }
        },
        "flags": {
          "building_present": false,
          "no_nature_protection": true,
          "outside_flood_q100": true,
          "plan_general_zone_match": true,
          "public_road_access": true
        },
        "gmina_name": "Warszawa",
        "gmina_teryt": "1465011",
        "id": "146501_1.0101.12/3",
        "number": "12/3",
        "obreb_name": "0101"
      }
    ],
    "page": {
      "has_more": false,
      "limit": 100,
      "next_cursor": null
    }
  },
  "sources": [
    {
      "as_of": "2026-10-01",
      "attribution": "Źródło: Główny Urząd Geodezji i Kartografii (GUGiK), Ewidencja Gruntów i Budynków (EGiB)",
      "id": "egib_parcels",
      "title": "egib_parcels"
    },
    {
      "as_of": "2026-10-01",
      "attribution": "Źródło: Państwowe Gospodarstwo Wodne Wody Polskie, mapy zagrożenia powodziowego (ISOK), licencja CC BY 4.0",
      "id": "mzp_flood",
      "title": "mzp_flood"
    },
    {
      "as_of": "2026-10-01",
      "attribution": "Źródło: Generalna Dyrekcja Ochrony Środowiska (GDOŚ), Centralny Rejestr Form Ochrony Przyrody",
      "id": "gdos_protected",
      "title": "gdos_protected"
    },
    {
      "as_of": "2026-10-01",
      "attribution": "Źródło: uchwały rad gmin w sprawie planu ogólnego, wojewódzkie dzienniki urzędowe; zestawienie: Działkopedia",
      "id": "pog_sweep",
      "title": "pog_sweep"
    },
    {
      "as_of": "2026-10-01",
      "attribution": "Źródło: Główny Urząd Geodezji i Kartografii (GUGiK), BDOT10k",
      "id": "bdot_roads",
      "title": "bdot_roads"
    },
    {
      "as_of": "2026-10-01",
      "attribution": "Źródło: Główny Urząd Geodezji i Kartografii (GUGiK), Ewidencja Gruntów i Budynków (EGiB)",
      "id": "egib_buildings",
      "title": "egib_buildings"
    }
  ],
  "status": "ok"
}
```

## Matching MCP tool

not specified in the source contract
