search_series
Search for BCRP economic indicators by keyword using deterministic search with fuzzy matching to identify relevant macroeconomic data series.
Instructions
Search for BCRP economic indicators by keyword.
Uses deterministic search with fuzzy matching. Returns the best match or an ambiguity error if multiple matches are equally scored.
Args: query: Search term (e.g., "tipo de cambio", "inflacion", "PBI")
Returns: JSON string with match result containing codigo_serie and confidence, or error details if ambiguous or not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp_bcrp/server.py:92-107 (handler)The MCP tool registration for `search_series` which delegates to the `_search_series` function.
@mcp.tool() async def search_series(query: str) -> str: """ Search for BCRP economic indicators by keyword. Uses deterministic search with fuzzy matching. Returns the best match or an ambiguity error if multiple matches are equally scored. Args: query: Search term (e.g., "tipo de cambio", "inflacion", "PBI") Returns: JSON string with match result containing codigo_serie and confidence, or error details if ambiguous or not found. """ return await _search_series(query) - mcp_bcrp/server.py:21-50 (handler)The core implementation logic of the search functionality used by the `search_series` tool.
async def _search_series(query: str) -> str: """ Uses robust local metadata search. Now returns deterministic result via SearchEngine.solve(). """ try: await metadata_client.load() logger.info(f"Searching for: {query}") # First try deterministic solve result = metadata_client.solve(query) if "error" not in result: # Success - return JSON with the match return json.dumps(result, ensure_ascii=False) if result.get("error") == "ambiguedad": # Return ambiguity info for user to refine return json.dumps(result, ensure_ascii=False) # Fallback to fuzzy search for exploratory queries df = metadata_client.search(query) if df.empty: return "No series found matching that query." return df.to_json(orient='records') except Exception as e: logger.error(f"Search failed: {e}") return f"Search failed: {str(e)}"