Skip to main content
Glama
cfocoder

Banxico MCP Server

get_inflation_data

Retrieve inflation data from Banxico by specifying the type (monthly, accumulated, annual) and the number of recent data points. Returns formatted percentages for analysis and decision-making.

Instructions

Get inflation data from Banxico.

Args: inflation_type: Type of inflation data ('monthly', 'accumulated', 'annual') limit: Maximum number of recent data points (default: 12)

Returns: Formatted inflation data with percentages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inflation_typeNomonthly
limitNo

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements get_inflation_data. It maps inflation types to Banxico series IDs, fetches data via API, applies optional limit to recent data points, and returns formatted output using helper function.
    @mcp.tool() async def get_inflation_data(inflation_type: str = "monthly", limit: Optional[int] = 12) -> str: """ Get inflation data from Banxico. Args: inflation_type: Type of inflation data ('monthly', 'accumulated', 'annual') limit: Maximum number of recent data points (default: 12) Returns: Formatted inflation data with percentages """ if not BANXICO_TOKEN: return "Error: BANXICO_API_TOKEN environment variable not set. Please configure your API token." # Map inflation types to series IDs series_map = { "monthly": "SP30577", # Monthly Inflation "accumulated": "SP30579", # Accumulated Inflation "annual": "SP30578" # Annual Inflation } if inflation_type not in series_map: return f"Invalid inflation type: {inflation_type}. Available types: {list(series_map.keys())}" series_id = series_map[inflation_type] endpoint = f"series/{series_id}/datos" data = await make_banxico_request(endpoint, BANXICO_TOKEN) if not data: return f"Failed to retrieve {inflation_type} inflation 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_inflation_data(data)
  • Helper function specifically for formatting inflation data output, adding percentage symbols, emojis, and displaying recent data points.
    def format_inflation_data(data: dict[str, Any]) -> str: """ Format inflation data with percentage symbols and better labeling. Args: data: Raw JSON response from Banxico API Returns: Formatted string with inflation data including percentage symbols """ if not data or "bmx" not in data: return "No inflation data available" series_list = data["bmx"].get("series", []) if not series_list: return "No inflation 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 inflation 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)
  • Input schema defined by function parameters and docstring: inflation_type (str, default 'monthly'), limit (Optional[int], default 12), returns str.
    async def get_inflation_data(inflation_type: str = "monthly", limit: Optional[int] = 12) -> str: """ Get inflation data from Banxico. Args: inflation_type: Type of inflation data ('monthly', 'accumulated', 'annual') limit: Maximum number of recent data points (default: 12) Returns: Formatted inflation data with percentages
  • The @mcp.tool() decorator registers the get_inflation_data function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cfocoder/banxico_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server