Skip to main content
Glama
cfocoder

Banxico MCP Server

get_udis_data

Retrieve current and historical UDIS (Investment Units) data from Mexico's central bank. Specify a limit to control the number of recent data points returned.

Instructions

Get UDIS (Investment Units) data from Banxico.

Args: limit: Maximum number of recent data points (default: 30)

Returns: Current and historical UDIS values

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The get_udis_data tool handler, registered via @mcp.tool() decorator. Fetches UDIS data from Banxico SIE API endpoint 'series/SP68257/datos', applies optional limit to recent data points, and formats the response using format_exchange_rate_data.
    @mcp.tool()
    async def get_udis_data(limit: Optional[int] = 30) -> str:
        """
        Get UDIS (Investment Units) data from Banxico.
        
        Args:
            limit: Maximum number of recent data points (default: 30)
            
        Returns:
            Current and historical UDIS values
        """
        if not BANXICO_TOKEN:
            return "Error: BANXICO_API_TOKEN environment variable not set. Please configure your API token."
        
        endpoint = "series/SP68257/datos"
        data = await make_banxico_request(endpoint, BANXICO_TOKEN)
        
        if not data:
            return "Failed to retrieve UDIS 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_exchange_rate_data(data)
  • Registration of the get_udis_data tool using FastMCP's @mcp.tool() decorator, which also derives schema from function signature and docstring.
    @mcp.tool()
  • Helper function used by get_udis_data to make authenticated HTTP requests to Banxico 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
  • Helper function used by get_udis_data to format the API response data into a readable string representation.
    def format_exchange_rate_data(data: dict[str, Any]) -> str:
        """
        Format exchange rate data into a readable string.
        
        Args:
            data: Raw JSON response from Banxico API
            
        Returns:
            Formatted string with exchange rate information
        """
        if not data or "bmx" not in data:
            return "No data available"
        
        series_list = data["bmx"].get("series", [])
        if not series_list:
            return "No series data found"
        
        result = []
        for series in series_list:
            series_title = series.get("titulo", "Unknown Series")
            series_id = series.get("idSerie", "Unknown ID")
            result.append(f"Series: {series_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 first few and last few data points
                if len(datos) <= 10:
                    for dato in datos:
                        fecha = dato.get("fecha", "Unknown date")
                        valor = dato.get("dato", "N/A")
                        result.append(f"  {fecha}: {valor}")
                else:
                    # Show first 5
                    for i, dato in enumerate(datos[:5]):
                        fecha = dato.get("fecha", "Unknown date")
                        valor = dato.get("dato", "N/A")
                        result.append(f"  {fecha}: {valor}")
                    
                    result.append(f"  ... ({len(datos) - 10} more data points) ...")
                    
                    # Show last 5
                    for dato in datos[-5:]:
                        fecha = dato.get("fecha", "Unknown date")
                        valor = dato.get("dato", "N/A")
                        result.append(f"  {fecha}: {valor}")
            
            result.append("")  # Empty line between series
        
        return "\n".join(result)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'Current and historical UDIS values' but lacks details on behavioral traits such as data freshness, rate limits, authentication needs, error handling, or whether it's a read-only operation. This is a significant gap for a data-fetching tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core purpose, followed by clear 'Args' and 'Returns' sections. Every sentence earns its place by providing essential information without redundancy, making it efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter, no nested objects) and the presence of an output schema (which handles return values), the description is reasonably complete. It covers purpose, parameter semantics, and return scope, though it lacks behavioral context and usage guidelines, which are minor gaps in this context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics for the 'limit' parameter, explaining it as 'Maximum number of recent data points (default: 30)', which clarifies its purpose beyond the schema's basic type and default. With 0% schema description coverage and 1 parameter, this compensates well, though it doesn't detail data recency or ordering.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('UDIS (Investment Units) data from Banxico'), making the purpose specific and understandable. It distinguishes from some siblings by focusing on UDIS data rather than reserves, exchange rates, or other economic indicators, though it doesn't explicitly differentiate from all similar data-fetching tools like 'get_date_range_data'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'get_date_range_data' and 'get_historical_data' tools, it's unclear if this tool is for UDIS-specific data, if it has date range limitations, or if other tools might overlap. No explicit when/when-not or alternative usage is mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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