Skip to main content
Glama
malkreide

swiss-food-safety-mcp

by malkreide
README.md
> πŸ‡¨πŸ‡­ **Part of the [Swiss Public Data MCP Portfolio](https://github.com/malkreide)**

# swiss-food-safety-mcp

![Version](https://img.shields.io/badge/version-1.1.5-blue)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![MCP](https://img.shields.io/badge/MCP-Model%20Context%20Protocol-purple)](https://modelcontextprotocol.io/)
[![Data Source](https://img.shields.io/badge/Data-opendata.swiss%20%2F%20BLV-red)](https://opendata.swiss/de/organization/bundesamt-fur-lebensmittelsicherheit-und-veterinaerwesen-blv)
![No Auth Required](https://img.shields.io/badge/auth-none%20required-brightgreen)
![CI](https://github.com/malkreide/swiss-food-safety-mcp/actions/workflows/ci.yml/badge.svg)

🌐 **English** | **[Deutsch](README.de.md)**

> MCP server connecting AI models to Swiss Federal Food Safety and Veterinary Office (BLV) open data β€” food recalls, animal disease surveillance, food control results, antibiotic usage, children's nutrition surveys and the pesticide register. No authentication required.

---

## Overview

**swiss-food-safety-mcp** gives AI assistants like Claude direct access to official Swiss food safety and veterinary data from the Federal Food Safety and Veterinary Office (BLV / *Bundesamt fΓΌr Lebensmittelsicherheit und VeterinΓ€rwesen*). It provides 11 tools covering food recalls, animal disease surveillance, food control results, antibiotic usage in veterinary medicine, nutrition surveys for children, and the pesticide register.

All data comes from official Swiss federal sources (opendata.swiss, lindas.admin.ch, news.admin.ch). No API keys or authentication are required.

This server follows the **No-Auth-First** philosophy and is part of a Swiss public sector MCP portfolio.

**Anchor demo query:** *"Are there any current BLV food warnings relevant to Zurich school canteens β€” and which notifiable animal diseases are currently reported in the canton?"*

### Demo

![Demo: Claude using blv_get_public_warnings and blv_search_animal_diseases](docs/assets/demo.svg)
[β†’ More use cases by audience β†’](EXAMPLES.md)

---

## Features

- 🚨 **Public warnings & recalls** β€” Live RSS feed of BLV product recalls and health warnings
- πŸ„ **Animal disease surveillance** β€” Notifiable animal diseases since 1991 (InfoSM) via the LINDAS SPARQL cube
- 🐦 **Avian influenza monitoring** β€” Wild bird surveillance data with geodata
- πŸ₯© **Food control results** β€” Cantonal food inspection results and violation rates
- πŸ’Š **Antibiotic usage veterinary** β€” ISABV data on antibiotic use in animal medicine
- πŸ§’ **Children's nutrition survey** β€” menuCH-Kids questionnaire tallies (answer counts, not nutrient intake)
- 🌿 **Pesticide register** β€” Swiss approved pesticide products and active ingredients
- πŸ“Š **Dataset discovery** β€” Browse all 28 BLV datasets on opendata.swiss via CKAN API
- πŸ”— **Dual transport** β€” stdio (Claude Desktop) + Streamable HTTP (cloud/Render.com)
- πŸ—£οΈ **Bilingual** β€” English-first documentation, German secondary

---

## Prerequisites

- Python 3.11+
- `uv` or `uvx` (recommended) β€” [install uv](https://docs.astral.sh/uv/getting-started/installation/)

---

## Installation

### Using uvx (recommended β€” no install needed)

```bash
uvx swiss-food-safety-mcp
```

### Using uv

```bash
uv tool install swiss-food-safety-mcp
swiss-food-safety-mcp
```

### From source

```bash
git clone https://github.com/malkreide/swiss-food-safety-mcp
cd swiss-food-safety-mcp
uv sync
uv run swiss-food-safety-mcp
```

---

## Quickstart

Add to `claude_desktop_config.json`:

**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`  
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
  "mcpServers": {
    "swiss-food-safety": {
      "command": "uvx",
      "args": ["swiss-food-safety-mcp"]
    }
  }
}
```

Try it immediately in Claude Desktop:

> *"Which BLV food warnings are currently active?"*  
> *"Are there any notifiable animal diseases reported in Zurich canton this year?"*

### Other MCP Clients (Cursor, Windsurf, VS Code + Continue)

```json
{
  "mcpServers": {
    "swiss-food-safety": {
      "command": "uvx",
      "args": ["swiss-food-safety-mcp"]
    }
  }
}
```

### Cloud Deployment (Streamable HTTP)

For use via **claude.ai in the browser** (e.g. on managed workstations without local software):

```bash
# Loopback only (default) β€” safe for local testing:
swiss-food-safety-mcp --http
# Server runs on 127.0.0.1:8002

# External exposure (e.g. behind the Render TLS proxy):
swiss-food-safety-mcp --http --host 0.0.0.0
```

> ⚠️ The HTTP transport binds to `127.0.0.1` by default. Pass `--host 0.0.0.0`
> **only** when external exposure is intended. Set `BLV_MCP_ALLOWED_ORIGINS`
> (comma-separated, no wildcard) to permit browser clients; it defaults to
> `https://claude.ai`.

**Render.com (recommended):**
1. Push/fork the repository to GitHub
2. On [render.com](https://render.com): New Web Service β†’ connect GitHub repo
3. Set the start command to: `swiss-food-safety-mcp --http --host 0.0.0.0`
4. In claude.ai under Settings β†’ MCP Servers, add: `https://your-app.onrender.com/mcp`

**Docker:**

```bash
docker build -t swiss-food-safety-mcp .
docker run -p 8002:8002 swiss-food-safety-mcp
# or, with explicit CPU/memory limits:
docker compose up
```

The image is a non-root, multi-stage build; the container already binds
`0.0.0.0` and includes a healthcheck. `docker-compose.yml` additionally caps
CPU and memory.

> πŸ’‘ *"stdio for the developer laptop, Streamable HTTP for the browser."*

> πŸ”§ **Configuration** β€” every runtime setting is overridable via `BLV_MCP_*`
> environment variables (`BLV_MCP_HTTP_HOST`, `BLV_MCP_HTTP_PORT`,
> `BLV_MCP_ALLOWED_ORIGINS`, `BLV_MCP_TIMEOUT`, `BLV_MCP_OTEL_ENDPOINT`, …).
> Outbound requests are restricted to Swiss federal hosts (`*.admin.ch`,
> `opendata.swiss`). Optional OpenTelemetry tracing: install with
> `pip install swiss-food-safety-mcp[otel]` and set `BLV_MCP_OTEL_ENDPOINT`.

---

## Available Tools

| Tool | Description | Data Source |
|---|---|---|
| `blv_get_public_warnings` | Current food recalls & health warnings | news.admin.ch RSS |
| `blv_list_datasets` | Browse all 28 BLV open datasets | opendata.swiss CKAN |
| `blv_get_dataset_info` | Dataset details & resource URLs | opendata.swiss CKAN |
| `blv_search_animal_diseases` | Notifiable animal diseases since 1991 | LINDAS SPARQL (`/query`) |
| `blv_get_animal_health_stats` | Annual animal health statistics | opendata.swiss CSV/JSON |
| `blv_get_food_control_results` | Cantonal food inspection results | opendata.swiss CSV |
| `blv_get_antibiotic_usage_vet` | Veterinary antibiotic usage (ISABV) | opendata.swiss CSV |
| `blv_get_avian_influenza` | Wild bird avian influenza surveillance | opendata.swiss CSV |
| `blv_get_nutrition_data_children` | menuCH-Kids: questionnaire tallies (not nutrient intake) | opendata.swiss CSV |
| `blv_search_pesticide_products` | Swiss approved pesticide register | opendata.swiss XML |
| `blv_get_meat_inspection_stats` | Slaughterhouse inspection statistics | opendata.swiss CSV/JSON |

### Example Queries

| Query | Tool |
|---|---|
| *"Which BLV food warnings are currently active?"* | `blv_get_public_warnings` |
| *"Are there animal diseases in Zurich canton in 2024?"* | `blv_search_animal_diseases` |
| *"What is the avian influenza situation in Switzerland 2024?"* | `blv_get_avian_influenza` |
| *"What do Swiss children actually eat?"* | `blv_get_nutrition_data_children` |
| *"Which copper-based pesticides are approved in Switzerland?"* | `blv_search_pesticide_products` |

---

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Claude / AI   │────▢│   Swiss Food Safety MCP     │────▢│  Swiss Federal Open Data     β”‚
β”‚   (MCP Host)    │◀────│   (MCP Server)              │◀────│                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚                             β”‚     β”‚  opendata.swiss (CKAN/CSV)   β”‚
                        β”‚  11 Tools Β· No Auth         β”‚     β”‚  lindas.admin.ch (SPARQL)    β”‚
                        β”‚  Stdio | Streamable HTTP    β”‚     β”‚  news.admin.ch (RSS/XML)     β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Synergies with Related MCP Servers

| Combination | Use Case |
|---|---|
| `swiss-food-safety-mcp` + `zurich-opendata-mcp` | Geo-mapped animal disease risk near school locations |
| `swiss-food-safety-mcp` + `fedlex-mcp` | Link recalls to food law (Lebensmittelgesetz) |
| `swiss-food-safety-mcp` + `swiss-statistics-mcp` | Nutrition data Γ— socioeconomics by school district |
| `swiss-food-safety-mcp` + `global-education-mcp` | Swiss children's nutrition vs. OECD benchmarks |

---

## Project Structure

```
swiss-food-safety-mcp/
β”œβ”€β”€ src/
β”‚   └── swiss_food_safety_mcp/
β”‚       β”œβ”€β”€ __init__.py        # Package metadata
β”‚       └── server.py          # All tools, resources, prompts
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── test_server.py         # Unit tests (no live API calls)
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml             # Python 3.11–3.13 matrix
β”œβ”€β”€ pyproject.toml             # hatchling build, uv-compatible
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ CONTRIBUTING.md            # Contribution guide (English)
β”œβ”€β”€ CONTRIBUTING.de.md        # Contribution guide (German)
β”œβ”€β”€ SECURITY.md               # Security policy (English)
β”œβ”€β”€ SECURITY.de.md            # Security policy (German)
β”œβ”€β”€ LICENSE                    # MIT
β”œβ”€β”€ README.md                  # This file (English)
└── README.de.md               # German version
```

---

## Data Sources

| Source | Description | Format |
|---|---|---|
| [opendata.swiss/BLV](https://opendata.swiss/de/organization/bundesamt-fur-lebensmittelsicherheit-und-veterinaerwesen-blv) | 28 open datasets | CSV, JSON, Parquet, SPARQL, XML |
| [lindas.admin.ch/sparql](https://lindas.admin.ch/sparql) | Swiss linked data SPARQL endpoint | RDF/SPARQL |
| [news.admin.ch RSS](https://www.newsd.admin.ch/newsd/feeds/rss?lang=de&org-nr=1079) | BLV public warnings & recalls | RSS/XML |
| [blv.admin.ch](https://www.blv.admin.ch) | BLV website (DE/FR/IT/EN) | HTML |

All data is open government data (OGD) under Creative Commons with attribution requirement.

---

## Known Limitations

- **RSS feed:** Limited to the most recent BLV publications; no historical archive
- **Pesticide register:** XML parsing may be slow for queries returning large result sets
- **CKAN datasets:** Opendata.swiss rate limits apply under heavy usage
- **Animal disease data:** Canton-level filtering depends on data completeness in the source
- **Datasets are pinned, not searched:** each data tool names its dataset slug and the resource that carries the data (see `DATENQUELLEN` in `server.py`). A keyword search takes the *first* hit and therefore falls back silently onto something plausible β€” that is how `blv_get_animal_health_stats` came to return antibiotics data, and how `blv_get_food_control_results` came to return a code list out of a dataset whose 26 resources include 18 of them. `scripts/record_fixtures.py` re-measures the pinned pairs on every run; a renamed dataset now fails loudly.
- **Children's nutrition is questionnaire tallies, not nutrient intake:** the only menuCH-Kids dataset published on opendata.swiss carries answer counts (`Geschlecht, Sprachregion, Altersgruppe, Frage, Antwort, Anzahl`). The docstring previously promised nutrient intake against dietary recommendations and offered "Energie", "Zucker", "Eisen" as filter examples β€” those matched nothing and returned an empty list. Adult food-consumption data exists as a separate dataset that this server does not cover.
- **The SPARQL-to-CSV fallback is gone.** It could never work: the one CSV resource of the fallback dataset is a ZIP file declared as `format: CSV`. With the endpoint corrected the fallback is also unnecessary β€” and a fallback that hides a broken query is worse than none.

---

## Safety & Limits

- **Read-only:** All tools perform HTTP GET requests only β€” no data is written, modified, or deleted.
- **No personal data:** The APIs return aggregated public health and food safety statistics. No personally identifiable information is processed or stored by this server.
- **Rate limits:** opendata.swiss CKAN and lindas.admin.ch SPARQL are public APIs; use `limit` and filtering parameters conservatively. The server enforces a 30-second timeout per request.
- **Data freshness:** RSS warnings reflect the latest BLV publications at query time. Statistical datasets (animal diseases, food control, antibiotics) are updated periodically by the BLV. No caching is performed by this server.
- **Terms of service:** Data is subject to the ToS of each source β€” [opendata.swiss](https://opendata.swiss/de/terms-of-use), [lindas.admin.ch](https://lindas.admin.ch), [news.admin.ch](https://www.admin.ch/gov/de/start/rechtliches.html). BLV data is published under Creative Commons with attribution.
- **No guarantees:** This server is a community project, not affiliated with the BLV or the Swiss federal administration. Availability depends on upstream APIs.

---

## Deployment & Scaling

This server is **Phase 1 β€” read-only** (see [`ROADMAP.md`](ROADMAP.md)): all
11 tools are read-only queries with no write surface.

Run it as a **single instance**. The Streamable HTTP transport keeps
per-session state, so horizontal scaling would require `Mcp-Session-Id` sticky
routing at the load balancer plus a shared session store β€” neither is
implemented, by design, for a server of this scope. A single Render instance
(or one container) is the supported deployment; `docker-compose.yml` sets
explicit CPU/memory limits for self-hosting.

---

## Testing

```bash
# Unit + contract tests (no network) β€” this is what CI runs
PYTHONPATH=src pytest tests/ -m "not live"

# All tests including live API checks
PYTHONPATH=src pytest tests/

# Re-measure which dataset and resource each tool hits
PYTHONPATH=src python scripts/record_fixtures.py
```

**54 tests** β€” 53 offline, 1 live.

### Why the fixtures are recorded rather than written

A hand-written mock encodes its author's assumption and therefore cannot
refute it: production code and fixture come from the same head, the same hour,
the same reading of the docs. Where both are wrong, both are wrong together β€”
and the suite stays green.

This repo had it in pure form. Every mocked CKAN resource was named
`"name": "CSV"`. On opendata.swiss the same field reads `Food establishments
2025` or `Food establishments codelist administrative measures` β€” and that
difference alone decided whether a tool returned inspection results or a code
legend. The mocks could not express the distinction, so no test could fail on
it.

What is recorded is therefore the **selection**: for each tool, the pinned
dataset slug, the resource that was hit, and that file's header line. The
header is the object of the exercise β€” it separates data from a legend, and it
shows whether the BOM and the delimiter were handled. `PROVENANCE.md` names the
source, the date, the selection rule and the SHA-256 for each file.

Two of the recorded measurements are **controls**: an invented path under
`lindas.admin.ch` (POST 404, so the 404 on `/sparql` is real) and an invented
class in the `fsvo` namespace (0 instances, so the previously queried `foag`
class genuinely does not exist). Without them each measurement would only show
what *we* received. The recorder aborts if a control stops discriminating, if a
pinned resource disappears, if a header line is empty or starts with a BOM, or
if one of the findings is superseded.

---

## MCP Protocol Version

This server speaks spec **`2026-07-28`** natively. It runs fastmcp 4.x, which
pins `mcp` 2.x, and that SDK serves *two* protocol eras over the same server
object:

| Era | Revision | How a client reaches it |
| --- | --- | --- |
| modern | **`2026-07-28`** | `server/discover`, metadata in `_meta.io.modelcontextprotocol/*` |
| handshake (legacy) | **`2025-11-25`** | the classic `initialize` exchange |

A current client gets `2026-07-28`; one that has not moved yet falls back to
the handshake and still gets every tool. Neither revision is chosen by this
server β€” the SDK negotiates, and the pin records which pair that negotiation is
allowed to produce.

The modern era is not just a higher number. It has **no `initialize` handshake
and no `InitializeResult`**: `Client.initialize()` raises there, and the server
metadata comes from `server/discover` instead. A check that still measured
`initialize_result.protocolVersion` would therefore be testing only the legacy
half while reporting a pass for both.

`tests/test_protocol_version.py` measures each era over its own path rather
than comparing constants to one another: it pins both revisions against
`LATEST_MODERN_VERSION` / `LATEST_HANDSHAKE_VERSION`, connects a real client in
each mode, asserts the structural absence of `InitializeResult` in the modern
one, and checks that both eras list the same tools. `test_das_sdk_fuehrt_weiterhin_zwei_aeren`
guards the other direction β€” a downgrade back to `mcp` 1.x would otherwise
reduce half of those assertions to an import error nobody reads.

The transport allow-list moved with the SDK: `Mcp-Method`, `Mcp-Name` and
`MCP-Protocol-Version` are the routing headers spec `2026-07-28` mirrors into
HTTP, and `mcp.shared.inbound` now reads them, so CORS lists them. `Mcp-Param-*`
is deliberately still absent β€” the spec mints those only for parameters a tool
marks with `x-mcp-header`, and no tool here does.

---

## Changelog

See [CHANGELOG.md](CHANGELOG.md)

---

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)

---

## Security

See [SECURITY.md](SECURITY.md) for the security policy and how to report a vulnerability.

---

## License

MIT License β€” see [LICENSE](LICENSE)

---

## Author

Hayal Oezkan Β· [github.com/malkreide](https://github.com/malkreide)

---

## Credits & Related Projects

- **Data:** [opendata.swiss / BLV](https://opendata.swiss/de/organization/bundesamt-fur-lebensmittelsicherheit-und-veterinaerwesen-blv) – Federal Food Safety and Veterinary Office (BLV)
- **Protocol:** [Model Context Protocol](https://modelcontextprotocol.io/) – Anthropic / Linux Foundation
- **Related:** [zurich-opendata-mcp](https://github.com/malkreide/zurich-opendata-mcp) – MCP server for Zurich city open data
- **Portfolio:** [Swiss Public Data MCP Portfolio](https://github.com/malkreide)

<!-- mcp-name: io.github.malkreide/swiss-food-safety-mcp -->

<!-- BEGIN GENERATED: install -->
## Installation

Run via [`uv`](https://docs.astral.sh/uv/)'s `uvx` β€” no clone or manual install needed. Add to your MCP client config (`mcpServers` for Claude Desktop, Cursor and Windsurf; use a top-level `servers` key for VS Code in `.vscode/mcp.json`):

```json
{
  "mcpServers": {
    "swiss-food-safety-mcp": {
      "command": "uvx",
      "args": [
        "swiss-food-safety-mcp"
      ]
    }
  }
}
```
<!-- END GENERATED: install -->

TDQS

A4.2/5.0

Scored across 11 tools

Disambiguation5/5

Each tool targets a distinct data source or operation (e.g., animal health stats, antibiotic usage, avian influenza, food control results, pesticide search). There is no overlap in purpose; even the two disease-related tools (blv_get_avian_influenza and blv_search_animal_diseases) differ in scopeβ€”wild bird surveillance vs. notifiable diseases. An agent can clearly select the correct tool.

Naming Consistency5/5

All tools follow a consistent 'blv_{verb}_{noun}' pattern in snake_case. Verbs are predictable: 'get' for retrieving specific datasets/stats, 'list' for browsing available datasets, 'search' for querying registries. No mixing of styles or vague verbs.

Tool Count5/5

With 11 tools, the server covers a broad spectrum of Swiss food safety data (animal health, food control, pesticides, nutrition, warnings) without being overwhelming. Each tool addresses a clear need, and the number feels well-scoped for the domain.

Completeness4/5

The tool set provides comprehensive coverage for the BLV's food safety and veterinary data: statistics, surveillance, inspections, warnings, and registry searches. Minor gaps exist (e.g., no tool for foodborne outbreak data or food contact materials), but core workflows like tracking recalls, comparing inspection results, and querying registries are fully supported.

Maintenance

ActivityActive
ResponsivenessNo issues