Spaces:
Sleeping
Swiss BFS API MCP Server
Overview
This MCP server provides access to ALL data from the Swiss Federal Statistical Office (BFS), not just population data. The BFS maintains comprehensive statistics on:
- Population and Demographics
- Territory and Environment
- Work and Income
- National Economy
- Prices and Inflation
- Industry and Services
- Agriculture and Forestry
- Energy
- Construction and Housing
- Tourism
- Mobility and Transport
- Social Security
- Health
- Education and Science
- Crime and Criminal Justice
Installation
pip install -r requirements.txt
Usage
Run the MCP server:
python bfs_mcp_server.py
The server communicates via stdio and can be integrated with any MCP-compatible client.
Available Tools
1. bfs_list_datacubes
Browse available datacubes in the API hierarchy.
path: Category path (e.g., "px-x-01" for population, "" for root)language: de/fr/it/en
2. bfs_get_metadata
Get detailed metadata about a specific datacube including dimensions and available values.
datacube_id: The datacube identifier (e.g., "px-x-0102030000_101")language: de/fr/it/en
3. bfs_query_data
Query any BFS datacube with custom filters.
datacube_id: The datacube identifierfilters: Array of filter objects withcode,filtertype, andvaluesformat: Output format (csv/json/json-stat/json-stat2/px)language: de/fr/it/en
4. bfs_search
Search for datacubes by topic keywords.
keywords: Search terms (e.g., "inflation", "education", "health")language: de/fr/it/en
5. bfs_get_config
Get API configuration and limits.
language: de/fr/it/en
Example Usage Flow
Search for a topic:
bfs_search(keywords="inflation")Browse a category:
bfs_list_datacubes(path="px-x-05") # Price statisticsGet metadata for a specific datacube:
bfs_get_metadata(datacube_id="px-x-0502010000_104")Query data with filters:
bfs_query_data( datacube_id="px-x-0502010000_104", filters=[ {"code": "Zeit", "filter": "top", "values": ["12"]} ], format="csv" )
Category Codes
Main statistical categories in the BFS system:
px-x-01: Populationpx-x-02: Territory and Environmentpx-x-03: Work and Incomepx-x-04: National Economypx-x-05: Pricespx-x-06: Industry and Servicespx-x-07: Agriculture and Forestrypx-x-08: Energypx-x-09: Construction and Housingpx-x-10: Tourismpx-x-11: Mobility and Transportpx-x-13: Social Securitypx-x-14: Healthpx-x-15: Education and Sciencepx-x-19: Crime and Criminal Justice
Integration with LLM Clients
This MCP server is designed to work with any MCP-compatible LLM client. The server handles natural language understanding through the client, providing structured access to Swiss federal statistics.
API Documentation
The underlying API is a PxWeb implementation (developed by Statistics Sweden).
- Base URL: https://www.pxweb.bfs.admin.ch/api/v1/{language}/
- Official BFS Website: https://www.bfs.admin.ch