search_time_series_groups
Search BCRP's economic and financial time series database using keywords to identify relevant time series groups for analysis. Returns unique group names matching the search criteria.
Instructions
Search for time series groups using one or multiple keywords.
This function searches the BCRP (Banco Central de Reserva del Perú) database for time series groups that match the provided keywords. It returns a list of unique time series group names that contain or relate to the search terms.
Args: keywords (List[str]): A list containing one or more keywords to search for. Each keyword should be a single word without spaces.
Returns: List[str]: A list of unique time series group names that match the search criteria. Returns an empty list if no matches are found.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keywords | Yes |
Implementation Reference
- main.py:17-42 (handler)The handler function for the 'search_time_series_groups' tool. It is decorated with @mcp.tool() for registration. Searches BCRP time series metadata CSV for groups matching the provided keywords using fuzzy matching (difflib.get_close_matches). Returns list of unique matching group names or error message.@mcp.tool() def search_time_series_groups(keywords: List[str]) -> List[str]: """ Search for time series groups using one or multiple keywords. This function searches the BCRP (Banco Central de Reserva del Perú) database for time series groups that match the provided keywords. It returns a list of unique time series group names that contain or relate to the search terms. Args: keywords (List[str]): A list containing one or more keywords to search for. Each keyword should be a single word without spaces. Returns: List[str]: A list of unique time series group names that match the search criteria. Returns an empty list if no matches are found. """ try: df = pd.read_csv(METADATA_ENDPOINT, delimiter=';', encoding='latin-1') # index 3 is the column index for the time series group # search based on wordsearch from bcrpy matches = df[df.iloc[:, 3].apply(lambda x: any(get_close_matches(k, str(x).split(), n=1, cutoff=CUTOFF) for k in keywords))] return list(set(matches[TIME_SERIES_GROUP])) except Exception as e: return [f"error: {e}"]