Skip to main content
Glama

get_cost_usage_summary

Retrieve cost and usage summaries for Oracle Cloud tenancies by specifying date ranges and granularity to analyze spending across services and compartments.

Instructions

Get cost and usage summary for a tenancy.

Args:
    tenant_id: OCID of the tenancy
    time_usage_started: Start time in ISO format (YYYY-MM-DD)
    time_usage_ended: End time in ISO format (YYYY-MM-DD)
    granularity: Granularity of the data (DAILY or MONTHLY), defaults to DAILY

Returns:
    List of cost and usage summaries with amounts, services, and compartments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tenant_idYes
time_usage_startedYes
time_usage_endedYes
granularityNoDAILY

Implementation Reference

  • Core handler function that queries the OCI Usage API for cost and usage summaries over a time period, aggregates results, and returns formatted list of summaries.
    def get_cost_usage_summary(usage_api_client: oci.usage_api.UsageapiClient,
                               tenant_id: str,
                               time_usage_started: str,
                               time_usage_ended: str,
                               granularity: str = "DAILY") -> List[Dict[str, Any]]:
        """
        Get cost and usage summary for a tenancy.
    
        Args:
            usage_api_client: OCI UsageApi client
            tenant_id: OCID of the tenancy
            time_usage_started: Start time in ISO format (YYYY-MM-DD)
            time_usage_ended: End time in ISO format (YYYY-MM-DD)
            granularity: Granularity of the data (DAILY, MONTHLY)
    
        Returns:
            List of cost and usage summaries
        """
        try:
            request_summarized_usages_details = oci.usage_api.models.RequestSummarizedUsagesDetails(
                tenant_id=tenant_id,
                time_usage_started=time_usage_started,
                time_usage_ended=time_usage_ended,
                granularity=granularity,
                is_aggregate_by_time=True
            )
    
            usage_response = oci.pagination.list_call_get_all_results(
                usage_api_client.request_summarized_usages,
                request_summarized_usages_details=request_summarized_usages_details
            )
    
            summaries = []
            for item in usage_response.data.items:
                summaries.append({
                    "time_usage_started": str(item.time_usage_started),
                    "time_usage_ended": str(item.time_usage_ended),
                    "computed_amount": item.computed_amount,
                    "computed_quantity": item.computed_quantity,
                    "currency": item.currency,
                    "service": item.service,
                    "resource_name": item.resource_name,
                    "compartment_name": item.compartment_name,
                    "compartment_id": item.compartment_id,
                    "unit": item.unit,
                })
    
            logger.info(f"Retrieved {len(summaries)} usage summaries for tenancy {tenant_id}")
            return summaries
    
        except Exception as e:
            logger.exception(f"Error getting cost usage summary: {e}")
            raise
  • MCP server tool registration for 'get_cost_usage_summary'. Wraps the core handler with common error handling, logging, and profile management, and registers it with the FastMCP server.
    @mcp.tool(name="get_cost_usage_summary")
    @mcp_tool_wrapper(
        start_msg="Getting cost and usage summary...",
        error_prefix="Error getting cost usage summary"
    )
    async def mcp_get_cost_usage_summary(ctx: Context, tenant_id: str, time_usage_started: str,
                                        time_usage_ended: str, granularity: str = "DAILY") -> List[Dict[str, Any]]:
        """
        Get cost and usage summary for a tenancy.
    
        Args:
            tenant_id: OCID of the tenancy
            time_usage_started: Start time in ISO format (YYYY-MM-DD)
            time_usage_ended: End time in ISO format (YYYY-MM-DD)
            granularity: Granularity of the data (DAILY or MONTHLY), defaults to DAILY
    
        Returns:
            List of cost and usage summaries with amounts, services, and compartments
        """
        return get_cost_usage_summary(oci_clients["usage_api"], tenant_id, time_usage_started,
                                     time_usage_ended, granularity)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes a read operation ('Get') but doesn't mention permissions, rate limits, data freshness, or error conditions. For a tool with no annotations, this is insufficient to inform safe and effective usage.

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 description is well-structured with clear sections for Args and Returns, making it easy to parse. It's front-loaded with the core purpose and avoids unnecessary details. However, the 'Returns' section could be more concise by omitting obvious details like 'List of'.

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 the tool's complexity (4 parameters, no output schema, no annotations), the description is moderately complete. It covers parameters well but lacks behavioral context and usage guidelines. Without an output schema, the Returns section is helpful but could detail the summary structure more.

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

Parameters4/5

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

The description adds significant value beyond the input schema, which has 0% description coverage. It explains each parameter's purpose (e.g., 'OCID of the tenancy', 'Start time in ISO format'), specifies defaults ('defaults to DAILY'), and clarifies formats ('YYYY-MM-DD'). This compensates well for the schema's lack of descriptions.

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: 'Get cost and usage summary for a tenancy.' It specifies the verb ('Get') and resource ('cost and usage summary'), making it easy to understand. However, it doesn't explicitly differentiate from sibling tools like 'get_cost_by_compartment' or 'get_cost_by_service', which prevents a perfect score.

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 guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_cost_by_compartment' or 'get_cost_by_service', nor does it specify prerequisites or exclusions. This leaves the agent without context for tool selection.

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/jopsis/mcp-server-oci'

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