联邦法律查询工具

一个用于查询瑞士联邦法律的工具,提供实时SPARQL查询和本地SQLite数据库支持,适用于法律研究和信息检索。

  • by loicvuilliomenet-boop
  • TypeScript
  • 混合部署
  • 1 星标
  • 更新于
在 GitHub 查看 loicvuilliomenet-boop/fedlex-mcp

使用说明

fedlex mcp

瑞士联邦立法的MCP服务器 Fedlex.

提供两个互补的访问层:

  • 实时SPARQL工具 --实时查询Fedlex SPARQL端点(除此之外无需进行本地设置 npm run build)
  • SQLite支持的工具 --快速、离线的工具,可与由构建的本地数据库协同工作 npm run ingest

实验项目。不是法律建议。始终根据Fedlex官方消息来源进行核实。


工具

实时SPARQL工具

这些查询 https://fedlex.data.admin.ch/sparqlendpoint 直接使用,不需要本地数据库。

工具 说明
search_legislation 在法律标题和缩写中按关键字搜索
list_legislation 列出所有现行法律(分页)
get_legislation 通过SR编号或ELI URI获取法律的元数据
get_legislation_text 获取法律的全文(HTML或XML)
get_versions 列出所有历史合并版本
get_citations 法律引用图(哪些法律引用了哪些法律)

SQLite支持的工具

这些功能针对的是由构建的本地SQLite数据库 npm run ingest。它们更快,离线工作,并提供仅通过SPARQL无法获得的功能。

工具 说明
search_provisions FTS5全文搜索所有文章文本(约10万条规定)
lookup_definition 在所有立法中按术语查找正式的法律定义
find_eu_references 实施或引用特定欧盟指令/法规的瑞士法律
get_article_citations 文章引用图(具体引用哪些文章)
get_db_stats 数据库统计信息:计数、大小和上次摄取时间戳

get_article_citations 比 get_citations:它没有“A法引用B法”,而是返回“《刑法》第12条引用《数据保护法》第3条”。


标识符

每一个需要 identifier 接受以下任一条件:

  • 一 SR编号 --例如。 "101" (联邦宪法), "210" (民法典), "311.0" (《刑法》), "220" (义务准则)
  • 满的 伊莱·乌里 --例如。 "https://fedlex.data.admin.ch/eli/cc/1999/404"

语言

所有工具支持 language: "fr" | "de" | "it" | "rm" (默认值: "fr").


设置

1.安装和构建

npm install && npm run build

2.(可选)构建本地SQLite数据库

SQLite支持的工具需要。从Fedlex下载并解析所有HTML法规(约7000条法律,通常15-30分钟,具体取决于连接):

npm run ingest

选项:

标志 默认值 描述
--lang fr 要摄取的语言(de, fr, it)
--concurrency 5 并行HTML获取
--db ./data/fedlex.sqlite SQLite文件的输出路径

您还可以设置 FEDLEX_DB_PATH 作为环境变量,将服务器指向现有数据库。

摄入管道:

  1. 获取全部 ConsolidationAbstract SPARQL中的条目
  2. 根据法律解决最新的整合和下载URL问题
  3. 获取并解析HTML文档以提取文章条款
  4. 每篇文章摘录法律定义和欧盟交叉引用
  5. 重建FTS5全文索引
  6. 从SPARQL获取文章级引用边并将其存储
  7. 在数据库文件旁边写入JSON摘要报告

用法

stdio(本地/克劳德桌面)

node dist/index.js

Claude桌面配置 (~/.claude/claude_desktop_config.json):

{
  "mcpServers": {
    "fedlex": {
      "command": "node",
      "args": ["/path/to/fedlex-mcp/dist/index.js"]
    }
  }
}

要使用预构建的数据库,请添加 FEDLEX_DB_PATH 转到env:

{
  "mcpServers": {
    "fedlex": {
      "command": "node",
      "args": ["/path/to/fedlex-mcp/dist/index.js"],
      "env": { "FEDLEX_DB_PATH": "/path/to/fedlex.sqlite" }
    }
  }
}

