Skip to main content
Glama

get_table

Retrieve formatted economic data tables from Peru's central bank by specifying series codes, custom column names, and date ranges.

Instructions

Get a formatted table with custom column names.

Args: series_codes: List of BCRP series codes to retrieve names: Optional custom names for columns (must match series_codes length) period: Date range in format 'YYYY-MM/YYYY-MM' or 'YYYY'

Returns: JSON string with formatted table data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
series_codesYes
namesNo
periodNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `get_table` tool handler function retrieves data for BCRP series, formats it into a table with optional custom names using pandas, and returns the result as a JSON string.
    @mcp.tool()
    async def get_table(
        series_codes: list[str], 
        names: list[str] = None, 
        period: str = None
    ) -> str:
        """
        Get a formatted table with custom column names.
        
        Args:
            series_codes: List of BCRP series codes to retrieve
            names: Optional custom names for columns (must match series_codes length)
            period: Date range in format 'YYYY-MM/YYYY-MM' or 'YYYY'
        
        Returns:
            JSON string with formatted table data.
        """
        try:
            # 1. Fetch Data
            data_json = await _get_data(series_codes, period)
            if data_json.startswith("Error") or data_json.startswith("No data"):
                return data_json
                
            import pandas as pd
            df = pd.read_json(data_json, orient='records')
            if df.empty:
                return "No data found."
                
            # 2. Resolve Names if not provided
            if not names:
                await metadata_client.load()
                names = metadata_client.get_series_names(series_codes)
                
            # 3. Rename columns
            mapping = {code: name for code, name in zip(series_codes, names)}
            df.rename(columns=mapping, inplace=True)
                
            return df.to_json(orient='records', date_format='iso', indent=2)
            
    
        except Exception as e:
            return f"Table generation failed: {str(e)}"
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/MaykolMedrano/mcp_bcrp'

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