Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File not needed for this repository. Please remove it. Many Thanks!!

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Descripción
<!-- Qué cambios incluye este PR -->

## Tipo de cambio
- [ ] Feature (nueva funcionalidad)
- [ ] Bugfix (corrección de error)
- [ ] Hotfix (corrección urgente)
- [ ] Docs (documentación)
- [ ] Refactor (sin cambio funcional)

## Checklist
- [ ] Tests añadidos/actualizados
- [ ] Documentación actualizada
- [ ] `black` y `flake8` pasan
- [ ] Funciona con la API del BOE

## Testing
<!-- Cómo se ha probado este cambio -->

## Notas adicionales
<!-- Cualquier información relevante para los revisores -->
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 5
labels:
- dependencies
- python

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 5
labels:
- dependencies
- github-actions
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Check formatting with Black
run: python -m black --check src/
- name: Lint with flake8
run: python -m flake8 src/
- name: Type check with mypy
run: python -m mypy src/

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e ".[test]"
- name: Run tests with coverage
run: python -m pytest tests/ -v --cov=src/mcp_boe --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == '3.11'
with:
fail_ci_if_error: false

connectivity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install -e .
- name: Test BOE API connectivity
run: python examples/basic_usage.py connectivity
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build tools
run: pip install build twine
- name: Build package
run: python -m build
- name: Publish to PyPI
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
59 changes: 58 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,59 @@
# Python
*.pyc
__pycache__/
__pycache__/
*.pyo
*.pyd
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
env/
.venv/
.env/

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Testing
.pytest_cache/
.coverage
htmlcov/
.tox/
.nox/
coverage.xml
*.cover
*.py,cover

# Mypy
.mypy_cache/

# Local scripts (not part of the project)
crear_estructura_testing.sh
107 changes: 107 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

MCP-BOE is a Model Context Protocol (MCP) server that provides access to the Spanish Official State Gazette (BOE - Boletín Oficial del Estado) API. It allows LLMs like Claude to search consolidated legislation, daily BOE/BORME summaries, and auxiliary reference tables.

## Build & Development Commands

```bash
# Install for development
pip install -e ".[dev]"

# Install with REST API support
pip install -e ".[api]"

# Run the MCP server
python -m mcp_boe.server

# Server modes
python -m mcp_boe.server --mode server # Run MCP server (default)
python -m mcp_boe.server --mode test # Run test function
python -m mcp_boe.server --mode diagnose # Diagnose API connectivity

# Test connectivity
python examples/basic_usage.py connectivity

# Run all tests
python examples/basic_usage.py all

# Run specific tests
python examples/basic_usage.py search # Legislation search
python examples/basic_usage.py summary # BOE summaries
python examples/basic_usage.py departments # Auxiliary tables

# Start REST API wrapper
python rest_api_wrapper.py

# Linting and formatting
python -m black src/
python -m flake8 src/
python -m mypy src/

# Run pytest
python -m pytest tests/
```

## Architecture

### Core Components

- **`src/mcp_boe/server.py`**: Main MCP server (`BOEMCPServer`) that registers tool handlers and coordinates communication with MCP clients. Entry point is `main()`.

- **`src/mcp_boe/utils/http_client.py`**: `BOEHTTPClient` - async HTTP client for BOE API with retry logic, timeout handling, and XML/JSON parsing. Base URL: `https://www.boe.es/datosabiertos/api`

- **`src/mcp_boe/tools/`**: MCP tool implementations, each class provides `get_tools()` returning tool definitions and async methods for tool execution:
- `legislation.py` - `LegislationTools`: Search and retrieve consolidated legislation
- `summaries.py` - `SummaryTools`: BOE/BORME daily summaries
- `auxiliary.py` - `AuxiliaryTools`: Reference tables (departments, legal ranges, matters)

- **`src/mcp_boe/models/boe_models.py`**: Pydantic models and validation helpers (`validate_boe_identifier`, `validate_date_format`)

### Tool Registration Pattern

Tools are registered in `BOEMCPServer._setup_handlers()` via `@self.server.list_tools()` and `@self.server.call_tool()` decorators. Each tool class implements:
1. `get_tools()` - Returns list of `mcp.types.Tool` with JSON Schema input definitions
2. Async handler methods that return `List[TextContent]`

### API Endpoints Used

```
/legislacion-consolidada - Legislation search and retrieval
/boe/sumario/{date} - BOE daily summaries
/borme/sumario/{date} - BORME daily summaries
/tablas-auxiliares/{table} - Auxiliary tables (departamentos, rangos, materias, etc.)
```

### Key Identifiers

- BOE document IDs: `BOE-A-YYYY-NNNNN` (e.g., `BOE-A-2015-10566`)
- Date format: `YYYYMMDD` (e.g., `20240529`)
- Department codes: 4-digit strings (e.g., `7723` for Jefatura del Estado)
- Legal range codes: 4-digit strings (e.g., `1300` for Ley, `1200` for Real Decreto)

## Configuration

Environment variables for advanced configuration (see `BOEMCPConfig`):
- `BOE_HTTP_TIMEOUT`: Request timeout (default: 30s)
- `BOE_MAX_RETRIES`: Max retry attempts (default: 3)
- `BOE_RETRY_DELAY`: Delay between retries (default: 1s)
- `LOG_LEVEL`: Logging level (default: INFO)

## MCP Client Configuration

For Claude Code with uvx:
```json
{
"mcpServers": {
"mcp-boe": {
"command": "uvx",
"args": ["--from", "git+https://github.com/ComputingVictor/MCP-BOE.git", "mcp-boe"],
"transport": "stdio"
}
}
}
```
Loading