cost_explorer_summary_tool
Analyze AWS spending patterns to identify cost drivers and optimize cloud expenses using granular data breakdowns.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | ||
| granularity | No | DAILY | |
| auth | No |
Implementation Reference
- src/aws_mcp_audit/server.py:209-213 (handler)MCP tool handler decorated with @mcp.tool (serves as registration). Builds AWS session and calls the core cost_explorer_summary helper function.@mcp.tool def cost_explorer_summary_tool(days: int = 30, granularity: str = "DAILY", auth: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: session = build_boto3_session(auth) out = cost_explorer_summary(session, days=days, granularity=granularity) return out
- Core helper function that performs the AWS Cost Explorer API call to get cost and usage summary data for the specified period and granularity.def cost_explorer_summary(session: boto3.Session, days: int = 30, granularity: str = "DAILY") -> Dict[str, Any]: ce = session.client("ce", region_name="us-east-1") # Cost Explorer is us-east-1 for API rng = _dates(days) try: resp = ce.get_cost_and_usage( TimePeriod=rng, Granularity=granularity, Metrics=["UnblendedCost"], ) return {"time_period": rng, "granularity": granularity, "results": resp.get("ResultsByTime", [])} except ClientError as e: return {"time_period": rng, "granularity": granularity, "error": str(e), "results": []}