Skip to main content
Glama

list_budgets

Retrieve budget details for Oracle Cloud Infrastructure compartments to monitor spending, track actual versus forecasted amounts, and manage reset periods.

Instructions

List all budgets in a compartment.

Args:
    compartment_id: OCID of the compartment to list budgets from

Returns:
    List of budgets with amount, reset period, actual spend, and forecasted spend

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes

Implementation Reference

  • Handler function implementing the list_budgets tool logic using OCI Budget SDK to fetch and format budgets in a compartment.
    def list_budgets(budget_client: oci.budget.BudgetClient, compartment_id: str) -> List[Dict[str, Any]]:
        """
        List all budgets in a compartment.
    
        Args:
            budget_client: OCI Budget client
            compartment_id: OCID of the compartment
    
        Returns:
            List of budgets with their details
        """
        try:
            budgets_response = oci.pagination.list_call_get_all_results(
                budget_client.list_budgets,
                compartment_id
            )
    
            budgets = []
            for budget in budgets_response.data:
                budgets.append({
                    "id": budget.id,
                    "display_name": budget.display_name,
                    "compartment_id": budget.compartment_id,
                    "target_compartment_id": budget.target_compartment_id,
                    "amount": budget.amount,
                    "reset_period": budget.reset_period,
                    "lifecycle_state": budget.lifecycle_state,
                    "alert_rule_count": budget.alert_rule_count,
                    "time_created": str(budget.time_created),
                    "actual_spend": budget.actual_spend,
                    "forecasted_spend": budget.forecasted_spend,
                    "time_spend_computed": str(budget.time_spend_computed) if budget.time_spend_computed else None,
                })
    
            logger.info(f"Found {len(budgets)} budgets in compartment {compartment_id}")
            return budgets
    
        except Exception as e:
            logger.exception(f"Error listing budgets: {e}")
            raise
  • MCP tool registration decorator and wrapper function that registers 'list_budgets' tool and delegates to the core handler with the initialized budget client.
    @mcp.tool(name="list_budgets")
    @mcp_tool_wrapper(
        start_msg="Listing budgets in compartment {compartment_id}...",
        error_prefix="Error listing budgets"
    )
    async def mcp_list_budgets(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]:
        """
        List all budgets in a compartment.
    
        Args:
            compartment_id: OCID of the compartment to list budgets from
    
        Returns:
            List of budgets with amount, reset period, actual spend, and forecasted spend
        """
        return list_budgets(oci_clients["budget"], compartment_id)

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