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
| Name | Required | Description | Default |
|---|---|---|---|
| series_codes | Yes | ||
| names | No | ||
| period | No |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp_bcrp/server.py:124-166 (handler)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)}"