Skip to main content
Glama

plot_chart

Generate professional charts from BCRP economic data series. Plot multiple indicators with custom date ranges, titles, and legends, saving results as PNG files for analysis.

Instructions

Generate a professional chart for BCRP series data. Returns the path to the saved PNG file.

Args: series_codes: List of BCRP series codes to plot period: Date range in format 'YYYY-MM/YYYY-MM' (optional) title: Custom chart title (optional, uses series name if not provided) names: Custom names for each series in legend (optional) output_path: Custom output path for the chart (optional)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
series_codesYes
periodNo
titleNo
namesNo
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `plot_chart` tool is defined here with an `@mcp.tool()` decorator and contains the logic for fetching data, parsing Spanish-formatted dates, and generating a plot using Matplotlib.
    @mcp.tool()
    async def plot_chart(
        series_codes: list[str], 
        period: str = None, 
        title: str = None,
        names: list[str] = None,
        output_path: str = None
    ) -> str:
        """
        Generate a professional chart for BCRP series data.
        Returns the path to the saved PNG file.
        
        Args:
            series_codes: List of BCRP series codes to plot
            period: Date range in format 'YYYY-MM/YYYY-MM' (optional)
            title: Custom chart title (optional, uses series name if not provided)
            names: Custom names for each series in legend (optional)
            output_path: Custom output path for the chart (optional)
        """
        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 to plot."
            
            # 2. Setup plot style
            import matplotlib
            matplotlib.use('Agg')
            import matplotlib.pyplot as plt
            import matplotlib.dates as mdates
            
            plt.style.use('seaborn-v0_8-whitegrid')
            fig, ax = plt.subplots(figsize=(12, 6), dpi=120)
            
            # 3. Parse time column (BCRP uses Spanish month abbreviations)
            if 'time' in df.columns:
                # Spanish month mapping
                spanish_months = {
                    'Ene': 'Jan', 'Feb': 'Feb', 'Mar': 'Mar', 'Abr': 'Apr',
                    'May': 'May', 'Jun': 'Jun', 'Jul': 'Jul', 'Ago': 'Aug',
                    'Sep': 'Sep', 'Oct': 'Oct', 'Nov': 'Nov', 'Dic': 'Dec'
                }
                
                def parse_spanish_date(date_str):
                    """Convert BCRP Spanish date format to datetime."""
                    try:
                        for es, en in spanish_months.items():
                            date_str = date_str.replace(es, en)
                        return pd.to_datetime(date_str, format='%b.%Y')
                    except Exception:
                        return pd.to_datetime(date_str)
                
                df['time'] = df['time'].apply(parse_spanish_date)
                df = df.set_index('time')
            
            # 4. Resolve Names if not provided
            if not names:
                await metadata_client.load()
                names = metadata_client.get_series_names(series_codes)
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It successfully communicates the side effect (saves a PNG file to disk) and return value (file path), but fails to mention other critical behavioral aspects like whether it overwrites existing files, required directory permissions, or error handling when series codes are invalid.

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

Conciseness4/5

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

The structure is well-organized with purpose front-loaded, followed by return value and parameter details. The 'Args:' format is readable and efficient. Minor deduction for the vague adjective 'professional' which doesn't add technical clarity, and the description could slightly condense the optional parameter notes.

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?

For a tool with 5 parameters and file output, the description is nearly complete. It documents all parameters and discloses the PNG output behavior even though an output schema exists (which relieves some descriptive burden). Minor gap: it doesn't specify the chart type (line, bar, etc.) or default file naming behavior when output_path is omitted.

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

Parameters5/5

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

Given 0% schema description coverage, the description excellently compensates by documenting all 5 parameters in the Args section with clear semantics, data types (List, string), and specific format guidance (e.g., 'YYYY-MM/YYYY-MM' for the period parameter). This provides essential value beyond the bare schema.

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 tool 'Generate[s] a professional chart for BCRP series data,' providing a specific verb, resource type, and domain context. It implicitly distinguishes itself from siblings like get_data and get_table by focusing on visualization rather than raw data retrieval, though it could explicitly mention 'visualization' or 'PNG image' in the primary sentence.

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 explicit guidance on when to select this tool versus alternatives like get_data or get_table. While mentioning 'Returns the path to the saved PNG file' hints at the output format difference, there is no 'when-to-use' or 'when-not-to-use' guidance, nor any mention of prerequisites like valid BCRP series codes.

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/MaykolMedrano/mcp_bcrp'

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