Skip to main content
Glama

lookup_postcode

Find Swiss locality details by postal code to get place name, canton, and geographic coordinates using official federal geodata.

Instructions

Look up a Swiss postcode (PLZ) to get locality name, canton, and coordinates. Source: Swiss federal geodata (swisstopo).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
postcodeYesSwiss postal code (PLZ), e.g. "8001" or "3000"

Implementation Reference

  • The handler logic for the 'lookup_postcode' tool in `handlePost`. It validates the postcode, fetches the data from the swisstopo API, identifies the canton, and returns the result.
    case "lookup_postcode": {
      const postcode = String(args.postcode ?? "").trim();
      if (!/^\d{4}$/.test(postcode)) {
        throw new Error(`Invalid Swiss postcode: "${postcode}". Must be a 4-digit number.`);
      }
    
      // 1. Fetch PLZ record from the official registry
      const findUrl = buildUrl(`${BASE}/rest/services/api/MapServer/find`, {
        layer: PLZ_LAYER,
        searchText: postcode,
        searchField: "plz",
        returnGeometry: false,
        sr: 4326,
      });
      const findData = await fetchJSON<PlzFindResponse>(findUrl);
    
      if (!findData.results.length) {
        return JSON.stringify({ found: false, postcode, message: "Postcode not found." });
      }
    
      const record = findData.results[0];
      const attr = record.attributes;
    
      // 2. Get coordinates + confirm locality from SearchServer (zipcode origin)
      const searchUrl = buildUrl(`${BASE}/rest/services/api/SearchServer`, {
        searchText: postcode,
        type: "locations",
        origins: "zipcode",
        sr: 4326,
        limit: 1,
      });
      const searchData = await fetchJSON<SearchResponse>(searchUrl);
      const searchEntry =
        searchData.results.find((r) => r.attrs.origin === "zipcode") ?? null;
    
      const lat = searchEntry?.attrs.lat ?? null;
      const lon = searchEntry?.attrs.lon ?? null;
    
      // 3. Identify canton
      const canton =
        lat !== null && lon !== null ? await identifyCanton(lat, lon) : null;
    
      return JSON.stringify({
        found: true,
        postcode: attr.plz,
        locality: attr.langtext,
        canton: canton
          ? { code: canton.code, name: canton.name }
          : null,
        coordinates: lat !== null ? { lat, lon } : null,
        source: "swisstopo — Amtliches Ortschaftenverzeichnis",
      });
    }
  • The tool registration definition for 'lookup_postcode', including the name, description, and input schema.
    {
      name: "lookup_postcode",
      description:
        "Look up a Swiss postcode (PLZ) to get locality name, canton, and coordinates. Source: Swiss federal geodata (swisstopo).",
      inputSchema: {
        type: "object",
        required: ["postcode"],
        properties: {
          postcode: {
            type: "string",
            description: "Swiss postal code (PLZ), e.g. \"8001\" or \"3000\"",
          },
        },
      },
    },
Behavior3/5

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

No annotations are provided, so the description carries full burden. It discloses the data source (Swiss federal geodata/swisstopo), which adds useful context about reliability and origin. However, it does not mention behavioral traits like rate limits, error handling, or response format, leaving gaps for a tool with no output schema.

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 two sentences, front-loaded with the core purpose and followed by source information. Every word earns its place with no redundancy or unnecessary details, making it highly efficient and well-structured.

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?

Given no annotations and no output schema, the description is moderately complete. It covers the purpose, data returned, and source, but lacks details on output format, error cases, or usage constraints. For a simple lookup tool, this is adequate but leaves room for improvement in behavioral transparency.

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

Parameters4/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds value by specifying the postcode format (PLZ) and providing examples ('8001' or '3000'), which enhances understanding beyond the schema's basic description. This justifies a score above baseline.

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 verb (look up) and resource (Swiss postcode), specifying the exact data returned (locality name, canton, coordinates) and distinguishing it from siblings like 'search_postcode' or 'geocode' by focusing on a single postcode lookup rather than search or coordinate-based operations.

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

Usage Guidelines3/5

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

The description implies usage when needing Swiss postal code details, but does not explicitly state when to use this tool versus alternatives like 'search_postcode' or 'geocode'. It provides basic context (Swiss-specific) but lacks explicit guidance on exclusions or comparisons.

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