get_series_metadata
Retrieve detailed metadata for Banxico economic data series, including title, description, and date range, using the specified series ID. Designed for precise access to financial indicators and exchange rate information.
Instructions
Get metadata for a Banxico series.
Args: series_id: The series ID to get metadata for (default: SF63528 for USD/MXN)
Returns: Series metadata including title, description, and date range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| series_id | No | SF63528 |
Implementation Reference
- banxico_mcp_server.py:372-414 (handler)The main handler function for the get_series_metadata MCP tool. It fetches metadata for a specified Banxico time series ID from the SIE API, handles errors, and formats the response as a readable string. Registered via @mcp.tool() decorator.@mcp.tool() async def get_series_metadata(series_id: str = "SF63528") -> str: """ Get metadata for a Banxico series. Args: series_id: The series ID to get metadata for (default: SF63528 for USD/MXN) Returns: Series metadata including title, description, and date range """ if not BANXICO_TOKEN: return "Error: BANXICO_API_TOKEN environment variable not set. Please configure your API token." endpoint = f"series/{series_id}" data = await make_banxico_request(endpoint, BANXICO_TOKEN) if not data: return f"Failed to retrieve metadata for series {series_id}. Please check your API token and network connection." if "bmx" not in data or "series" not in data["bmx"]: return "No series metadata found" result = [] for series in data["bmx"]["series"]: title = series.get("titulo", "Unknown title") series_id = series.get("idSerie", "Unknown ID") fecha_inicio = series.get("fechaInicio", "Unknown") fecha_fin = series.get("fechaFin", "Unknown") periodicidad = series.get("periodicidad", "Unknown") cifra = series.get("cifra", "Unknown") unidad = series.get("unidad", "Unknown") result.append(f"Series ID: {series_id}") result.append(f"Title: {title}") result.append(f"Start Date: {fecha_inicio}") result.append(f"End Date: {fecha_fin}") result.append(f"Frequency: {periodicidad}") result.append(f"Type: {cifra}") result.append(f"Unit: {unidad}") result.append("") return "\n".join(result)
- banxico_mcp_server.py:43-69 (helper)Shared helper function used by get_series_metadata (and other tools) to make authenticated HTTP requests to the Banxico SIE API, with error handling and JSON parsing.async def make_banxico_request(endpoint: str, token: str) -> dict[str, Any] | None: """ Make a request to the Banxico SIE API with proper error handling. Args: endpoint: The API endpoint to call (without base URL) token: The Banxico API token Returns: JSON response data or None if request failed """ url = f"{BANXICO_API_BASE}/{endpoint}" headers = {"User-Agent": USER_AGENT} params = {"token": token} try: async with httpx.AsyncClient() as client: response = await client.get(url, headers=headers, params=params, timeout=30.0) response.raise_for_status() return response.json() except httpx.HTTPError as e: logger.error(f"HTTP error occurred: {e}") return None except Exception as e: logger.error(f"An error occurred: {e}") return None