# esjavadex/ree-mcp architecture

> Architecture diagram of the GitHub repository esjavadex/ree-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/esjavadex/ree-mcp
- Repository: https://github.com/esjavadex/ree-mcp

## Overview

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: [`src/ree_mcp/interface/tool_services.py`](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/tool_services.py) (Tool services), [`src/ree_mcp/domain/repositories/indicator_repository.py`](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/repositories/indicator_repository.py) (Repository iface), [`src/ree_mcp/application/use_cases/get_indicator_data.py`](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/get_indicator_data.py) (Get data), [`src/ree_mcp/application/use_cases/list_indicators.py`](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/list_indicators.py) (List inds)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_interface["Interface"]
  node_n_mcp_server["MCP server<br/>entrypoint<br/>[mcp_server.py]"]
  node_n_tool_services["Tool services<br/>tooling<br/>[tool_services.py]"]
  node_n_tool_helpers["Tool helpers<br/>adapter<br/>[tool_helpers.py]"]
  node_n_indicator_config["Indicator config<br/>metadata"]
end

subgraph group_grp_application["Application"]
  node_n_get_data["Get data<br/>use case"]
  node_n_list_inds["List inds<br/>use case<br/>[list_indicators.py]"]
  node_n_search_inds["Search inds<br/>use case"]
  node_n_indicator_req["Indicator request<br/>dto"]
  node_n_indicator_resp["Indicator response<br/>dto"]
end

subgraph group_grp_domain["Domain"]
  node_n_indicator_entity["Indicator<br/>entity<br/>[indicator.py]"]
  node_n_indicator_data["Indicator data<br/>entity<br/>[indicator_data.py]"]
  node_n_indicator_value(("Value<br/>entity<br/>[indicator_value.py]"))
  node_n_value_objects{{"Value objects<br/>types"}}
  node_n_repo_iface["Repository iface<br/>contract"]
  node_n_domain_ex["Domain errors<br/>exceptions<br/>[exceptions.py]"]
end

subgraph group_grp_infrastructure["Infrastructure"]
  node_n_settings["Settings<br/>config<br/>[settings.py]"]
  node_n_api_client["REE client<br/>http client<br/>[ree_api_client.py]"]
  node_n_repo_impl["REE repository<br/>adapter"]
end

subgraph group_grp_tests["Tests"]
  node_n_unit_domain["Domain tests"]
  node_n_unit_interface["Interface tests"]
  node_n_integration_http["HTTP tests"]
  node_n_e2e_mcp["E2E server<br/>tests"]
end

subgraph group_grp_runtime["Runtime"]
  node_n_main["Module entry<br/>runtime<br/>[__main__.py]"]
  node_n_env["Env example<br/>config<br/>[.env.example]"]
end

node_n_mcp_server -->|"exposes"| node_n_tool_services
node_n_tool_services -->|"uses"| node_n_tool_helpers
node_n_tool_services -->|"reads"| node_n_indicator_config
node_n_tool_services -->|"calls"| node_n_get_data
node_n_tool_services -->|"calls"| node_n_list_inds
node_n_tool_services -->|"calls"| node_n_search_inds
node_n_get_data -->|"accepts"| node_n_indicator_req
node_n_get_data -->|"returns"| node_n_indicator_resp
node_n_list_inds -->|"returns"| node_n_indicator_resp
node_n_search_inds -->|"returns"| node_n_indicator_resp
node_n_get_data -->|"depends on"| node_n_repo_iface
node_n_list_inds -->|"depends on"| node_n_repo_iface
node_n_search_inds -->|"depends on"| node_n_repo_iface
node_n_repo_iface -->|"shapes"| node_n_indicator_entity
node_n_repo_iface -->|"shapes"| node_n_indicator_data
node_n_indicator_data -->|"contains"| node_n_indicator_value
node_n_indicator_entity -->|"uses"| node_n_value_objects
node_n_indicator_data -->|"uses"| node_n_value_objects
node_n_repo_impl -->|"uses"| node_n_api_client
node_n_repo_impl -->|"implements"| node_n_repo_iface
node_n_api_client -->|"reads"| node_n_settings
node_n_main -->|"starts"| node_n_mcp_server
node_n_env -.->|"documents"| node_n_settings
node_n_unit_domain -->|"verifies"| node_n_indicator_entity
node_n_unit_domain -->|"verifies"| node_n_value_objects
node_n_unit_interface -->|"verifies"| node_n_indicator_config
node_n_unit_interface -->|"verifies"| node_n_tool_helpers
node_n_integration_http -->|"verifies"| node_n_api_client
node_n_e2e_mcp -->|"verifies"| node_n_mcp_server

