Skip to main content
Glama

list_postcodes_in_canton

Retrieve Swiss postal codes for any canton using canton codes or names. Access official Swiss geodata to find all postcodes in specific cantons.

Instructions

List all Swiss postcodes (PLZ) in a given canton. Accepts 2-letter canton codes (ZH, BE, GR…) or full names. Source: Swiss federal geodata (swisstopo).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cantonYesCanton code (e.g. "ZH", "BE", "GR") or full name (e.g. "Zürich", "Bern", "Graubünden")

Implementation Reference

  • The handler function in the switch block that fetches and processes the postcode data for a specified canton.
    case "list_postcodes_in_canton": {
      const cantonInput = String(args.canton ?? "").trim();
      if (!cantonInput) {
        throw new Error("canton must not be empty.");
      }
    
      const cantonCode = resolveCantonCode(cantonInput);
    
      // 1. Get canton bounding box
      const cantonUrl = buildUrl(`${BASE}/rest/services/api/MapServer/find`, {
        layer: CANTON_LAYER,
        searchText: cantonCode,
        searchField: "ak",
        returnGeometry: true,
        sr: 4326,
      });
      const cantonData = await fetchJSON<CantonFindResponse>(cantonUrl);
    
      if (!cantonData.results.length) {
        throw new Error(`Canton not found: "${cantonInput}"`);
      }
    
      const cantonResult = cantonData.results[0];
      const [minX, minY, maxX, maxY] = cantonResult.bbox;
      const cantonAttr = cantonResult.attributes;
      const mapExtent = `${minX},${minY},${maxX},${maxY}`;
    
      // 2. Identify PLZ features within the canton bbox
      const identifyUrl = buildUrl(`${BASE}/rest/services/api/MapServer/identify`, {
        geometry: mapExtent,
        geometryType: "esriGeometryEnvelope",
        layers: `all:${PLZ_LAYER}`,
        mapExtent,
        imageDisplay: "1000,1000,96",
        tolerance: 0,
        sr: 4326,
        returnGeometry: false,
      });
      const plzData = await fetchJSON<{ results: PlzFindResult[] }>(identifyUrl);
    
      const postcodes = plzData.results
        .map((r) => ({
          postcode: r.attributes.plz,
          locality: r.attributes.langtext,
        }))
        .sort((a, b) => a.postcode - b.postcode);
    
      // Deduplicate by PLZ
      const seen = new Set<number>();
      const unique = postcodes.filter((e) => {
        if (seen.has(e.postcode)) return false;
        seen.add(e.postcode);
        return true;
      });
    
      return JSON.stringify({
        canton: { code: cantonAttr.ak, name: cantonAttr.name },
        count: unique.length,
        postcodes: unique,
        note:
          unique.length >= 200
            ? "Results may be capped at 200 by the API. Cross-border PLZ entries near canton boundaries may be included."
            : undefined,
        source: "swisstopo — Amtliches Ortschaftenverzeichnis",
      });
    }
  • The tool registration definition containing the name, description, and input schema for 'list_postcodes_in_canton'.
    {
      name: "list_postcodes_in_canton",
      description:
        "List all Swiss postcodes (PLZ) in a given canton. Accepts 2-letter canton codes (ZH, BE, GR…) or full names. Source: Swiss federal geodata (swisstopo).",
      inputSchema: {
        type: "object",
        required: ["canton"],
        properties: {
          canton: {
            type: "string",
            description:
              "Canton code (e.g. \"ZH\", \"BE\", \"GR\") or full name (e.g. \"Zürich\", \"Bern\", \"Graubünden\")",
          },
        },
      },
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds useful context about the data source ('Source: Swiss federal geodata (swisstopo)'), which helps establish credibility. However, it doesn't describe important behavioral aspects like response format, pagination, error conditions, or performance characteristics that would be valuable for an AI agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with three tightly focused sentences: purpose statement, parameter guidance, and data source attribution. Every sentence earns its place, and the information is front-loaded with the core functionality stated first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple read-only tool with one well-documented parameter and no output schema, the description provides adequate context about what the tool does and its data source. However, without annotations or output schema, it lacks information about response structure, error handling, and other behavioral details that would help an agent use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already fully documents the single 'canton' parameter with examples. The description adds marginal value by restating the acceptable formats ('2-letter canton codes or full names') but doesn't provide additional semantic context beyond what's in the schema. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('List all Swiss postcodes') and resource ('in a given canton'), with precise scope ('all Swiss postcodes (PLZ)'). It distinguishes from sibling tools like 'lookup_postcode' and 'search_postcode' by focusing on canton-level listing rather than individual lookups or searches.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('List all Swiss postcodes in a given canton') and specifies acceptable input formats ('Accepts 2-letter canton codes or full names'). However, it doesn't explicitly state when not to use it or name alternative tools for related tasks like searching postcodes.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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