Skip to main content
Glama

get_voting_results

Retrieve Swiss popular vote results from Basel-Stadt open data, including vote titles, dates, counts, percentages, and eligible voters for national and cantonal votes since 2021.

Instructions

Get results of Swiss popular votes (Volksabstimmungen) from Basel-Stadt open data. Returns vote title, date, yes/no counts, yes percentage, and eligible voters. Covers national and cantonal votes since 2021.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yearNoFilter by year (e.g. 2024). If omitted, returns most recent votes.
limitNoMaximum number of votes to return (default: 10, max: 50).

Implementation Reference

  • The handleGetVotingResults function orchestrates the fetching and aggregation of voting results from Basel-Stadt open data.
    export async function handleGetVotingResults(params: {
      year?: number;
      limit?: number;
    }): Promise<string> {
      const limit = Math.min(params.limit ?? 10, 50);
    
      let extraWhere = "";
      if (params.year) {
        const y = params.year;
        extraWhere = `abst_datum_text like "${y}%"`;
      }
    
      const rows = await fetchVoteRows(extraWhere, limit);
      const votes = aggregateVotes(rows).slice(0, limit);
    
      if (votes.length === 0) {
        return JSON.stringify({
          error: "No voting results found for the given parameters",
          hint: "Try without a year filter, or use a different year (available: 2021–2025)",
        });
      }
    
      const result = {
        count: votes.length,
        source: "Basel-Stadt open data — national & cantonal votes",
        data_url: "https://data.bs.ch/explore/dataset/100345/",
        note: "Results from Basel-Stadt (BS canton) as representative Swiss data. National votes cover the whole country.",
        votes,
      };
    
      const json = JSON.stringify(result);
      if (json.length > 48000) {
        const trimmed = { ...result, votes: votes.slice(0, 5) };
        return JSON.stringify(trimmed);
      }
      return json;
    }
  • Tool definition including name, description, and input schema for get_voting_results.
    export const votingTools = [
      {
        name: "get_voting_results",
        description:
          "Get results of Swiss popular votes (Volksabstimmungen) from Basel-Stadt open data. Returns vote title, date, yes/no counts, yes percentage, and eligible voters. Covers national and cantonal votes since 2021.",
        inputSchema: {
          type: "object",
          properties: {
            year: {
              type: "number",
              description: "Filter by year (e.g. 2024). If omitted, returns most recent votes.",
            },
            limit: {
              type: "number",
              description: "Maximum number of votes to return (default: 10, max: 50).",
            },
          },
        },
      },
  • Registration of the get_voting_results tool within the MCP server using server.tool.
    server.tool(
      "get_voting_results",
      votingTools[0].description,
      votingTools[0].inputSchema,
      async (params) => ({
        content: [
          {
            type: "text",
            text: await handleGetVotingResults(
              params as { year?: number; limit?: number },
            ),
          },
        ],
      }),
    );

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