Skip to main content
Glama

get_cost_by_service

Analyze Oracle Cloud Infrastructure spending by retrieving cost breakdowns per service for a specified tenancy and time period.

Instructions

Get cost breakdown by service 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)

Returns:
    List of costs grouped by service with total cost per service

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tenant_idYes
time_usage_startedYes
time_usage_endedYes

Implementation Reference

  • MCP tool registration and wrapper handler function that provides the tool interface, handles context, logging, errors, and delegates to the core helper using OCI usage_api client.
    @mcp.tool(name="get_cost_by_service")
    @mcp_tool_wrapper(
        start_msg="Getting cost breakdown by service...",
        error_prefix="Error getting cost by service"
    )
    async def mcp_get_cost_by_service(ctx: Context, tenant_id: str, time_usage_started: str,
                                      time_usage_ended: str) -> List[Dict[str, Any]]:
        """
        Get cost breakdown by service 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)
    
        Returns:
            List of costs grouped by service with total cost per service
        """
        return get_cost_by_service(oci_clients["usage_api"], tenant_id, time_usage_started, time_usage_ended)
  • Core helper function that executes the OCI Usage API call to request summarized usages grouped by service and aggregates the total cost per service.
    def get_cost_by_service(usage_api_client: oci.usage_api.UsageapiClient,
                           tenant_id: str,
                           time_usage_started: str,
                           time_usage_ended: str) -> List[Dict[str, Any]]:
        """
        Get cost breakdown by service.
    
        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)
    
        Returns:
            List of costs grouped by service
        """
        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="DAILY",
                group_by=["service"]
            )
    
            usage_response = oci.pagination.list_call_get_all_results(
                usage_api_client.request_summarized_usages,
                request_summarized_usages_details=request_summarized_usages_details
            )
    
            # Aggregate by service
            service_costs = {}
            for item in usage_response.data.items:
                service = item.service
                if service not in service_costs:
                    service_costs[service] = {
                        "service": service,
                        "total_cost": 0.0,
                        "currency": item.currency,
                        "unit": item.unit,
                    }
                service_costs[service]["total_cost"] += float(item.computed_amount) if item.computed_amount else 0.0
    
            result = list(service_costs.values())
            logger.info(f"Retrieved cost breakdown for {len(result)} services")
            return result
    
        except Exception as e:
            logger.exception(f"Error getting cost by service: {e}")
            raise
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 states the tool returns a list of costs grouped by service, which is helpful, but lacks critical details such as whether it's a read-only operation, requires specific permissions, has rate limits, or handles errors. For a cost-reporting tool with zero annotation coverage, 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.

Conciseness4/5

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

The description is appropriately sized and well-structured, with clear sections for purpose, arguments, and returns. Each sentence earns its place by providing essential information without redundancy. However, the formatting with quotes and line breaks could be slightly cleaner, preventing a perfect score.

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 moderate complexity (3 parameters, no output schema, no annotations), the description is adequate but incomplete. It covers the basic purpose and parameters but lacks usage guidelines, behavioral details, and output specifics. It meets the minimum viable threshold but has clear gaps that could hinder an AI agent's effectiveness.

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 substantial meaning beyond the input schema, which has 0% coverage. It explains that 'tenant_id' is an OCID, specifies the ISO format for date parameters, and clarifies their roles as start and end times. This compensates well for the schema's lack of descriptions, though it doesn't cover all potential nuances like timezone handling.

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 breakdown by service for a tenancy.' It specifies the verb ('Get'), resource ('cost breakdown by service'), and scope ('for a tenancy'), making the intent unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_cost_by_compartment' or 'get_cost_usage_summary,' 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_usage_summary,' nor does it specify prerequisites or exclusions. The only implied context is the need for a tenancy and date range, but this is insufficient for effective 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