西班牙官方公报的模型上下文协议
<img width="512" height="512" alt="image" src="https://github.com/user-attachments/assets/cd1c5e79-add7-466c-bcbd-554b81a2fef9" />这是一个MCP服务器,允许Claude和其他大型语言模型访问官方BOE API,以查询西班牙政府的立法、每日摘要和辅助表格。
如果你已经安装了uvx,你可以直接使用MCP服务器而无需手动安装:
# 检查uvx是否已安装
uvx --version
# 直接从仓库执行
uvx --from git+https://github.com/ComputingVictor/MCP-BOE.git mcp-boe --help
# 克隆仓库
git clone https://github.com/ComputingVictor/MCP-BOE.git
cd MCP-BOE
# 安装基本依赖
pip install -e .
# 或者安装带有API REST的依赖
pip install -e ".[api]"
# 或者安装全部用于开发的依赖
pip install -e ".[dev]"
# 快速测试连通性
python examples/basic_usage.py connectivity
# 测试全部功能
python examples/basic_usage.py quick
# 检查一切是否正常工作
python examples/basic_usage.py connectivity
# 交互式探索功能
python examples/basic_usage.py interactive
# 搜索立法
python examples/basic_usage.py search
# 查看BOE摘要
python examples/basic_usage.py summary
# 查询部门
python examples/basic_usage.py departments
uvx 是一个大大简化Python包安装和执行的工具。使用UVX,你不需要:
uvx会自动创建一个隔离环境并下载所有必要的依赖。
{
"mcpServers": {
"mcp-boe": {
"command": "uvx",
"args": ["--from", "git+https://github.com/ComputingVictor/MCP-BOE.git", "mcp-boe"],
"transport": "stdio"
}
}
}
你也可以使用包含的示例配置文件:
# 下载并使用示例配置
curl -O https://raw.githubusercontent.com/ComputingVictor/MCP-BOE/main/claude_mcp_config_uvx.json
# 使用自定义配置
/config-mcp /路径/到/你的/claude_mcp_config.json
# 或使用示例配置
/config-mcp claude_m
{
"mcpServers": {
"mcp-boe": {
"command": "/路径/到/你的/conda/envs/你的环境/bin/python",
"args": ["-m", "mcp_boe.server"],
"transport": "stdio",
"env": {
"PYTHONPATH": "/路径/到/你的/MCP-BOE/src"
}
}
}
}
/config-mcp /路径/到/你的/claude_mcp_config.json
你能查找关于《2015年第40号法律》的信息吗?
显示本周的BOE摘要
哪些部门包含“部”这个词?
# 安装开放WebUI
pip install open-webui
# 配置环境变量
export PYTHONPATH=/路径/到/你的/MCP-BOE/src
# 启动服务
ollama serve &
open-webui serve
要从web、移动设备或任何HTTP客户端使用:
python rest_api_wrapper.py
API将在以下地址可用:http://localhost:8000
交互式文档:http://localhost:8000/docs
curl -X POST "http://localhost:8000/search/legislation" \
-H "Content-Type: application/json" \
-d '{"query": "西班牙宪法", "limit": 5}'
curl -X POST "http://localhost:8000/summary/boe" \
-H "Content-Type:
application/json" \
-d '{"max_items": 10}'
curl -X POST "http://localhost:8000/auxiliary/departments" \
-H "Content-Type: application/json" \
-d '{"search_term": "部", "limit": 10}'
curl "http://localhost:8000/auxiliary/code/7723"
from mcp_boe import BOEHTTPClient
from mcp_boe.tools.legislation import LegislationTools
async def buscar_ley():
async with BOEHTTPClient() as client:
tools = LegislationTools(client)
# 搜索《2015年第40号法律》
resultados = await tools.search_consolidated_legislation({
"query": "2015年第40号法律",
"limit": 3
})
for resultado in resultados:
print(resultado.text)
from mcp_boe.tools.summaries import SummaryTools
from datetime import datetime, timedelta
async def sumario_boe():
async with BOEHTTPClient() as client:
tools = SummaryTools(client)
# 三天前的摘要
fecha = (datetime.now() - timedelta(days=3)).strftime("%Y%m%d")
resultados = await tools.get_boe_summary({
"date": fecha,
"max_items": 5
})
for resultado in resultados:
print(resultado.text)
from mcp_boe.tools.auxiliary import AuxiliaryTools
async def buscar_departamentos():
async with BOEHTTPClient() as client:
tools = AuxiliaryTools(client)
# 搜索部
resultados = await tools.get_departments_table({
"search_term": "部",
"limit": 10
})
for resultado in resultados:
print(resultado.text)
| 工具 | 描述 | 参数 |
|---|---|---|
search_consolidated_legislation 搜索已整合立法。 query, limit, offset | ||
get_consolidated_law 获取特定规则。 law_id, include_metadata, include_analysis, include_full_text | ||
get_law_structure 查看标准结构。 law_id |
| 工具 | 描述 | 参数 |
|---|---|---|
get_boe_summary 根据日期获取BOE摘要。 date, max_items | ||
get_borme_summary 根据日期获取BORME摘要 | date, max_items | |
search_recent_boe 搜索最近的BOE。 days_back, search_terms |
| 工具 | 描述 | 参数 |
|---|---|---|
get_departments_table 部门代码。 search_term, limit | ||
get_legal_ranges_table | 规范范围 | limit |
get_code_description 特定代码描述。 code | ||
search_auxiliary_data 搜索所有表格 | query |
# 所有测试
python examples/basic_usage.py all
# 快速测试
python examples/basic_usage.py quick
# 特定测试
python examples/basic_usage.py search
python examples/basic_usage.py summary
python examples/basic_usage.py departments
git checkout -b feature/new-feature)git commit -am '添加新功能')git push origin feature/new-feature)# 配置开发环境
python -m venv venv
source venv/bin/activate # 在Windows上:venv\Scripts\activate
pip install -e .
# 运行测试
python -m pytest tests/
# 代码检查
python -m black src/
python -m flake8 src/
MCP-BOE/
├── src/mcp_boe/ # 主要源代码
│ ├── models/ # Pydantic模型
│ ├── tools/ # MCP工具
│ ├── utils/ # 实用工具(HTTP客户端)
│ └── server.py # 主MCP服务器
├── examples/ # 使用示例
├── tests/ # 单元测试
├── pyproject.toml # 项目配置和依赖
├── rest_api_wrapper.py # 可选的API REST包装器
└── README.md # 此文件
export PYTHONPATH="${PYTHONPATH}:/路径/到/你的/MCP-BOE/src"
检查与BOE API的连通性:
python examples/basic_usage.py connectivity
Pydantic v2警告是正常的,不会影响功能。
本项目采用MIT许可证。查看LICENSE文件了解详情。
Victor Viloria
有任何疑问? 打开一个问题或提交一个pull request。
喜欢这个项目吗? 在GitHub上给它一个⭐。