io.github.malkreide/swiss-statistics-mcp
BFS STAT-TAB PxWeb API for official Swiss statistics
Versions
0.2.3latestTools 15
bfs_browse_catalog Browse the BFS catalogue: the theme list, or the datasets within a theme. Two modes in one tool (`mode` in the result says which ran): - Omit `theme_code` → list all 21 statistical themes with their 2-digit codes and dataset counts (the taxonomy of Swiss federal statistics). - Provide `theme_code` → list the datasets in that theme (table IDs + titles) to feed bfs_get_table_metadata / bfs_get_data. Args: params (BrowseCatalogInput): - theme_code (str | None): 2-digit theme code, e.g. '15' for Bildung; omit for the theme list - lang (str): Language code ('de', 'fr', 'it', 'en') - limit (int): Max tables to return (theme mode; default 20) Returns: BrowseCatalogResult. `mode='themes'` populates `themes`; `mode='tables'` populates `tables` plus theme metadata. On error, `error`/`hint` are set.
bfs_search_tables Search for BFS statistical tables by keyword in their titles. Performs a full-text search across all 682+ BFS table titles. Results include table IDs needed for bfs_get_table_metadata and bfs_get_data. Note: First call builds a catalog (~682 API requests). Subsequent calls within 1 hour use the cached catalog and are instant. Args: params (SearchTablesInput): - query (str): Search keywords, e.g. 'Lehrkräfte', 'Schüler Kanton' - theme_code (Optional[str]): Filter by theme, e.g. '15' - lang (str): Language for table titles - limit (int): Max results (default 10) Returns: SearchTablesResult with matching tables. On error, `error` and `hint` are set and `results` is None.
bfs_get_table_metadata Get metadata for a BFS table: title, variables, and available filter values. Essential step before calling bfs_get_data. Returns all dimension variables with their codes and value labels needed to construct data queries. Args: params (GetTableMetadataInput): - table_id (str): BFS table ID, e.g. 'px-x-1504000000_173' - lang (str): Language for labels Returns: str: JSON with table title, source, update date, and all variables with their codes and value options. Use variable codes in bfs_get_data filters. Example output structure: { "title": "Lehrkräfte nach Schuljahr, Kanton...", "variables": [ { "code": "Schuljahr", "label": "Schuljahr", "n_values": 14, "values": [{"code": "0", "label": "2010/11"}, ...] } ] }
bfs_get_data Query statistical data from a BFS table with optional filters. Fetches actual data values from a STAT-TAB table. Always call bfs_get_table_metadata first to understand available variables and values. Args: params (GetDataInput): - table_id (str): BFS table ID - filters (Optional[list]): Dimension filters to narrow results. Each filter: {"code": "VariableCode", "values": ["val1", "val2"]} Without filters, all data is returned (may be very large). - lang (str): Language for labels - max_rows (int): Safety limit on returned rows (default 500) Returns: DataTableResult with `dimensions`, `rows`, plus `truncated`, `rows_total`, `rows_returned` for machine-readable capping. On error, `error` and `hint` are set.
bfs_education_stats Retrieve Swiss education statistics — convenience tool for Schulamt context. Provides direct access to key education datasets without needing to know table IDs or variable codes. Covers teachers, students, enrollment scenarios, and scholarship data, optionally filtered by canton. Args: params (GetEducationStatsInput): - topic (str): One of: 'teachers', 'students', 'scenarios', 'scholarships' - canton (Optional[str]): Canton name, e.g. 'Zürich'. None = all cantons. - lang (str): Language code Returns: DataTableResult with `topic`, `topic_description`, `canton_filter` on success, plus the data table fields. On error, `error` and `hint` are set.
bfs_population Retrieve Swiss population statistics by region, year, and breakdown. Accesses the core BFS population dataset (ständige Wohnbevölkerung) with flexible filtering by canton/municipality, year, age, and gender. Critical for school space planning and demographic projections. Args: params (GetPopulationInput): - region (str): 'Schweiz', or canton name like 'Zürich' - year (Optional[str]): Year filter, e.g. '2024' - breakdown (str): 'total', 'age', or 'gender' Returns: str: JSON with population figures for the selected region and breakdown.
bfs_compare_cantons Compare a BFS statistical indicator across multiple Swiss cantons. Designed for KI-Fachgruppe demos and benchmarking. Fetches the same dataset for multiple cantons simultaneously, enabling direct comparison. Args: params (CompareCantonsInput): - table_id (str): BFS table ID to query - canton_values (list[str]): Canton value codes to compare. Use '0' for Switzerland total, '1' for Zürich, '2' for Bern, etc. Get codes via bfs_get_table_metadata on any canton-level table. - additional_filters (Optional[list]): Extra dimension filters - lang (str): Language code Returns: str: JSON with data for all selected cantons side by side. Example use case: Compare teacher-to-student ratios across ZH, BE, LU, CH total: canton_values=['0', '1', '2', '3']
bfs_featured_datasets Return a curated list of high-value BFS datasets for Schulamt and public administration. Provides a shortlist of the most relevant datasets for education planning, demographic analysis, and political context — ideal as a starting point. Args: params (ListThemesInput): - lang (str): Language code Returns: FeaturedDatasetsResult with curated table IDs, titles, themes, and recommended use cases.
lookup_commune Resolve a Swiss commune by name or BFS number, as of a given date. The BFS commune number is the portfolio's join key. This tool returns the official register entry — BFS number, name, canton, validity dates and the stable LINDAS URI — for a commune as it existed on `valid_at_date`. Args: params (LookupCommuneInput): - name_or_bfs_number (str): name/substring or BFS number - valid_at_date (str): ISO date; commune state as of this date Returns: LookupCommuneResult with matching `communes` (BFS number, canton, validity, LINDAS URI). On error, `error` and `hint` are set.
resolve_historical_commune Map a historical BFS commune number onto today's number(s). This is the core value of the reference layer: when old statistics are keyed on a BFS number that has since been merged or renamed, this tool returns which of today's commune(s) that number resolves to, plus the mutation path (fusions/renamings with dates). Use `resolves_to` to re-key (umschlüsseln) old figures onto the current municipal division. Args: params (ResolveHistoricalCommuneInput): - bfs_number (int): historical BFS number - from_date (str): ISO date the old data belongs to - to_date (str): ISO target date (default today) Returns: ResolveHistoricalCommuneResult with `resolves_to` (today's BFS number/name/LINDAS URI) and `mutation_path`. On error, `error`/`hint`.
list_communes List all communes of a canton, as of a given date. Canton membership is derived from the snapshot's Parent chain (commune → district → canton), so this reflects the official division on `valid_at_date`. Each entry carries its BFS number and LINDAS URI. Args: params (ListCommunesInput): - canton (str): abbreviation ('ZH') or name ('Zürich') - valid_at_date (str): ISO date; default today Returns: ListCommunesResult with the canton's `communes`, sorted by BFS number. On error, `error` and `hint` are set.
search_historical_series Search long-run historical time series (HSSO) by topic. Historical Statistics of Switzerland provides long-run series (roughly 19th–20th century) as static XLSX tables. This tool searches the table catalogue by keyword and returns each match with its page and a stable XLSX download URL. Licence: HSSO is CC BY-NC-SA 3.0 — attribution required, NonCommercial. Every response carries that notice in `licence_note`. Args: params (SearchHistoricalSeriesInput): - topic (str): keyword(s); all must match the title - period (str): optional period hint (informational only) Returns: SearchHistoricalSeriesResult with matching `series` (code, title, page URL, XLSX URL). On error, `error` and `hint` are set.
bfs_construction_activity Yearly new buildings and new dwellings for a commune, with room-size mix. Returns the consolidated official annual construction statistics (BFS STAT-TAB theme 09) for one commune: newly built buildings with dwellings (px-x-0904030000_106) and newly built dwellings broken down by number of rooms (px-x-0904030000_105), as a per-year series from `since_year`. Note: this is the *consolidated official yearly* statistic. For up-to-date building-register states and the construction pipeline (Baugesuche / Bauvorhaben), see the `swiss-housing-mcp` server — the overlap is deliberate so the two sources can be cross-validated. Args: params (ConstructionActivityInput): - municipality_bfs (int): BFS commune number, e.g. 261 (Zürich) - since_year (int): earliest year, inclusive (default 2015) Returns: ConstructionActivityResult with a `years` series (new_buildings, new_dwellings, dwellings_by_rooms). On error, `error`/`hint` are set.
bfs_construction_investment Yearly building investment and Arbeitsvorrat for a region/canton/commune. Returns building investment (Bauinvestitionen, current year) alongside the Arbeitsvorrat (work on hand for the following year) from BFS STAT-TAB px-x-0904010000_205, as a per-year series from `since_year`. The Arbeitsvorrat is the monetary leading indicator: it signals next year's construction volume before it is realised. Args: params (ConstructionInvestmentInput): - level (str): 'grossregion', 'kanton', or 'gemeinde' - code (str): region/canton/commune code matching `level` - since_year (int): earliest year, inclusive (default 2015) Returns: ConstructionInvestmentResult with a `years` series (investment, work_on_hand) in 1000 CHF. On error, `error`/`hint` are set.
bfs_price_index Swiss price indices not carried by STAT-TAB: Baupreisindex & IMPI. - `baupreisindex`: the construction price index — returns the national semi-annual index series (Schweiz, Baugewerbe Total), parsed from the BFS DAM XLSX selected via opendata.swiss (CKAN) metadata. - `impi`: the residential property price index — BFS publishes this only as PDF/HTML, so this returns the official source links plus an explicit limitation rather than parsed values. Data flows through opendata.swiss (CKAN), which rejects default User-Agents with HTTP 403; a custom User-Agent is always sent. Results are cached for 24h. Args: params (PriceIndexInput): - index (str): 'baupreisindex' or 'impi' - since_year (int | None): optional earliest year to include Returns: PriceIndexResult with `series` (baupreisindex) or `source_links` (impi). On error, `error`/`hint` are set.
Permissions 4
env_vars low network medium filesystem low shell high