search_time_series_by_group
Find economic time series data from Peru's Central Reserve Bank by filtering within specific categories or groups to identify relevant indicators for analysis.
Instructions
Search for time series within a specific group from the BCRP database.
This function retrieves time series metadata from the BCRP (Banco Central de Reserva del Perú) database and filters it to find all time series that belong to a specific group. It returns a list of dictionaries containing the code and name of each matching time series.
Args: time_series_group (str): The name of the time series group to search within. This should match or be contained within the "Grupo de serie" field in the BCRP metadata.
Returns: List[Dict[str, str]]: A list of dictionaries where each dictionary contains: - "code": The unique identifier code for the time series - "name": The descriptive name of the time series If an error occurs, returns a list with a single dictionary containing an "error" key with the error message.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time_series_group | Yes |
Implementation Reference
- main.py:43-70 (handler)The handler function for the 'search_time_series_by_group' tool, decorated with @mcp.tool() for registration. It fetches BCRP time series metadata, filters by the provided group name using pandas, and returns up to 50 matching time series as dictionaries with 'code' and 'name'. The type hints and docstring define the input schema and output format.@mcp.tool() def search_time_series_by_group(time_series_group: str) -> Any: """ Search for time series within a specific group from the BCRP database. This function retrieves time series metadata from the BCRP (Banco Central de Reserva del Perú) database and filters it to find all time series that belong to a specific group. It returns a list of dictionaries containing the code and name of each matching time series. Args: time_series_group (str): The name of the time series group to search within. This should match or be contained within the "Grupo de serie" field in the BCRP metadata. Returns: List[Dict[str, str]]: A list of dictionaries where each dictionary contains: - "code": The unique identifier code for the time series - "name": The descriptive name of the time series If an error occurs, returns a list with a single dictionary containing an "error" key with the error message. """ try: metadata = pd.read_csv(METADATA_ENDPOINT, delimiter=';', encoding='latin-1') result_list = metadata[metadata[TIME_SERIES_GROUP].str.contains(time_series_group, na=False)].iloc[:, [0, 3]].values.tolist() return [{"code": row[0], "name": row[1]} for row in result_list[:50]] except Exception as e: return [{"error": str(e)}]