Skip to main content
Glama
ESJavadex

REE MCP Server

by ESJavadex

get_carbon_intensity

Calculate CO2 emissions per unit of electricity generated from Spain's grid data. Retrieve carbon intensity time series for specified periods to analyze energy mix cleanliness.

Instructions

Get carbon intensity over time (gCO2/kWh).

Calculates CO2 emissions per unit of electricity generated. Lower values indicate cleaner energy mix.

Args: start_date: Start datetime in ISO format (YYYY-MM-DDTHH:MM) end_date: End datetime in ISO format (YYYY-MM-DDTHH:MM) time_granularity: Time aggregation (raw, hour, day, fifteen_minutes)

Returns: JSON string with carbon intensity time series and statistics.

Examples: Get hourly carbon intensity for a day: >>> await get_carbon_intensity("2025-10-08T00:00", "2025-10-08T23:59", "hour")

Get daily carbon intensity for a week:
>>> await get_carbon_intensity("2025-10-01T00:00", "2025-10-07T23:59", "day")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYes
end_dateYes
time_granularityNohour

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler implementing get_carbon_intensity tool. Fetches CO2 emissions and generation data using specific REE indicators, calculates gCO2/kWh intensity, computes statistics (min/max/avg), and returns formatted JSON response with interpretation guidelines.
    @mcp.tool()
    async def get_carbon_intensity(
        start_date: str, end_date: str, time_granularity: str = "hour"
    ) -> str:
        """Get carbon intensity over time (gCO2/kWh).
    
        Calculates CO2 emissions per unit of electricity generated. Lower values
        indicate cleaner energy mix.
    
        Args:
            start_date: Start datetime in ISO format (YYYY-MM-DDTHH:MM)
            end_date: End datetime in ISO format (YYYY-MM-DDTHH:MM)
            time_granularity: Time aggregation (raw, hour, day, fifteen_minutes)
    
        Returns:
            JSON string with carbon intensity time series and statistics.
    
        Examples:
            Get hourly carbon intensity for a day:
            >>> await get_carbon_intensity("2025-10-08T00:00", "2025-10-08T23:59", "hour")
    
            Get daily carbon intensity for a week:
            >>> await get_carbon_intensity("2025-10-01T00:00", "2025-10-07T23:59", "day")
        """
        try:
            async with ToolExecutor() as executor:
                use_case = executor.create_get_indicator_data_use_case()
    
                # Get CO2 emissions
                co2_request = GetIndicatorDataRequest(
                    indicator_id=IndicatorIDs.CO2_EMISSIONS.id,
                    start_date=start_date,
                    end_date=end_date,
                    time_granularity=time_granularity,
                )
                co2_response = await use_case.execute(co2_request)
                co2_data = co2_response.model_dump()
    
                # Get generation/demand
                demand_request = GetIndicatorDataRequest(
                    indicator_id=IndicatorIDs.REAL_DEMAND_SUM_GENERATION.id,
                    start_date=start_date,
                    end_date=end_date,
                    time_granularity=time_granularity,
                )
                demand_response = await use_case.execute(demand_request)
                demand_data = demand_response.model_dump()
    
            # Calculate carbon intensity (gCO2/kWh)
            co2_values = co2_data.get("values", [])
            demand_values = demand_data.get("values", [])
    
            intensity_values = []
            for co2_val, demand_val in zip(co2_values, demand_values, strict=False):
                if demand_val["value"] > 0:
                    # Convert tCO2 to gCO2, MW to MWh (for hourly data they're equivalent)
                    intensity_g_per_kwh = (co2_val["value"] * 1_000_000) / (demand_val["value"] * 1_000)
                    intensity_values.append(
                        {
                            "datetime": co2_val["datetime"],
                            "carbon_intensity_g_per_kwh": round(intensity_g_per_kwh, 2),
                            "co2_tonnes": co2_val["value"],
                            "generation_mw": demand_val["value"],
                        }
                    )
    
            # Calculate statistics
            stats = {}
            if intensity_values:
                intensities = [v["carbon_intensity_g_per_kwh"] for v in intensity_values]
                stats = {
                    "min_g_per_kwh": min(intensities),
                    "max_g_per_kwh": max(intensities),
                    "avg_g_per_kwh": round(sum(intensities) / len(intensities), 2),
                    "count": len(intensities),
                }
    
            result = {
                "period": {"start": start_date, "end": end_date, "granularity": time_granularity},
                "values": intensity_values,
                "statistics": stats,
                "interpretation": {
                    "excellent": "< 50 g/kWh",
                    "good": "50-150 g/kWh",
                    "moderate": "150-300 g/kWh",
                    "poor": "> 300 g/kWh",
                },
            }
    
            return ResponseFormatter.success(result)
    
        except Exception as e:
            return ResponseFormatter.unexpected_error(e, context="Error calculating carbon intensity")
  • Defines the CO2_EMISSIONS indicator ID (10355) used as data source for carbon calculations in get_carbon_intensity.
    CO2_EMISSIONS = IndicatorMetadata(
        id=10355,
        name="CO₂ Emissions",
        category=IndicatorCategory.EMISSION,
        description="CO₂ emissions associated with real-time generation (tCO₂eq)",
    )
  • Defines the REAL_DEMAND_SUM_GENERATION indicator ID (10004) used as denominator (generation proxy) for carbon intensity calculation.
    REAL_DEMAND_SUM_GENERATION = IndicatorMetadata(
        id=10004,
        name="Real Demand Sum of Generation",
        category=IndicatorCategory.DEMAND,
        description="Real demand calculated from generation sum",
    )
  • FastMCP server initialization where all @mcp.tool() decorators register the get_carbon_intensity tool.
    # Initialize MCP server
    mcp = FastMCP("REE MCP Server", dependencies=["httpx", "pydantic", "pydantic-settings"])
  • Docstring providing input/output schema description, parameters, return type, and usage examples for MCP tool schema generation.
    """Get carbon intensity over time (gCO2/kWh).
    
    Calculates CO2 emissions per unit of electricity generated. Lower values
    indicate cleaner energy mix.
    
    Args:
        start_date: Start datetime in ISO format (YYYY-MM-DDTHH:MM)
        end_date: End datetime in ISO format (YYYY-MM-DDTHH:MM)
        time_granularity: Time aggregation (raw, hour, day, fifteen_minutes)
    
    Returns:
        JSON string with carbon intensity time series and statistics.
    
    Examples:
        Get hourly carbon intensity for a day:
        >>> await get_carbon_intensity("2025-10-08T00:00", "2025-10-08T23:59", "hour")
    
        Get daily carbon intensity for a week:
        >>> await get_carbon_intensity("2025-10-01T00:00", "2025-10-07T23:59", "day")
    """
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that the tool calculates CO2 emissions per unit of electricity and explains what lower values indicate, which adds useful context. However, it doesn't mention rate limits, authentication requirements, data freshness, geographic scope, or error conditions that would be important for a data retrieval tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and efficiently organized. It starts with the core purpose, adds explanatory context about what the values mean, then provides clear parameter documentation with examples. Every sentence adds value, and the information is front-loaded with the most important details first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there's an output schema (though not shown), the description doesn't need to explain return values in detail. It mentions the return format (JSON string with time series and statistics) which is appropriate. For a 3-parameter data retrieval tool with no annotations, the description provides good coverage of parameters and purpose, though could benefit from more behavioral context about limitations or constraints.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by providing detailed parameter documentation. It explains all three parameters (start_date, end_date, time_granularity), specifies their formats (ISO format), lists enumeration values for time_granularity, and provides concrete examples showing how to use them.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('Get') and resource ('carbon intensity over time'), including the measurement unit (gCO2/kWh). It distinguishes this tool from siblings by focusing specifically on carbon intensity calculations rather than demand, pricing, generation mix, or other grid metrics mentioned in the sibling list.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While it distinguishes from siblings by topic, it doesn't mention when to choose carbon intensity data over other related tools like get_generation_mix or get_renewable_summary, nor does it specify prerequisites or appropriate contexts for use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ESJavadex/ree-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server