Skip to main content
Glama
oldcoder01
by oldcoder01

generate_report

Generate actionable AWS audit reports from security snapshots to identify compliance gaps and operational risks for contractors.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
snapshot_idYes
finding_set_idNo
formatNomd
authNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function for the 'generate_report' MCP tool. Decorated with @mcp.tool for registration. Generates a markdown or PDF report by loading snapshot data, findings, cost analysis, optionally fetching live cost explorer data, rendering via helper, and saving files.
    @mcp.tool
    def generate_report(snapshot_id: str, finding_set_id: Optional[str] = None, format: str = "md", auth: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
        s_path = os.path.join(snapshot_dir(DATA_DIR, snapshot_id), "snapshot.json")
        snap = read_json(s_path)
    
        fsid = finding_set_id or snapshot_id
        f_path = os.path.join(snapshot_dir(DATA_DIR, fsid), "findings.json")
        findings = read_json(f_path) if os.path.exists(f_path) else []
    
        cost_path = os.path.join(snapshot_dir(DATA_DIR, snapshot_id), "cost.json")
        cost = read_json(cost_path) if os.path.exists(cost_path) else {}
    
        # Optionally include cost explorer in report (best-effort)
        cost_ce = {}
        try:
            if auth is not None:
                session = build_boto3_session(auth)
                cost_ce = cost_explorer_summary(session, days=30, granularity="DAILY")
        except Exception as e:
            cost_ce = {"error": str(e), "results": []}
    
        md = render_markdown(snap, findings, cost, cost_ce)
        out_dir = snapshot_dir(DATA_DIR, snapshot_id)
    
        md_path = os.path.join(out_dir, "report.md")
        with open(md_path, "w", encoding="utf-8") as f:
            f.write(md)
    
        if format.lower() == "pdf":
            pdf_path = os.path.join(out_dir, "report.pdf")
            write_pdf_from_text(pdf_path=pdf_path, title="AWS Audit Snapshot", text=md)
            return {"report_md": md_path, "report_pdf": pdf_path}
    
        return {"report_md": md_path}
  • Key helper function that formats the report data into a markdown string, including executive summary, top findings, cost snapshot, and inventory summary.
    def render_markdown(snapshot: Dict[str, Any], findings: List[Dict[str, Any]], cost: Dict[str, Any], cost_explorer: Dict[str, Any]) -> str:
        meta = snapshot.get("meta", {})
        lines: List[str] = []
    
        lines.append(f"# AWS Audit Snapshot — {meta.get('account_id', 'unknown')}")
        lines.append("")
        lines.append(f"- Snapshot ID: `{meta.get('snapshot_id')}`")
        lines.append(f"- Collected: `{meta.get('collected_at')}`")
        lines.append(f"- Regions: {', '.join(meta.get('regions', []))}")
        lines.append("")
    
        lines.append("## Executive Summary")
        lines.append(f"- Findings: **{len(findings)}**")
        lines.append("")
    
        lines.append("## Top Findings")
        if not findings:
            lines.append("- No findings generated.")
        else:
            # show first 15
            for f in findings[:15]:
                lines.append(f"- **{f.get('severity')}** — {f.get('title')} ({f.get('region') or 'global'})")
        lines.append("")
    
        lines.append("## Cost Snapshot")
        if cost:
            lines.append("### Tier 1 (inventory-derived signals)")
            lines.append(f"- Unattached EBS (GB): {cost.get('unattached_ebs_gb')}")
            lines.append(f"- Unassociated EIPs: {cost.get('unassociated_eips')}")
            lines.append("")
        if cost_explorer and cost_explorer.get("results"):
            lines.append("### Tier 2 (Cost Explorer)")
            lines.append(f"- Range: {cost_explorer.get('time_period')}")
            lines.append(f"- Points: {len(cost_explorer.get('results', []))}")
            lines.append("")
        elif cost_explorer and cost_explorer.get("error"):
            lines.append("### Tier 2 (Cost Explorer)")
            lines.append(f"- Not available: {cost_explorer.get('error')}")
            lines.append("")
    
        lines.append("## Inventory Summary")
        summary = snapshot.get("summary", {})
        for k, v in summary.items():
            lines.append(f"- {k}: {v}")
        lines.append("")
        return "\n".join(lines)
  • Supporting helper to convert markdown text to PDF using reportlab library, used when format='pdf'.
    def write_pdf_from_text(pdf_path: str, title: str, text: str) -> None:
        os.makedirs(os.path.dirname(pdf_path), exist_ok=True)
        c = canvas.Canvas(pdf_path, pagesize=LETTER)
        width, height = LETTER
        y = height - 72
        c.setTitle(title)
    
        for raw in text.splitlines():
            if y < 72:
                c.showPage()
                y = height - 72
            c.drawString(72, y, raw[:1200])
            y -= 14
    
        c.save()
  • MCP tool registration decorator applied to the generate_report handler function.
    @mcp.tool
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

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

Parameters1/5

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

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

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/oldcoder01/aws-mcp-audit'

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