get_generation_mix
Retrieve electricity generation breakdown by source (nuclear, wind, solar, etc.) for a specific date and hour from Spain's grid operator data.
Instructions
Get the electricity generation mix at a specific time.
Returns the power generation breakdown by source (nuclear, wind, solar, etc.) for a specific hour.
Args: date: Date in YYYY-MM-DD format hour: Hour in HH format (00-23, default: 12)
Returns: JSON string with generation mix by source.
Examples: Get generation mix at noon on Oct 8: >>> await get_generation_mix("2025-10-08", "12")
Get overnight generation mix:
>>> await get_generation_mix("2025-10-08", "02")
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | ||
| hour | No | 12 |
Implementation Reference
- MCP tool handler and registration for 'get_generation_mix'. This @mcp.tool()-decorated function implements the tool logic: builds datetime range, creates services, fetches and formats generation mix data.@mcp.tool() async def get_generation_mix(date: str, hour: str = "12") -> str: """Get the electricity generation mix at a specific time. Returns the power generation breakdown by source (nuclear, wind, solar, etc.) for a specific hour. Args: date: Date in YYYY-MM-DD format hour: Hour in HH format (00-23, default: 12) Returns: JSON string with generation mix by source. Examples: Get generation mix at noon on Oct 8: >>> await get_generation_mix("2025-10-08", "12") Get overnight generation mix: >>> await get_generation_mix("2025-10-08", "02") """ try: start_datetime, end_datetime = DateTimeHelper.build_datetime_range(date, hour) async with ToolExecutor() as executor: use_case = executor.create_get_indicator_data_use_case() data_fetcher = DataFetcher(use_case) service = GenerationMixService(data_fetcher) result = await service.get_generation_mix(start_datetime, end_datetime) return ResponseFormatter.success(result) except Exception as e: return ResponseFormatter.unexpected_error(e, context="Error getting generation mix")
- Core helper method in GenerationMixService that fetches generation data from multiple REE indicators using predefined sources and aggregates into a mix dictionary.async def get_generation_mix(self, start_date: str, end_date: str) -> dict[str, Any]: """Get generation mix for a specific time. Args: start_date: Start datetime in ISO format end_date: End datetime in ISO format Returns: Generation mix data with sources and values """ sources = IndicatorIDs.get_generation_mix_sources() raw_data = await self.data_fetcher.fetch_multiple_indicators( sources, start_date, end_date, "hour" ) generation_mix: dict[str, Any] = { "datetime": start_date, "sources": {}, } for source_name, response_data in raw_data.items(): if "error" in response_data: generation_mix["sources"][source_name] = response_data else: values = response_data.get("values", []) if values: generation_mix["sources"][source_name] = { "value_mw": values[0]["value"], "unit": response_data["indicator"]["unit"], } else: generation_mix["sources"][source_name] = {"error": "No data available"} return generation_mix
- Helper method providing the exact REE indicator IDs and metadata used for fetching generation mix sources (nuclear, wind, solar, hydro, etc.). Called by GenerationMixService.def get_generation_mix_sources(cls) -> dict[str, IndicatorMetadata]: """Get indicators for generation mix analysis. Returns: Dictionary mapping source names to indicator metadata. """ return { "nuclear": cls.NUCLEAR, "wind_national": cls.WIND_NATIONAL, "solar_pv_peninsular": cls.SOLAR_PV_PENINSULAR, "solar_thermal_peninsular": cls.SOLAR_THERMAL_PENINSULAR, "hydro_national": cls.HYDRO_NATIONAL, "combined_cycle_national": cls.COMBINED_CYCLE_NATIONAL, }
- Input/output schema and documentation for the get_generation_mix tool, defining parameters (date, hour) and expected JSON response format."""Get the electricity generation mix at a specific time. Returns the power generation breakdown by source (nuclear, wind, solar, etc.) for a specific hour. Args: date: Date in YYYY-MM-DD format hour: Hour in HH format (00-23, default: 12) Returns: JSON string with generation mix by source. Examples: Get generation mix at noon on Oct 8: >>> await get_generation_mix("2025-10-08", "12") Get overnight generation mix: >>> await get_generation_mix("2025-10-08", "02") """