How esjavadex/ree-mcp works
1. What this repo is
- A Python 3.11+ MCP server that exposes Spanish grid data from REE/eSios to an LLM client such as Claude.
- The server’s job is to translate natural-language tool calls into typed REE data queries and return structured results.
2. Top-level architecture
- The code is split into four clear layers: interface, application, domain, and infrastructure.
- This matches Clean Architecture: outer layers handle transport and I/O; inner layers hold business rules and types.
3. Interface layer: MCP boundary
- src/ree_mcp/interface/mcp_server.py is the entry point for the MCP server runtime.
- tool_services.py, tool_helpers.py, and indicator_config.py define the tools Claude can call, parameter normalization, and indicator-specific metadata.
- This is the boundary between the MCP protocol and the app’s internal use cases.
4. Application layer: orchestration
- src/ree_mcp/application/use_cases/ contains the main workflows:
- list_indicators
- search_indicators
- get_indicator_data
- These use cases coordinate repository access and return DTOs from src/ree_mcp/application/dtos/.
- This layer does not know about MCP or HTTP; it only knows how to execute the business workflow.
5. Domain layer: core model
- src/ree_mcp/domain/entities/ models the REE concepts: indicator, indicator_data, and indicator_value.
- src/ree_mcp/domain/value_objects/ provides typed concepts such as indicator_id, datetime_range, geographic_scope, measurement_unit, and time_granularity.
- src/ree_mcp/domain/repositories/indicator_repository.py defines the repository interface the application depends on.
- domain/exceptions.py centralizes domain-level error types.
6. Infrastructure layer: REE integration
- src/ree_mcp/infrastructure/http/ree_api_client.py is the HTTP client for the external REE eSios API.
- src/ree_mcp/infrastructure/repositories/ree_indicator_repository.py implements the domain repository using that client.
- src/ree_mcp/infrastructure/config/settings.py handles runtime configuration, including API token loading from environment variables.
7. Primary data flow
- A Claude/MCP client invokes a tool on the server.
- The interface layer maps that request into a use case input.
- The use case calls the IndicatorRepository abstraction.
- The infrastructure repository fetches data from the REE API client.
- Results are converted into domain entities and application DTOs, then returned through the MCP tool response path.
8. How search and retrieval differ
- search_indicators and list_indicators support discovery of available REE indicators.
- get_indicator_data is the retrieval path for time-series or point-in-time data.
- This separation keeps metadata lookup distinct from actual data access.
9. Configuration and runtime
- The project is package-based under src/ree_mcp and runs as a module via src/ree_mcp/__main__.py.
- Configuration is environment-driven, with .env.example showing the expected REE API token.
- The README indicates the server is intended to be launched locally and connected to Claude Code via MCP.
10. Testing boundaries
- Tests are split by architectural layer:
- tests/unit/domain
- tests/unit/interface
- tests/integration/infrastructure
- tests/e2e
- This mirrors the architecture and helps verify domain rules, interface behavior, REE HTTP integration, and full MCP server behavior independently.
11. Tooling and delivery
- The repo uses uv, ruff, mypy, and GitHub Actions for CI.
- requirements*.txt, pyproject.toml, and uv.lock indicate reproducible Python packaging and dependency management.
- The workflow files suggest automated unit/integration/e2e validation on pull requests.
12. External boundary
- The only major external system is the REE eSios API.
- Everything else—MCP, Claude, and local configuration—exists to mediate access to that API while preserving a clean separation of concerns.
Main entry points: tool_services.py Tool services · indicator_repository.py Repository iface · get_indicator_data.py Get data · list_indicators.py List inds
Components 24
Interface
MCP boundary and tool wiring
- MCP server · Starts the MCP runtime and exposes tools to clients
src/ree_mcp/interface/mcp_server.py - Tool services · Defines callable MCP tools and request handling
src/ree_mcp/interface/tool_services.py - Tool helpers · Normalizes tool inputs and shared parameter handling
src/ree_mcp/interface/tool_helpers.py - Indicator config · Tool and indicator-specific metadata and mapping
src/ree_mcp/interface/indicator_config.py
Application
Use cases and DTOs
- Get data · Coordinates retrieval of indicator data
src/ree_mcp/application/use_cases/get_indicator_data.py - List inds · Returns available indicators
src/ree_mcp/application/use_cases/list_indicators.py - Search inds · Finds indicators by query or criteria
src/ree_mcp/application/use_cases/search_indicators.py - Indicator request · Input DTO for indicator workflows
src/ree_mcp/application/dtos/indicator_request.py - Indicator response · Output DTO for indicator workflows
src/ree_mcp/application/dtos/indicator_response.py
Domain
Core REE model and contracts
- Indicator · Core indicator metadata model
src/ree_mcp/domain/entities/indicator.py - Indicator data · Container for indicator values and context
src/ree_mcp/domain/entities/indicator_data.py - Value · Single measured indicator point
src/ree_mcp/domain/entities/indicator_value.py - Value objects · Typed domain concepts for IDs, ranges, units, and granularity
src/ree_mcp/domain/value_objects - Repository iface · Abstraction the application uses to access indicators
src/ree_mcp/domain/repositories/indicator_repository.py - Domain errors · Shared domain-level exception types
src/ree_mcp/domain/exceptions.py
Infrastructure
External API and persistence adapters
- Settings · Loads runtime configuration and API token
src/ree_mcp/infrastructure/config/settings.py - REE client · HTTP access to the external REE eSios API
src/ree_mcp/infrastructure/http/ree_api_client.py - REE repository · Implements the domain repository against REE HTTP APIs
src/ree_mcp/infrastructure/repositories/ree_indicator_repository.py
Tests
Layered verification of behavior
- Domain tests · Validates entities and value objects
tests/unit/domain - Interface tests · Validates tool config and helper behavior
tests/unit/interface - HTTP tests · Checks REE API client integration boundaries
tests/integration/infrastructure - E2E server · Exercises the MCP server end to end
tests/e2e
Runtime
Package entrypoint and local configuration
- Module entry · Package module entrypoint for local execution
src/ree_mcp/__main__.py - Env example · Example environment variables for local setup
.env.example
Connections 29
- MCP server → Tool services: exposes · Server wires tool services into the MCP boundary
- Tool services → Tool helpers: uses · Services rely on shared input normalization
- Tool services → Indicator config: reads · Services use indicator metadata to define tools
- Tool services → Get data: calls · Tool invocations dispatch into use cases
- Tool services → List inds: calls · Tool invocations dispatch into use cases
- Tool services → Search inds: calls · Tool invocations dispatch into use cases
- Get data → Indicator request: accepts · Use cases consume request DTOs
- Get data → Indicator response: returns · Use cases return response DTOs
- List inds → Indicator response: returns · Discovery use case returns response DTOs
- Search inds → Indicator response: returns · Discovery use case returns response DTOs
- Get data → Repository iface: depends on · Use case depends on repository abstraction
- List inds → Repository iface: depends on · Use case depends on repository abstraction
- Search inds → Repository iface: depends on · Use case depends on repository abstraction
- Repository iface → Indicator: shapes · Repository contract is expressed in domain terms
- Repository iface → Indicator data: shapes · Repository contract is expressed in domain terms
- Indicator data → Value: contains · Indicator data is composed of values
- Indicator → Value objects: uses · Entities rely on typed domain concepts
- Indicator data → Value objects: uses · Entities rely on typed domain concepts
- REE repository → REE client: uses · Repository adapter delegates to HTTP client
- REE repository → Repository iface: implements · Infrastructure fulfills the domain contract
- REE client → Settings: reads · HTTP client uses runtime configuration
- Module entry → MCP server: starts · Module entry launches the server runtime
- Env example → Settings: documents · Example environment values match runtime config
- Domain tests → Indicator: verifies · Domain tests cover entities and value objects
- Domain tests → Value objects: verifies · Domain tests cover entities and value objects
- Interface tests → Indicator config: verifies · Interface tests cover tool metadata
- Interface tests → Tool helpers: verifies · Interface tests cover normalization helpers
- HTTP tests → REE client: verifies · Integration tests cover the REE client boundary
- E2E server → MCP server: verifies · E2E tests exercise the full MCP path