list_images
Retrieve all compute images within a specified Oracle Cloud Infrastructure compartment, displaying OS details, version, size, and lifecycle state for resource management.
Instructions
List all compute images in a compartment.
Args:
compartment_id: OCID of the compartment to list images from
Returns:
List of images with OS, version, size, and lifecycle state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes |
Implementation Reference
- mcp_server_oci/tools/resources.py:79-117 (handler)Core handler function that queries OCI Compute API for images in a compartment, formats the response into a list of dictionaries with relevant image details.def list_images(compute_client: oci.core.ComputeClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all images in a compartment. Args: compute_client: OCI Compute client compartment_id: OCID of the compartment Returns: List of images with their details """ try: images_response = oci.pagination.list_call_get_all_results( compute_client.list_images, compartment_id ) images = [] for image in images_response.data: images.append({ "id": image.id, "display_name": image.display_name, "compartment_id": image.compartment_id, "operating_system": image.operating_system, "operating_system_version": image.operating_system_version, "lifecycle_state": image.lifecycle_state, "time_created": str(image.time_created), "size_in_mbs": image.size_in_mbs, "base_image_id": image.base_image_id, "create_image_allowed": image.create_image_allowed, "listing_type": image.listing_type, }) logger.info(f"Found {len(images)} images in compartment {compartment_id}") return images except Exception as e: logger.exception(f"Error listing images: {e}") raise
- mcp_server_oci/mcp_server.py:1322-1338 (registration)MCP tool registration using @mcp.tool decorator. This wrapper function handles MCP context, logging, error handling via mcp_tool_wrapper, and delegates to the core list_images handler.@mcp.tool(name="list_images") @mcp_tool_wrapper( start_msg="Listing compute images in compartment {compartment_id}...", error_prefix="Error listing images" ) async def mcp_list_images(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """ List all compute images in a compartment. Args: compartment_id: OCID of the compartment to list images from Returns: List of images with OS, version, size, and lifecycle state """ return list_images(oci_clients["compute"], compartment_id)
- mcp_server_oci/mcp_server.py:87-96 (registration)Import statement that brings the list_images handler function into scope for use in the MCP server registration.from mcp_server_oci.tools.resources import ( list_availability_domains, list_fault_domains, list_images, get_image, list_shapes, get_namespace, list_regions, get_tenancy_info, )