list_buckets
Retrieve all Object Storage buckets in a specified OCI compartment to manage storage resources and configurations.
Instructions
List all Object Storage buckets in a compartment.
Args:
compartment_id: OCID of the compartment to list buckets from
namespace: Optional namespace (if not provided, will be fetched automatically)
Returns:
List of buckets with their configurations and metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes | ||
| namespace | No |
Implementation Reference
- mcp_server_oci/mcp_server.py:814-836 (handler)MCP tool handler for 'list_buckets': registers the tool, wraps with error handling/logging, fetches namespace if missing, and delegates to core helper.@mcp.tool(name="list_buckets") @mcp_tool_wrapper( start_msg="Listing Object Storage buckets in compartment {compartment_id}...", error_prefix="Error listing buckets" ) async def mcp_list_buckets(ctx: Context, compartment_id: str, namespace: Optional[str] = None) -> List[Dict[str, Any]]: """ List all Object Storage buckets in a compartment. Args: compartment_id: OCID of the compartment to list buckets from namespace: Optional namespace (if not provided, will be fetched automatically) Returns: List of buckets with their configurations and metadata """ # Get namespace if not provided if not namespace: namespace_info = get_namespace(oci_clients["object_storage"]) namespace = namespace_info.get("namespace") return list_buckets(oci_clients["object_storage"], namespace, compartment_id)
- Core helper function implementing the OCI Object Storage bucket listing logic using pagination and formatting bucket details.def list_buckets(object_storage_client: oci.object_storage.ObjectStorageClient, compartment_id: str, namespace_name: str) -> List[Dict[str, Any]]: """ List all buckets in a compartment. Args: object_storage_client: OCI ObjectStorage client compartment_id: OCID of the compartment namespace_name: Object Storage namespace name Returns: List of buckets with their details """ try: buckets_response = oci.pagination.list_call_get_all_results( object_storage_client.list_buckets, namespace_name, compartment_id ) buckets = [] for bucket in buckets_response.data: buckets.append({ "name": bucket.name, "namespace": bucket.namespace, "compartment_id": bucket.compartment_id, "created_by": bucket.created_by, "time_created": str(bucket.time_created), "etag": bucket.etag, }) logger.info(f"Found {len(buckets)} buckets in compartment {compartment_id}") return buckets except Exception as e: logger.exception(f"Error listing buckets: {e}") raise
- mcp_server_oci/mcp_server.py:814-814 (registration)Tool registration decorator specifying the tool name 'list_buckets' for MCP server.@mcp.tool(name="list_buckets")