list_log_groups
Retrieve all log groups within a specified Oracle Cloud Infrastructure compartment to monitor and manage logging resources.
Instructions
List all log groups in a compartment.
Args:
compartment_id: OCID of the compartment to list log groups from
Returns:
List of log groups with their display names and lifecycle states
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes |
Implementation Reference
- Core handler function that executes the OCI API call to list log groups in a compartment using pagination and formats the response.def list_log_groups(logging_client: oci.logging.LoggingManagementClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all log groups in a compartment. Args: logging_client: OCI Logging Management client compartment_id: OCID of the compartment Returns: List of log groups with their details """ try: log_groups_response = oci.pagination.list_call_get_all_results( logging_client.list_log_groups, compartment_id ) log_groups = [] for log_group in log_groups_response.data: log_groups.append({ "id": log_group.id, "display_name": log_group.display_name, "description": log_group.description, "compartment_id": log_group.compartment_id, "time_created": str(log_group.time_created), "time_last_modified": str(log_group.time_last_modified), "lifecycle_state": log_group.lifecycle_state, }) logger.info(f"Found {len(log_groups)} log groups in compartment {compartment_id}") return log_groups except Exception as e: logger.exception(f"Error listing log groups: {e}") raise
- mcp_server_oci/mcp_server.py:1730-1746 (registration)MCP tool registration with @mcp.tool decorator, including wrapper for error handling, logging, and OCI client injection.@mcp.tool(name="list_log_groups") @mcp_tool_wrapper( start_msg="Listing log groups in compartment {compartment_id}...", error_prefix="Error listing log groups" ) async def mcp_list_log_groups(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """ List all log groups in a compartment. Args: compartment_id: OCID of the compartment to list log groups from Returns: List of log groups with their display names and lifecycle states """ return list_log_groups(oci_clients["logging"], compartment_id)