File size: 3,168 Bytes
81d39a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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