click node_n_mcp_server "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/mcp_server.py"
click node_n_tool_services "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/tool_services.py"
click node_n_tool_helpers "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/tool_helpers.py"
click node_n_indicator_config "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/indicator_config.py"
click node_n_get_data "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/get_indicator_data.py"
click node_n_list_inds "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/list_indicators.py"
click node_n_search_inds "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/search_indicators.py"
click node_n_indicator_req "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/dtos/indicator_request.py"
click node_n_indicator_resp "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/dtos/indicator_response.py"
click node_n_indicator_entity "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/entities/indicator.py"
click node_n_indicator_data "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/entities/indicator_data.py"
click node_n_indicator_value "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/entities/indicator_value.py"
click node_n_value_objects "https://github.com/esjavadex/ree-mcp/tree/main/src/ree_mcp/domain/value_objects"
click node_n_repo_iface "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/repositories/indicator_repository.py"
click node_n_domain_ex "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/exceptions.py"
click node_n_settings "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/infrastructure/config/settings.py"
click node_n_api_client "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/infrastructure/http/ree_api_client.py"
click node_n_repo_impl "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/infrastructure/repositories/ree_indicator_repository.py"
click node_n_main "https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/__main__.py"
click node_n_env "https://github.com/esjavadex/ree-mcp/blob/main/.env.example"
click node_n_unit_domain "https://github.com/esjavadex/ree-mcp/tree/main/tests/unit/domain"
click node_n_unit_interface "https://github.com/esjavadex/ree-mcp/tree/main/tests/unit/interface"
click node_n_integration_http "https://github.com/esjavadex/ree-mcp/tree/main/tests/integration/infrastructure"
click node_n_e2e_mcp "https://github.com/esjavadex/ree-mcp/tree/main/tests/e2e"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_mcp_server,node_n_tool_services,node_n_tool_helpers,node_n_indicator_config toneBlue
class node_n_get_data,node_n_list_inds,node_n_search_inds,node_n_indicator_req,node_n_indicator_resp toneAmber
class node_n_indicator_entity,node_n_indicator_data,node_n_indicator_value,node_n_value_objects,node_n_repo_iface,node_n_domain_ex toneMint
class node_n_settings,node_n_api_client,node_n_repo_impl toneRose
class node_n_unit_domain,node_n_unit_interface,node_n_integration_http,node_n_e2e_mcp toneIndigo
class node_n_main,node_n_env toneTeal
```

## Components

### Interface

MCP boundary and tool wiring

- [MCP server](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/mcp_server.py): entrypoint · Starts the MCP runtime and exposes tools to clients · `src/ree_mcp/interface/mcp_server.py`
- [Tool services](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/tool_services.py): tooling · Defines callable MCP tools and request handling · `src/ree_mcp/interface/tool_services.py`
- [Tool helpers](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/tool_helpers.py): adapter · Normalizes tool inputs and shared parameter handling · `src/ree_mcp/interface/tool_helpers.py`
- [Indicator config](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/interface/indicator_config.py): metadata · Tool and indicator-specific metadata and mapping · `src/ree_mcp/interface/indicator_config.py`

### Application

Use cases and DTOs

- [Get data](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/get_indicator_data.py): use case · Coordinates retrieval of indicator data · `src/ree_mcp/application/use_cases/get_indicator_data.py`
- [List inds](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/list_indicators.py): use case · Returns available indicators · `src/ree_mcp/application/use_cases/list_indicators.py`
- [Search inds](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/use_cases/search_indicators.py): use case · Finds indicators by query or criteria · `src/ree_mcp/application/use_cases/search_indicators.py`
- [Indicator request](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/dtos/indicator_request.py): dto · Input DTO for indicator workflows · `src/ree_mcp/application/dtos/indicator_request.py`
- [Indicator response](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/application/dtos/indicator_response.py): dto · Output DTO for indicator workflows · `src/ree_mcp/application/dtos/indicator_response.py`

### Domain

Core REE model and contracts

- [Indicator](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/entities/indicator.py): entity · Core indicator metadata model · `src/ree_mcp/domain/entities/indicator.py`
- [Indicator data](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/entities/indicator_data.py): entity · Container for indicator values and context · `src/ree_mcp/domain/entities/indicator_data.py`
- [Value](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/entities/indicator_value.py): entity · Single measured indicator point · `src/ree_mcp/domain/entities/indicator_value.py`
- [Value objects](https://github.com/esjavadex/ree-mcp/tree/main/src/ree_mcp/domain/value_objects): types · Typed domain concepts for IDs, ranges, units, and granularity · `src/ree_mcp/domain/value_objects`
- [Repository iface](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/repositories/indicator_repository.py): contract · Abstraction the application uses to access indicators · `src/ree_mcp/domain/repositories/indicator_repository.py`
- [Domain errors](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/domain/exceptions.py): exceptions · Shared domain-level exception types · `src/ree_mcp/domain/exceptions.py`

### Infrastructure

External API and persistence adapters

- [Settings](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/infrastructure/config/settings.py): config · Loads runtime configuration and API token · `src/ree_mcp/infrastructure/config/settings.py`
- [REE client](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/infrastructure/http/ree_api_client.py): http client · HTTP access to the external REE eSios API · `src/ree_mcp/infrastructure/http/ree_api_client.py`
- [REE repository](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/infrastructure/repositories/ree_indicator_repository.py): adapter · Implements the domain repository against REE HTTP APIs · `src/ree_mcp/infrastructure/repositories/ree_indicator_repository.py`

### Tests

Layered verification of behavior

- [Domain tests](https://github.com/esjavadex/ree-mcp/tree/main/tests/unit/domain): tests · Validates entities and value objects · `tests/unit/domain`
- [Interface tests](https://github.com/esjavadex/ree-mcp/tree/main/tests/unit/interface): tests · Validates tool config and helper behavior · `tests/unit/interface`
- [HTTP tests](https://github.com/esjavadex/ree-mcp/tree/main/tests/integration/infrastructure): tests · Checks REE API client integration boundaries · `tests/integration/infrastructure`
- [E2E server](https://github.com/esjavadex/ree-mcp/tree/main/tests/e2e): tests · Exercises the MCP server end to end · `tests/e2e`

### Runtime

Package entrypoint and local configuration

- [Module entry](https://github.com/esjavadex/ree-mcp/blob/main/src/ree_mcp/__main__.py): runtime · Package module entrypoint for local execution · `src/ree_mcp/__main__.py`
- [Env example](https://github.com/esjavadex/ree-mcp/blob/main/.env.example): config · Example environment variables for local setup · `.env.example`

## Connections

- 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
