search_postcode
Find Swiss postal codes by entering a city or locality name. Uses official Swiss geodata to return all matching PLZ entries.
Instructions
Search Swiss postcodes by city or locality name. Returns all PLZ entries matching the name. Source: Swiss federal geodata (swisstopo).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city_name | Yes | City or locality name, e.g. "Zürich", "Bern", "Locarno" |
Implementation Reference
- src/modules/post.ts:267-302 (handler)The handler function for the `search_postcode` tool, which searches for Swiss postcodes by city or locality name using the swisstopo API.
case "search_postcode": { const cityName = String(args.city_name ?? "").trim(); if (!cityName) { throw new Error("city_name must not be empty."); } const findUrl = buildUrl(`${BASE}/rest/services/api/MapServer/find`, { layer: PLZ_LAYER, searchText: cityName, searchField: "langtext", returnGeometry: false, sr: 4326, }); const findData = await fetchJSON<PlzFindResponse>(findUrl); const entries = findData.results.map((r) => ({ postcode: r.attributes.plz, locality: r.attributes.langtext, additionalNumber: r.attributes.zusziff !== "00" ? r.attributes.zusziff : undefined, })); // Deduplicate by PLZ (multiple records can share same PLZ with different suffixes) const seen = new Set<number>(); const unique = entries.filter((e) => { if (seen.has(e.postcode)) return false; seen.add(e.postcode); return true; }); return JSON.stringify({ query: cityName, count: unique.length, results: unique, source: "swisstopo — Amtliches Ortschaftenverzeichnis", }); } - src/modules/post.ts:156-169 (schema)The schema definition for the `search_postcode` tool.
name: "search_postcode", description: "Search Swiss postcodes by city or locality name. Returns all PLZ entries matching the name. Source: Swiss federal geodata (swisstopo).", inputSchema: { type: "object", required: ["city_name"], properties: { city_name: { type: "string", description: "City or locality name, e.g. \"Zürich\", \"Bern\", \"Locarno\"", }, }, }, },