HTTP/SSE(在线部署)

node dist/index.js --http
# custom port:
PORT=8080 node dist/index.js --http

MCP端点:

  • GET /sse --MCP客户端的SSE流
  • POST /messages?sessionId=<id> --信息中继

码头工人

docker build -t fedlex-mcp .
docker run -p 3000:3000 fedlex-mcp

部署到Railway/Render/Fly.io

将启动命令设置为 node dist/index.js --http 并暴露端口 3000 (或设置 PORT 有人)。


REST API

所有工具也都可以作为普通HTTP GET端点在 /api/。适用于浏览器客户端或非MCP集成。

实时SPARQL端点

GET /api/search?q=<query>&lang=fr&limit=20&in_force=true
GET /api/list?lang=fr&limit=50&offset=0&in_force=true
GET /api/legislation/:id?lang=fr
GET /api/text/:id?lang=fr&format=html&version=2024-01-01
GET /api/versions/:id
GET /api/citations/:id?direction=both&lang=fr&limit=50

SQLite支持的端点

GET /api/db/search?q=<query>&limit=20&sr=235.1
GET /api/db/definitions?term=<term>&limit=20
GET /api/db/eu-refs?id=2016/679&type=Directive&limit=30
GET /api/db/article-citations?sr=311.0&article=art_1&direction=both&limit=50
GET /api/db/stats

参数 /api/db/article-citations:

参数 必填 说明
sr 是 法律的SR编号
article 否 按HTML id筛选特定文章(例如。 art_1, art_2a)
direction 没有 from (传出), to (传入),或 both (默认)
limit 否 每个方向的最大结果(默认50,最大200)

例子

实时SPARQL工具

search_legislation("protection des données")
→ finds LPD (SR 235.1) and related ordinances

get_legislation("235.1")
→ metadata for the Loi fédérale sur la protection des données

get_legislation_text("311.0", language="fr")
→ full text of the Code pénal suisse

get_versions("220")
→ all historical versions of the Code des obligations

get_citations("101", direction="from", language="fr")
→ all laws that cite the Constitution fédérale

search_legislation("Datenschutz", language="de")
→ same search in German

SQLite支持的工具

search_provisions("données personnelles sensibles", sr_number="235.1")
→ FTS5 search within the LPD for that phrase

lookup_definition("personne concernée")
→ all formal definitions of that term across Swiss federal law

find_eu_references(eu_identifier="2016/679")
→ Swiss laws referencing the GDPR

get_article_citations("311.0", article_id="art_12", direction="both")
→ articles that Art. 12 CP cites, and articles in other laws that cite Art. 12 CP

get_db_stats()
→ total counts of laws, provisions, definitions, EU references, article citations

数据源

所有数据均来自瑞士联邦总理府 Fedlex平台 通过:

  • SPARQL端点: https://fedlex.data.admin.ch/sparqlendpoint
  • 本体论: JOLux (基于FRBR、ELI)
  • 可用格式:PDF、HTML、XML(Akoma Ntoso,自2022年以来)、DOCX
  • 覆盖所有机密汇编文本----法令、条例、条例、条约

免责声明

该项目是一个独立的实验性MCP服务器,用于访问来自瑞士联邦总理府Fedlex平台的信息。它仅用于技术和信息目的。

  • 没有法律建议。 本项目产生的任何内容均不构成法律建议、法律意见或专业律师的替代品。
  • 无保修。 该软件已提供 “原样”,没有任何形式的保证。输出可能不完整、不准确、不可用、解析不当或过时。
  • 与官方消息来源核实。 用户在依赖Fedlex官方来源之前,必须独立验证所有法律文本、参考文献、元数据和结论。
  • 使用风险自负。 作者对错误、遗漏、停机、对法律材料的误解,或因使用本项目而产生的任何直接或间接后果不承担任何责任。
  • 第三方来源依赖。 可用性和正确性部分取决于上游Fedlex服务、数据格式和网络条件,这些可能会在不另行通知的情况下发生变化。

通过使用这个项目,你接受了它是一个尽力而为的工具,而不是一个权威的法律记录系统。