Skip to main content
Glama

get_cost_breakdown

Analyze AWS costs by service or usage type to identify spending patterns and optimize cloud expenses.

Instructions

Detailed cost analysis. If service_name is provided, breaks down that service by Usage Type. Otherwise, breaks down by Service.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNoStart date in YYYY-MM-DD format (default: 14 days ago).
end_dateNoEnd date in YYYY-MM-DD format.
service_nameNoOptional: Specific service to analyze (e.g., 'Amazon Elastic Compute Cloud - Compute').

Implementation Reference

  • Executes the get_cost_breakdown tool. Fetches AWS cost data using CostExplorerClient's GetCostAndUsageCommand. Groups by SERVICE (default) or USAGE_TYPE if service_name provided. Returns daily breakdown sorted by cost descending, top 100 items.
    if (name === "get_cost_breakdown") {
        const endDate = (args as any)?.end_date || new Date().toISOString().split('T')[0];
        const startDate = (args as any)?.start_date || new Date(Date.now() - 14 * 24 * 60 * 60 * 1000).toISOString().split('T')[0];
        const serviceName = (args as any)?.service_name;
    
        const groupByKey = serviceName ? "USAGE_TYPE" : "SERVICE";
        const filter = serviceName
            ? { Dimensions: { Key: "SERVICE", Values: [serviceName] } } as any
            : undefined;
    
        const command = new GetCostAndUsageCommand({
            TimePeriod: { Start: startDate, End: endDate },
            Granularity: "DAILY",
            Metrics: ["UnblendedCost"],
            GroupBy: [{ Type: "DIMENSION", Key: groupByKey }],
            Filter: filter
        });
    
        const response = await costExplorerClient.send(command);
    
        const costs = response.ResultsByTime?.flatMap(r =>
            r.Groups?.map(g => ({
                Date: r.TimePeriod?.Start,
                [groupByKey === "USAGE_TYPE" ? "UsageType" : "Service"]: g.Keys?.[0],
                Cost: parseFloat(g.Metrics?.UnblendedCost?.Amount || "0").toFixed(4),
                Unit: g.Metrics?.UnblendedCost?.Unit
            }))
        )
            .filter(c => c && parseFloat(c.Cost) > 0) // Filter out zero costs
            .sort((a, b) => parseFloat(b?.Cost || "0") - parseFloat(a?.Cost || "0")) || [];
    
        return {
            content: [{ type: "text", text: JSON.stringify(costs.slice(0, 100), null, 2) }]
        };
    }
  • Input schema definition for the get_cost_breakdown tool, defining parameters for date range and optional service_name.
    name: "get_cost_breakdown",
    description: "Detailed cost analysis. If service_name is provided, breaks down that service by Usage Type. Otherwise, breaks down by Service.",
    inputSchema: {
        type: "object",
        properties: {
            start_date: { type: "string", description: "Start date in YYYY-MM-DD format (default: 14 days ago)." },
            end_date: { type: "string", description: "End date in YYYY-MM-DD format." },
            service_name: { type: "string", description: "Optional: Specific service to analyze (e.g., 'Amazon Elastic Compute Cloud - Compute')." }
        }
    }
  • src/index.ts:208-219 (registration)
    Registers the get_cost_breakdown tool in the ListTools response with name, description, and input schema.
    {
        name: "get_cost_breakdown",
        description: "Detailed cost analysis. If service_name is provided, breaks down that service by Usage Type. Otherwise, breaks down by Service.",
        inputSchema: {
            type: "object",
            properties: {
                start_date: { type: "string", description: "Start date in YYYY-MM-DD format (default: 14 days ago)." },
                end_date: { type: "string", description: "End date in YYYY-MM-DD format." },
                service_name: { type: "string", description: "Optional: Specific service to analyze (e.g., 'Amazon Elastic Compute Cloud - Compute')." }
            }
        }
    },
  • Initializes the AWS CostExplorerClient used by the get_cost_breakdown handler.
    const costExplorerClient = new CostExplorerClient({});
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the breakdown behavior but fails to disclose critical details: whether this is a read-only operation, if it requires specific permissions, rate limits, or what the output format looks like (e.g., structured data vs. raw). For a cost analysis tool with no annotations, this is a significant gap.

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

Conciseness5/5

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

The description is two sentences with zero waste: the first states the purpose, the second explains the conditional breakdown logic. It's front-loaded and appropriately sized for the tool's complexity.

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

Completeness3/5

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

Given no annotations and no output schema, the description is incomplete for a cost analysis tool. It covers the basic purpose and parameter logic but misses behavioral context (e.g., safety, permissions) and output details. However, it's adequate for a simple read operation with well-documented parameters, leaving room for improvement.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description adds marginal value by explaining the conditional effect of service_name on the breakdown logic, but doesn't provide additional syntax or format details beyond what the schema specifies. Baseline 3 is appropriate when schema does the heavy lifting.

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's purpose as 'Detailed cost analysis' and specifies the breakdown logic (by Usage Type if service_name provided, otherwise by Service). It distinguishes from siblings like get_cost_by_service by offering more granular analysis, though it doesn't explicitly name alternatives.

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

Usage Guidelines3/5

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

The description implies when to use it through conditional logic (service_name vs. no service_name), suggesting it's for detailed breakdowns. However, it lacks explicit guidance on when to choose this over similar tools like get_cost_by_service or get_recent_cost, and doesn't mention prerequisites or exclusions.

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/bhaveshopss/MCP-server'

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