# 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 ```bash pip install -r requirements.txt ``` ## Usage Run the MCP server: ```bash 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 identifier - `filters`: Array of filter objects with `code`, `filter` type, and `values` - `format`: 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 1. **Search for a topic:** ``` bfs_search(keywords="inflation") ``` 2. **Browse a category:** ``` bfs_list_datacubes(path="px-x-05") # Price statistics ``` 3. **Get metadata for a specific datacube:** ``` bfs_get_metadata(datacube_id="px-x-0502010000_104") ``` 4. **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`: Population - `px-x-02`: Territory and Environment - `px-x-03`: Work and Income - `px-x-04`: National Economy - `px-x-05`: Prices - `px-x-06`: Industry and Services - `px-x-07`: Agriculture and Forestry - `px-x-08`: Energy - `px-x-09`: Construction and Housing - `px-x-10`: Tourism - `px-x-11`: Mobility and Transport - `px-x-13`: Social Security - `px-x-14`: Health - `px-x-15`: Education and Science - `px-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