The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the Openlex MCP listing page.
🇨🇭 Part of the Swiss Public Data MCP Portfolio
MCP Server for Canton Zurich legislation (ZH-Lex) — full-text search, article extraction, and education law tools for ~970 cantonal laws
openlex-mcp provides AI-native access to the entire legal collection of Canton Zurich (Zürcher Gesetzessammlung). It combines full-text data from HuggingFace with live metadata from the official zh.ch website, storing everything in a local SQLite database with FTS5 full-text indexing for sub-50ms search performance.
| Source | Data | Access |
|---|---|---|
| HuggingFace | 974 ZH laws — full text (PDF extracts) | Cached locally as SQLite + FTS5 |
| zh.ch ZH-Lex | Current metadata, PDF links, validity status | Live HTTP requests |
Built for the Schulamt (school department) of the City of Zurich, but covers all areas of cantonal law — from tax law to building regulations.
Anchor demo query: "What does the Volksschulgesetz say about parental involvement? Show me Art. 55 VSG and find all articles that mention 'Elternrat'."
Current phase: Phase 1 — Read-Only. All tools are read-only (readOnlyHint: true); no writes to external systems. See ROADMAP.md for the phase plan and transition gates before any write or multi-agent capability is added.
By default the HTTP transport binds to 127.0.0.1 (localhost only). The host
and port are configurable via the MCP_HOST / MCP_PORT environment variables
(or the --host / --port CLI flags, which take precedence).
Never bind to 0.0.0.0 outside a container — it exposes the server to your
local network (NeighborJack risk). For containerized/cloud deployments set
MCP_HOST=0.0.0.0 explicitly; when that happens outside a detected container the
server logs a warning.
Try it immediately in Claude Desktop:
"What is the Volksschulgesetz (VSG)?" "Find all Zurich laws about data protection" "Show me Art. 1 of the Volksschulgesetz" "Which education laws mention 'Schulleitung'?"
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
Or with the installed entry point:
Config file locations:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonFor use via claude.ai in the browser (e.g. on managed workstations without local software):
Render.com (recommended):
python -m openlex_mcp.server --http --port 8000MCP_HOST=0.0.0.0 so the container is reachable
(the code default is 127.0.0.1; Render sets the RENDER env var, so no
NeighborJack warning is logged)MCP_CORS_ORIGINS=https://claude.ai so the browser can read the
Mcp-Session-Id header (comma-separated list; no wildcard — defaults to
empty, i.e. no cross-origin access)https://your-app.onrender.com/sse💡 "stdio for the developer laptop, SSE for the browser."
| Tool | Description |
|---|---|
openlex__zhlaw_search_laws | Full-text search across all ~970 ZH laws (FTS5 + BM25 ranking) |
openlex__zhlaw_get_law | Retrieve a law by LS number (e.g. 412.100) or abbreviation (e.g. VSG) |
openlex__zhlaw_list_laws | List and filter laws by legal area prefix |
openlex__zhlaw_find_education_laws | Specialized search in education law (LS 412.x series) |
| Tool | Description |
|---|---|
openlex__zhlaw_get_article | Extract a specific article from a law (e.g. Art. 28 VSG) |
openlex__zhlaw_search_articles | Search within all articles of a specific law |
| Tool | Description |
|---|---|
openlex__zhlaw_get_law_metadata | Get live metadata from zh.ch (PDF links, validity status) |
openlex__zhlaw_update_cache | Refresh the local data cache from HuggingFace |
| Prefix | Legal Area | Example |
|---|---|---|
131 | Constitution and popular rights | Kantonsverfassung |
170 | Administrative procedure | Datenschutzgesetz |
331 | Tax law | Steuergesetz |
412 | Education and schools | Volksschulgesetz (VSG) |
700 | Spatial planning and building | Planungs- und Baugesetz |
810 | Health | Gesundheitsgesetz |
| Query | Tool |
|---|---|
| "What is the Volksschulgesetz?" | openlex__zhlaw_get_law |
| "Find laws about data protection" | openlex__zhlaw_search_laws |
| "Show me Art. 55 VSG" | openlex__zhlaw_get_article |
| "Which education laws mention Schulleitung?" | openlex__zhlaw_find_education_laws |
| "Find all articles about Elternrat in the VSG" | openlex__zhlaw_search_articles |
| "Is LS 412.100 still in force?" | openlex__zhlaw_get_law_metadata |
| Source | Protocol | Coverage | Auth | License |
|---|---|---|---|---|
HuggingFace rcds/swiss_legislation | Datasets API | 974 ZH laws (full text) | None | CC-BY-SA 4.0 |
| zh.ch ZH-Lex | HTTP/HTML | Current metadata, PDFs | None | Public |
| LexFind.ch | HTTP | Cross-cantonal links | None | Public |
All 8 endpoints are exposed as Tools rather than MCP Resources. Rationale:
zhlex://laws/{sr_number}) are a future consideration for Phase 2 if clients benefit from resource-level caching or subscriptions.The Streamable-HTTP transport keeps session state in-process (FastMCP default). This has two implications:
Before scaling beyond one instance: either add a shared session store or configure your edge load balancer to route on the Mcp-Session-Id header with a stick-table and an appropriate TTL.
| Item | Value |
|---|---|
Served via the initialize handshake | 2024-11-05 … 2025-11-25 — the handshake ceiling |
| Served via the per-request envelope | 2026-07-28 |
| Who picks | The client's first request, once per connection. A request carrying the 2026-07-28 _meta envelope opens a modern connection; anything else opens a handshake connection. |
| SDK | mcp[cli]>=2.0.0,<3 |
| Cache hints | tools/list and server/discover: ttlMs 300000, cacheScope public |
| Pinned in | src/openlex_mcp/server.py — MCP_PROTOCOL_VERSION constant |
mcp is upgraded (via Dependabot PR), verify the protocol version in the SDK release notes.MCP_PROTOCOL_VERSION in server.py, regenerate docs/tool-hashes.json (PYTHONPATH=src python scripts/gen_tool_hashes.py --write), and note the change in CHANGELOG.md.pytest tests/ -m "not live" to confirm compatibility before merging.All tools return a structured response envelope (not Markdown text), so MCP
clients receive structuredContent they can parse directly:
html_content field is unreliable (cross-contaminated between laws); the server uses pdf_content instead, which is correct but has PDF extraction artefacts (hyphenation, layout artefacts)version_active_since = 2023-01-01; the HuggingFace dataset itself was last touched 2024-10-10. The 24-hour cache TTL and provenance="cache" describe where an answer came from, not how old the laws in it are. Every response now carries corpus_as_of and corpus_note alongside provenance.is_active = True and not one has a version_inactive_since. That is not a server bug — the source lists only the statutes in force at snapshot time. The consequence is what matters: a law repealed since then still appears to be in force. Consult the ZH-Lex permalink for the operative text.zhlaw_update_cache does not make the laws newer. It re-downloads the same frozen dataset. Its docstring previously read "only call when law search results seem outdated", which suggested exactly the effect it does not have.| Aspect | Details |
|---|---|
| Access | Read-only (readOnlyHint: true) — the server cannot modify or delete any data |
| Personal data | No personal data — all sources are aggregated, public legal texts |
| Rate limits | Built-in per-query caps (max 50 search results, 5000 chars content preview) |
| Timeout | 30 seconds per HTTP call to zh.ch |
| Egress | Outbound requests are restricted to an allow-list (www.zh.ch over HTTPS, plus the HTTP-only legacy permalink host www.zhlex.zh.ch), with SSRF IP-blocking and DNS-pinning — see docs/network-egress.md |
| Authentication | No API keys required — HuggingFace dataset is public, zh.ch is open |
| Security posture (Lethal Trifecta) | Score 1 / 3: public data only (no private/sensitive data) ✓ · GET-only egress to *.zh.ch — no POST, no webhooks, no email ✓ · no code execution ✓. Structurally safe by design. |
| Session handling | Mcp-Session-Id generated and managed by the MCP SDK (cryptographically secure UUIDs). No user-identity binding — auth_model=none is correct for public read-only data. If authentication is ever added, bind sessions to the validated OAuth sub claim before deployment. |
| Secrets | No secrets held — all data sources are public. See docs/secret-management.md. |
| Licenses | Law data: CC-BY-SA 4.0 (rcds/swiss_legislation); zh.ch metadata: public |
| Terms of Service | Subject to ToS of HuggingFace and Canton Zurich |
| Disclaimer | This server provides legal texts for informational purposes only — it does not constitute legal advice |
To report a vulnerability, see the Security Policy.
150 tests — 142 offline, 8 live. Eight tools, eight live tests: the best
coverage in this portfolio, which is why the finding here is not about
mechanics but about a confusion between two questions. provenance="cache"
answers where an answer came from; corpus_as_of answers how old the laws
in it are. Only the first was ever answered, and the second is the one a user
means when they ask "is this current?".
test_live_get_law_metadata fails in the recording environment: zhlex.zh.ch
is not reachable from it. Nothing follows from that. Public DNS resolves
the host (NOERROR, 194.247.8.174) and an NXDOMAIN control shows the query
discriminates — so the limit is the environment's, not the source's.
The test was therefore left untouched. A test you see red because your own
network cannot get out is not a test to rewrite; rewriting it would leave you
measuring your own environment instead of the source. PROVENANCE.md records
this as open.
See CHANGELOG.md
See ROADMAP.md
See CONTRIBUTING.md
See SECURITY.md
MIT License — see LICENSE
Hayal Oezkan · malkreide
Run via 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):