Skip to main content
Glama

get_data

Fetch time series data for specific economic indicators from the Banco Central de Reserva del Perú database using series codes and date ranges.

Instructions

Fetch time series data for specific BCRP series codes.

Args: series_codes: List of BCRP series codes (e.g., ["PN01652XM", "PD04638PD"]) period: Date range in format 'YYYY-MM/YYYY-MM' or single 'YYYY-MM'. If None, returns all available data.

Returns: JSON string with array of records containing 'time' and values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
series_codesYes
periodNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The _get_data function is the internal helper function that performs the actual data fetching logic from the BCRP client.
    async def _get_data(series_codes: list[str], period: str = None) -> str:
        try:
            logger.info(f"Fetching data for: {series_codes} range: {period}")
            
            # Parse period if needed, but client handles basic string appending
            # We might need to handle the specific format "start_date/end_date" if provided as one string
            start = None
            end = None
            start = None
            end = None
            if period:
                parts = period.split('/')
                if len(parts) == 2:
                    start, end = parts
                elif len(parts) == 1:
                     # Check if it looks like a year "YYYY"
                     if len(period) == 4 and period.isdigit():
                         start = f"{period}-01"
                         end = f"{period}-12"
                     else:
                         start = period # fallback
                         # If only start is provided, client won't append it currently.
                         # We should probably set end to 'now' or similar if start is provided?
                         # Or rely on client update. But client needs start AND end.
                         # If only start provided, let's duplicate it? or leave end=None?
                         # If I set end=start, it fetches one month.
                         pass
            
            df = await bcrp_client.get_series(series_codes, start_date=start, end_date=end)
            
            if df.empty:
                return "No data found for the specified parameters."
                
            return df.to_json(orient='records', date_format='iso')
        except Exception as e:
            logger.error(f"Fetch failed: {e}")
            return f"Error fetching data: {str(e)}"
  • The get_data tool definition which is registered with FastMCP and calls the internal _get_data function.
    @mcp.tool()
    async def get_data(series_codes: list[str], period: str = None) -> str:
        """
        Fetch time series data for specific BCRP series codes.
        
        Args:
            series_codes: List of BCRP series codes (e.g., ["PN01652XM", "PD04638PD"])
            period: Date range in format 'YYYY-MM/YYYY-MM' or single 'YYYY-MM'.
                    If None, returns all available data.
        
        Returns:
            JSON string with array of records containing 'time' and values.
        """
        return await _get_data(series_codes, period)
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