Skip to main content
Glama

list_instances

Retrieve all compute instances within a specified Oracle Cloud Infrastructure compartment to manage and monitor your cloud resources.

Instructions

List all instances in a compartment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes

Implementation Reference

  • Core implementation of the list_instances tool: lists OCI compute instances using pagination, formats details including ID, name, state, shape, resources, and handles errors.
    def list_instances(compute_client: oci.core.ComputeClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all instances in a compartment. Args: compute_client: OCI Compute client compartment_id: OCID of the compartment Returns: List of instances with their details """ try: # List all instances in the compartment instances_response = oci.pagination.list_call_get_all_results( compute_client.list_instances, compartment_id, ) # Format the instances instances = [] for instance in instances_response.data: instances.append({ "id": instance.id, "name": instance.display_name, "lifecycle_state": instance.lifecycle_state, "shape": instance.shape, "time_created": str(instance.time_created), "availability_domain": instance.availability_domain, "compartment_id": instance.compartment_id, "fault_domain": instance.fault_domain, "is_running": instance.lifecycle_state == "RUNNING", "ocpu_count": getattr(instance.shape_config, "ocpus", None) if instance.shape_config else None, "memory_in_gbs": getattr(instance.shape_config, "memory_in_gbs", None) if instance.shape_config else None, }) logger.info(f"Found {len(instances)} instances in compartment {compartment_id}") return instances except Exception as e: logger.exception(f"Error listing instances: {e}") raise
  • MCP server registration of the 'list_instances' tool: defines the async handler get_instances that calls the core list_instances function with OCI compute client, includes type hints for schema and wrapper for logging/error handling.
    @mcp.tool(name="list_instances") @mcp_tool_wrapper( start_msg="Listing instances in compartment {compartment_id}...", error_prefix="Error listing instances" ) async def get_instances(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """List all instances in a compartment.""" return list_instances(oci_clients["compute"], compartment_id)
  • Import of the list_instances handler function from the tools module into the MCP server for registration.
    list_instances, get_instance, start_instance, stop_instance, )

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