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
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes |
Implementation Reference
- mcp_server_oci/tools/cost.py:173-212 (handler)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_server_oci/mcp_server.py:1562-1578 (registration)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)