get_cetes_28_data
Retrieve current and historical 28-day CETES interest rate data from Banxico. Specify a limit to control the number of recent data points returned for analysis or decision-making.
Instructions
Get CETES 28-day interest rate data from Banxico.
Args: limit: Maximum number of recent data points (default: 30)
Returns: Current and historical CETES 28-day rates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No |
Implementation Reference
- banxico_mcp_server.py:512-538 (handler)The handler function decorated with @mcp.tool() registers and implements the get_cetes_28_data tool. It fetches CETES 28-day interest rate data (series SF282) from the Banxico API, applies an optional limit to recent data points, and formats the output.@mcp.tool() async def get_cetes_28_data(limit: Optional[int] = 30) -> str: """ Get CETES 28-day interest rate data from Banxico. Args: limit: Maximum number of recent data points (default: 30) Returns: Current and historical CETES 28-day rates """ if not BANXICO_TOKEN: return "Error: BANXICO_API_TOKEN environment variable not set. Please configure your API token." endpoint = "series/SF282/datos" data = await make_banxico_request(endpoint, BANXICO_TOKEN) if not data: return "Failed to retrieve CETES 28-day data. Please check your API token and network connection." # Apply limit if specified if limit and data.get("bmx", {}).get("series"): for series in data["bmx"]["series"]: if "datos" in series and len(series["datos"]) > limit: series["datos"] = series["datos"][-limit:] return format_interest_rate_data(data)
- banxico_mcp_server.py:43-69 (helper)Helper function used by get_cetes_28_data to make authenticated HTTP requests to the Banxico SIE API.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
- banxico_mcp_server.py:172-216 (helper)Helper function used by get_cetes_28_data to format the interest rate data with percentage symbols and recent data points display.def format_interest_rate_data(data: dict[str, Any]) -> str: """ Format interest rate data with percentage symbols and rate-specific formatting. Args: data: Raw JSON response from Banxico API Returns: Formatted string with interest rate data """ if not data or "bmx" not in data: return "No interest rate data available" series_list = data["bmx"].get("series", []) if not series_list: return "No interest rate series found" result = [] for series in series_list: title = series.get("titulo", "Unknown Series") series_id = series.get("idSerie", "Unknown ID") result.append(f"📈 {title} (ID: {series_id})") datos = series.get("datos", []) if not datos: result.append(" No data points available") else: result.append(f" Total data points: {len(datos)}") # Show recent data points with percentage formatting display_count = min(len(datos), 10) for dato in datos[-display_count:]: fecha = dato.get("fecha", "Unknown date") valor = dato.get("dato", "N/A") # Add percentage symbol for interest rate data if valor != "N/A" and valor is not None: try: valor_num = float(valor) valor = f"{valor_num}%" except (ValueError, TypeError): pass result.append(f" {fecha}: {valor}") result.append("") # Empty line between series return "\n".join(result)