search_indicators
Find Spanish electricity grid indicators by keyword to access demand, generation, pricing, and emissions data from Red Eléctrica de España.
Instructions
Search for indicators by keyword in their names.
Searches through all available indicators and returns those matching the keyword in their name or short name.
Args: keyword: Keyword to search for (e.g., "demanda", "precio", "solar") limit: Maximum number of results (default: 20)
Returns: JSON string with matching indicator metadata.
Examples: Find all demand-related indicators: >>> await search_indicators("demanda", limit=10)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | ||
| limit | No |
Implementation Reference
- MCP tool handler for 'search_indicators'. Registers the tool with @mcp.tool(), handles input parameters (keyword: str, limit: int|None=20), executes the SearchIndicatorsUseCase via ToolExecutor, formats results as JSON, and handles errors.@mcp.tool() async def search_indicators(keyword: str, limit: int | None = 20) -> str: """Search for indicators by keyword in their names. Searches through all available indicators and returns those matching the keyword in their name or short name. Args: keyword: Keyword to search for (e.g., "demanda", "precio", "solar") limit: Maximum number of results (default: 20) Returns: JSON string with matching indicator metadata. Examples: Find all demand-related indicators: >>> await search_indicators("demanda", limit=10) Find price indicators: >>> await search_indicators("precio") Find solar generation indicators: >>> await search_indicators("solar") """ try: async with ToolExecutor() as executor: use_case = executor.create_search_indicators_use_case() indicators = await use_case.execute(keyword=keyword, limit=limit) result = { "keyword": keyword, "count": len(indicators), "indicators": [ind.model_dump() for ind in indicators], } return ResponseFormatter.success(result, ensure_ascii=False) except Exception as e: return ResponseFormatter.unexpected_error(e, context="Error searching indicators")
- SearchIndicatorsUseCase class implementing the core search logic: initializes with IndicatorRepository, executes search via repository.search_indicators(), and transforms results to IndicatorMetadataResponse DTOs.class SearchIndicatorsUseCase: """Use case for searching indicators by keyword. Attributes: repository: Indicator repository implementation """ def __init__(self, repository: IndicatorRepository) -> None: """Initialize use case. Args: repository: Indicator repository """ self.repository = repository async def execute( self, keyword: str, limit: int | None = None ) -> list[IndicatorMetadataResponse]: """Execute the use case. Args: keyword: Keyword to search for limit: Maximum number of results Returns: List of matching indicator metadata. """ indicators = await self.repository.search_indicators(keyword=keyword, limit=limit) return [ IndicatorMetadataResponse( id=int(ind.id), name=ind.name, short_name=ind.short_name, description=ind.description, unit=ind.unit.value, frequency=ind.frequency, geo_scope=ind.geo_scope.value, ) for ind in indicators ]
- ToolExecutor.create_search_indicators_use_case() factory method that creates and returns a SearchIndicatorsUseCase instance wired with the repository.def create_search_indicators_use_case(self) -> SearchIndicatorsUseCase: """Create a SearchIndicatorsUseCase instance. Returns: Configured use case instance """ return SearchIndicatorsUseCase(self.repository)
- src/ree_mcp/interface/mcp_server.py:117-117 (registration)@mcp.tool() decorator registers the search_indicators function as an MCP tool.@mcp.tool()
- Function signature and docstring define the tool schema: parameters keyword (str), limit (int|None=20), return str (JSON), with detailed documentation and examples.async def search_indicators(keyword: str, limit: int | None = 20) -> str: """Search for indicators by keyword in their names. Searches through all available indicators and returns those matching the keyword in their name or short name. Args: keyword: Keyword to search for (e.g., "demanda", "precio", "solar") limit: Maximum number of results (default: 20) Returns: JSON string with matching indicator metadata. Examples: Find all demand-related indicators: >>> await search_indicators("demanda", limit=10) Find price indicators: >>> await search_indicators("precio") Find solar generation indicators: >>> await search_indicators("solar") """