Skip to main content
Glama

compare_electricity_tariffs

Compare Swiss electricity tariffs across municipalities to find the cheapest options for relocation or cost analysis.

Instructions

Compare Swiss electricity tariffs across multiple municipalities side-by-side. Returns prices sorted from cheapest to most expensive. Useful for relocation decisions or cost analysis.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
municipalitiesYesArray of municipality BFS numbers to compare (e.g. ['261', '351', '6621']). Max 20. Use search_municipality_energy to find IDs.
categoryNoElectricity category (H1–H8, C1–C7). Default: H4.
yearNoTariff year (2011–2026). Default: 2026.

Implementation Reference

  • Implementation of the compare_electricity_tariffs tool handler in src/modules/energy.ts.
    case "compare_electricity_tariffs": {
      const municipalities = args.municipalities as string[];
      const category = (args.category as string | undefined) ?? "H4";
      const year = (args.year as string | undefined) ?? CURRENT_YEAR;
    
      if (!Array.isArray(municipalities) || municipalities.length < 2) {
        throw new Error("At least 2 municipality IDs are required for comparison.");
      }
      if (municipalities.length > 20) {
        throw new Error("Maximum 20 municipalities can be compared at once.");
      }
    
      const query = `
        query Observations($locale: String!, $priceComponent: PriceComponent!, $filters: ObservationFilters!) {
          observations(locale: $locale, filters: $filters) {
            period
            municipality
            municipalityLabel
            operator
            operatorLabel
            canton
            cantonLabel
            category
            value(priceComponent: $priceComponent)
            coverageRatio
          }
        }
      `;
    
      const data = await gql<{ observations: Observation[] }>(query, {
        locale: "de",
        priceComponent: "total",
        filters: {
          period: [year],
          municipality: municipalities,
          category: [category],
        },
      });
    
      const observations = data.observations ?? [];
    
      if (!observations.length) {
        return JSON.stringify({
          error: "No tariff data found for the given municipalities",
          municipalities,
          category,
          year,
          hint: "Use search_municipality_energy to verify BFS numbers.",
          source: "https://www.strompreis.elcom.admin.ch",
        }, null, 2);
      }
    
      // Deduplicate by municipality (keep first/cheapest operator if multiple)
      const byMunicipality = new Map<string, Observation>();
      for (const obs of observations) {
        const existing = byMunicipality.get(obs.municipality);
        if (!existing || (obs.value !== null && (existing.value === null || obs.value < existing.value))) {
          byMunicipality.set(obs.municipality, obs);
        }
      }
    
      // Sort by total price ascending
      const sorted = [...byMunicipality.values()].sort((a, b) => {
        if (a.value === null) return 1;
        if (b.value === null) return -1;
        return a.value - b.value;
      });
    
      const results = sorted.map((obs, idx) => ({
        rank: idx + 1,
        municipality: obs.municipalityLabel,
        municipalityId: obs.municipality,
        canton: obs.cantonLabel,
        operator: obs.operatorLabel,
        total_rp_per_kwh: obs.value,
        year,
        category,
      }));
    
      // Find municipalities not found in results
      const foundIds = new Set(observations.map((o) => o.municipality));
      const notFound = municipalities.filter((m) => !foundIds.has(m));
    
      const cheapest = results[0];
      const mostExpensive = results[results.length - 1];
      const spread =
        cheapest && mostExpensive && cheapest.total_rp_per_kwh !== null && mostExpensive.total_rp_per_kwh !== null
          ? +(mostExpensive.total_rp_per_kwh - cheapest.total_rp_per_kwh).toFixed(3)
          : null;
    
      return JSON.stringify(
        {
          comparison: results,
          summary: {
            cheapest: cheapest.municipality,
            most_expensive: mostExpensive.municipality,
            spread_rp_per_kwh: spread,
            category,
            categoryDescription: CATEGORY_DESCRIPTIONS[category] ?? category,
            year,
            note: "Prices in Rappen per kWh. Multiple operators per municipality: cheapest shown.",
          },
          notFound: notFound.length ? notFound : undefined,
          source: "https://www.strompreis.elcom.admin.ch",
        },
        null,
        2
      );
    }
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. It discloses key behavioral traits: the tool performs comparison (not creation/modification), returns sorted results (cheapest to most expensive), and has a specific use case. However, it doesn't mention rate limits, authentication needs, error conditions, or response format details.

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 sentences that each earn their place: states the core function, describes the output sorting, and provides usage context. No wasted words or redundant information.

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

Completeness4/5

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

For a read-only comparison tool with no output schema, the description provides good context about what the tool does and returns. However, it could be more complete by mentioning the response structure (e.g., what fields are included in the comparison) or any limitations beyond the 20-municipality maximum already stated in the schema.

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?

With 100% schema description coverage, the baseline is 3. The description doesn't add any parameter-specific information beyond what's already in the schema descriptions (e.g., it doesn't explain what H4 default means or why year range is 2011-2026).

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 tool's purpose with specific verbs ('compare', 'returns') and resources ('Swiss electricity tariffs across multiple municipalities'), and distinguishes it from siblings by focusing on tariff comparison rather than single-tariff retrieval or municipality search.

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 the tool ('useful for relocation decisions or cost analysis') and implicitly suggests an alternative (search_municipality_energy for finding IDs), but doesn't explicitly state when not to use it or compare it to all relevant siblings like get_electricity_tariff.

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