Skip to main content
Glama

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
NameRequiredDescriptionDefault
city_nameYesCity or locality name, e.g. "Zürich", "Bern", "Locarno"

Implementation Reference

  • 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",
      });
    }
  • 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\"",
          },
        },
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vikramgorla/mcp-swiss'

If you have feedback or need assistance with the MCP directory API, please join our Discord server