MCP Server for Swiss federal law via the Fedlex SPARQL endpoint
Project description
:switzerland: Part of the Swiss Public Data MCP Portfolio
:balance_scale: fedlex-mcp
MCP Server for Swiss federal law — search the SR, monitor legal changes, and query BBl/treaties via Claude Desktop or Claude.ai
Overview
fedlex-mcp connects AI assistants (Claude) with the Fedlex SPARQL endpoint of the Swiss Federal Chancellery. This enables AI agents to look up Swiss federal law, monitor legal changes, and analyse legislation directly in conversation — without manual research on fedlex.admin.ch.
Metaphor: USB-C for federal law. Once connected, Claude can reach into the Systematic Compilation at any time.
Features
- :balance_scale: 7 tools, 2 resources covering the full breadth of Swiss federal law
- :mag: SPARQL-powered — direct access to the Fedlex linked data endpoint
- :globe_with_meridians: 4 languages — German, French, Italian, Romansh
- :unlock: No API key required — all data under open reuse licence
- :cloud: Dual transport — stdio (Claude Desktop) + Streamable HTTP (cloud)
Prerequisites
- Python 3.11+
- uv (recommended) or pip
Installation
# Clone the repository
git clone https://github.com/malkreide/fedlex-mcp.git
cd fedlex-mcp
# Install
pip install -e .
# or with uv:
uv pip install -e .
Or with uvx (no permanent installation):
uvx fedlex-mcp
Quickstart
# stdio (for Claude Desktop)
python -m fedlex_mcp.server
# Streamable HTTP (port 8000)
python -m fedlex_mcp.server --http --port 8000
Try it immediately in Claude Desktop:
"Show me all valid federal laws on vocational training" "What does the Data Protection Act say? Is it still in force?" "Which federal laws enter into force in the next 3 months?"
Configuration
Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"fedlex": {
"command": "python",
"args": ["-m", "fedlex_mcp.server"]
}
}
}
Or with uvx:
{
"mcpServers": {
"fedlex": {
"command": "uvx",
"args": ["fedlex-mcp"]
}
}
}
Config file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Cloud Deployment (SSE for browser access)
For use via claude.ai in the browser (e.g. on managed workstations without local software):
Render.com (recommended):
- Push/fork the repository to GitHub
- On render.com: New Web Service -> connect GitHub repo
- Set start command:
python -m fedlex_mcp.server --http --port 8000 - In claude.ai under Settings -> MCP Servers, add:
https://your-app.onrender.com/sse
"stdio for the developer laptop, SSE for the browser."
Demo
Available Tools
| Tool | Description |
|---|---|
fedlex_search_laws |
Search the Systematic Compilation (SR) by keyword in title |
fedlex_get_law_by_sr |
Get a law by its SR number (e.g. 235.1 = Data Protection Act) |
fedlex_get_recent_publications |
Latest publications from the Official Compilation (AS) |
fedlex_get_upcoming_changes |
Laws entering into force soon (legal monitoring) |
fedlex_search_gazette |
Search the Federal Gazette (BBl) |
fedlex_get_law_history |
All versions of a law (version history) |
fedlex_search_treaties |
International treaties (SR numbers starting with 0.) |
Example Use Cases
| Query | Tool |
|---|---|
| "Show me all valid federal laws on vocational training" | fedlex_search_laws |
| "What does the Data Protection Act say?" | fedlex_get_law_by_sr |
| "Which laws enter into force in the next 3 months?" | fedlex_get_upcoming_changes |
| "What did the Federal Council publish this week?" | fedlex_get_recent_publications |
| "Show me the version history of the DSG" | fedlex_get_law_history |
| "Which education treaties does Switzerland have with the EU?" | fedlex_search_treaties |
→ More use cases by audience →
Architecture
+-------------------+ +------------------------------+ +--------------------------+
| Claude / AI |---->| Fedlex MCP |---->| Fedlex SPARQL Endpoint |
| (MCP Host) |<----| (MCP Server) |<----| (Swiss Federal |
+-------------------+ | | | Chancellery) |
| 7 Tools . 2 Resources | +--------------------------+
| Stdio | SSE |
| |
| No authentication required |
+------------------------------+
Data Model (JOLux Ontology)
jolux:ConsolidationAbstract <- SR entry
+-- jolux:isRealizedBy -> jolux:Expression (URI ends in /de, /fr, /it, /rm)
+-- jolux:title "Federal Act of 19 June 1992 on Data Protection"
+-- jolux:titleShort "DSG"
+-- jolux:historicalLegalId "235.1"
jolux:inForceStatus:
.../0 In force
.../1 No longer published in the SR
.../3 No longer in force
SPARQL Endpoint: https://fedlex.data.admin.ch/sparqlendpoint
Licence: Free reuse (commercial and other purposes) per fedlex.admin.ch
Languages
| Code | Language |
|---|---|
de |
German (default, most complete coverage) |
fr |
French |
it |
Italian |
rm |
Romansh |
Project Structure
fedlex-mcp/
+-- src/fedlex_mcp/
| +-- __init__.py # Package
| +-- server.py # 7 tools, 2 resources
+-- tests/
| +-- test_server.py # Unit tests (mocked)
+-- .github/workflows/ci.yml # GitHub Actions (Python 3.11/3.12/3.13)
+-- pyproject.toml
+-- CHANGELOG.md
+-- CONTRIBUTING.md
+-- LICENSE
+-- README.md # This file (English)
+-- README.de.md # German version
Known Limitations
- SPARQL complexity: Very broad keyword searches may time out (45s timeout)
- Language coverage: German has the most complete data; other languages may have gaps
- Historical data: Not all historical versions of laws have machine-readable metadata
- Rate limiting: The Fedlex endpoint may throttle high-frequency requests
Project Phase
This server is in Phase 1 (read-only). All tools are annotated
readOnlyHint: true / destructiveHint: false and only ever query the public
Fedlex SPARQL endpoint — there are no write, send, or filesystem capabilities.
| Phase | Scope | Status |
|---|---|---|
| 1 — Read-only | Query SR/AS/BBl/treaties | ✅ current |
| 2 — Write-capable | (none planned) | — |
| 3 — Multi-agent | (none planned) | — |
A transition to a later phase would require an audit re-run and the human-in-the-loop controls described in the audit catalog before any write-capable tool is added.
MCP Protocol Version
The protocol version is negotiated at the initialize handshake by the
mcp Python SDK (pinned to >=1.3.0 in
pyproject.toml). The SDK is kept current via monthly Dependabot PRs
(.github/dependabot.yml); protocol-relevant bumps are noted in
CHANGELOG.md.
Testing
# Unit tests (no API key required)
PYTHONPATH=src pytest tests/ -m "not live"
# Integration tests (live API calls)
pytest tests/ -m "live"
Safety & Limits
- Read-only: All tools perform SPARQL SELECT queries only — no data is written, modified, or deleted on the Fedlex endpoint.
- No personal data: Fedlex contains public law texts and official gazettes. No personally identifiable information (PII) is processed or stored by this server.
- Rate limits: The Fedlex SPARQL endpoint is a public service without a documented rate limit; use
limitparameters conservatively. The server enforces a 45s timeout per request. - Data freshness: Results reflect the Fedlex endpoint at query time. No caching is performed by this server.
- Terms of service: Data is subject to the reuse conditions of fedlex.admin.ch — free reuse for commercial and other purposes.
- No guarantees: This server is a community project, not affiliated with the Swiss Federal Chancellery. Availability depends on the upstream SPARQL endpoint.
Changelog
See CHANGELOG.md
Contributing
See CONTRIBUTING.md
License
MIT License — see LICENSE
Author
Hayal Oezkan . malkreide
Credits & Related Projects
- Fedlex: fedlex.admin.ch — Swiss Federal Chancellery
- Protocol: Model Context Protocol — Anthropic / Linux Foundation
- Related: swiss-cultural-heritage-mcp — Swiss cultural heritage data
- Related: zurich-opendata-mcp — City of Zurich open data
- Related: swiss-transport-mcp — Swiss public transport
- Portfolio: Swiss Public Data MCP Portfolio
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fedlex_mcp-1.0.0.tar.gz.
File metadata
- Download URL: fedlex_mcp-1.0.0.tar.gz
- Upload date:
- Size: 92.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55f7425efcbceb918dbc0de061e10d3bce5e33a2ad4c1ba26c5edc31c389e666
|
|
| MD5 |
c9badb03f285ee8bdb9a52ac7e34b457
|
|
| BLAKE2b-256 |
a1e39459ff6d21f32d57a0bdcb7ff68c0e6b273da49d4bce8987486bed5281c2
|
Provenance
The following attestation bundles were made for fedlex_mcp-1.0.0.tar.gz:
Publisher:
publish.yml on malkreide/fedlex-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fedlex_mcp-1.0.0.tar.gz -
Subject digest:
55f7425efcbceb918dbc0de061e10d3bce5e33a2ad4c1ba26c5edc31c389e666 - Sigstore transparency entry: 1708929805
- Sigstore integration time:
-
Permalink:
malkreide/fedlex-mcp@a9529dd4de9266b79d2b608f013bc8bba6bb9e4e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/malkreide
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a9529dd4de9266b79d2b608f013bc8bba6bb9e4e -
Trigger Event:
release
-
Statement type:
File details
Details for the file fedlex_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fedlex_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
611e834dd14b94e1ceef0422fbc7fdc0d3685fad5571614c8879a4fe640ccbd5
|
|
| MD5 |
2a43d0690d60823a6efd8a1c03779e7e
|
|
| BLAKE2b-256 |
a0f4ae13ed99ae50f0bf35b7d58379d89f16ad426c297915e63862c786cbfd51
|
Provenance
The following attestation bundles were made for fedlex_mcp-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on malkreide/fedlex-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fedlex_mcp-1.0.0-py3-none-any.whl -
Subject digest:
611e834dd14b94e1ceef0422fbc7fdc0d3685fad5571614c8879a4fe640ccbd5 - Sigstore transparency entry: 1708929866
- Sigstore integration time:
-
Permalink:
malkreide/fedlex-mcp@a9529dd4de9266b79d2b608f013bc8bba6bb9e4e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/malkreide
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a9529dd4de9266b79d2b608f013bc8bba6bb9e4e -
Trigger Event:
release
-
Statement type: