plot_series
Retrieve Consumer Price Index (CPI) time series data formatted for chart creation, enabling visualization of inflation trends from Bureau of Labor Statistics datasets.
Instructions
Get CPI All Items (CUUR0000SA0) data formatted for plotting. Returns time series data with dates and values that can be used to create charts on the client side. No parameters needed.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/bls_mcp/tools/plot_series.py:42-111 (handler)The `execute` method in `PlotSeriesTool` class implements the core handler logic: fetches hardcoded CPI series CUUR0000SA0 data, formats it for client-side plotting with dates and values, computes statistics, and returns structured JSON including plot instructions.async def execute(self, arguments: Dict[str, Any]) -> Dict[str, Any]: """Execute the plot series tool - returns data for CUUR0000SA0.""" logger.info("Executing plot_series for CUUR0000SA0") # Hardcoded series series_id = "CUUR0000SA0" # Fetch ALL available data for this series try: series_data = await self.data_provider.get_series(series_id) except Exception as e: logger.error(f"Failed to fetch series: {e}") return {"status": "error", "error": str(e)} # Extract data points data_points = series_data.get("data", []) if not data_points: return {"status": "error", "error": "No data available"} # Sort data chronologically and format for plotting plot_data = [] for point in data_points: year = point["year"] month = point["period"].replace("M", "").zfill(2) date_str = f"{year}-{month}" value = float(point["value"]) plot_data.append({ "date": date_str, "value": value, "year": year, "month": month, "period": point["period"] }) # Sort oldest to newest plot_data.sort(key=lambda x: x["date"]) # Calculate statistics values = [d["value"] for d in plot_data] min_value = min(values) max_value = max(values) avg_value = sum(values) / len(values) # Get metadata metadata = series_data.get("metadata", {}) return { "status": "success", "series_id": series_id, "series_title": metadata.get("series_title", "CPI All Urban Consumers: All Items"), "data": plot_data, "statistics": { "count": len(plot_data), "min": round(min_value, 3), "max": round(max_value, 3), "average": round(avg_value, 3), }, "date_range": { "start": plot_data[0]["date"], "end": plot_data[-1]["date"] }, "plot_instructions": { "chart_type": "line", "x_axis": "date", "y_axis": "value", "title": metadata.get("series_title", "CPI All Urban Consumers: All Items"), "y_label": "Index Value", "x_label": "Date" } }
- Pydantic `BaseModel` defining the input schema for the `plot_series` tool. It is empty since no input parameters are required.class PlotSeriesInput(BaseModel): """Input schema for plot_series tool - no parameters needed.""" pass
- src/bls_mcp/server.py:47-52 (registration)Registration of the `PlotSeriesTool` instance in the BLS MCP server's `tools` dictionary under the key `'plot_series'`, making it available via the MCP protocol.self.tools = { "get_series": GetSeriesTool(self.data_provider), "list_series": ListSeriesTool(self.data_provider), "get_series_info": GetSeriesInfoTool(self.data_provider), "plot_series": PlotSeriesTool(self.data_provider), }
- src/bls_mcp/tools/plot_series.py:39-40 (registration)Property providing the input schema for tool registration and MCP `list_tools` response.def input_schema(self) -> type[BaseModel]: return PlotSeriesInput
- src/bls_mcp/tools/plot_series.py:27-28 (registration)Property defining the tool name `'plot_series'` used for registration and identification.def name(self) -> str: return "plot_series"