Skip to main content
Glama
cfocoder

Banxico MCP Server

get_series_metadata

Retrieve metadata for Bank of Mexico economic data series including title, description, and date range to understand data structure and availability.

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
NameRequiredDescriptionDefault
series_idNoSF63528

Implementation Reference

  • The handler function for the get_series_metadata tool. Decorated with @mcp.tool() which registers it as an MCP tool. Fetches and formats metadata for the specified Banxico economic series.
    @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)
  • Helper function used by get_series_metadata 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
  • The @mcp.tool() decorator registers the get_series_metadata 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