Skip to main content
Glama

get_instance

Retrieve configuration and status details for Oracle Cloud Infrastructure compute instances to monitor resources and manage deployments.

Instructions

Get details of a specific instance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instance_idYes

Implementation Reference

  • MCP tool handler for 'get_instance': async wrapper that calls the core get_instance function with OCI compute client, includes logging and error handling via mcp_tool_wrapper.
    @mcp.tool(name="get_instance")
    @mcp_tool_wrapper(
        start_msg="Getting details for instance {instance_id}...",
        success_msg="Retrieved instance details successfully",
        error_prefix="Error getting instance details"
    )
    async def get_instance_details(ctx: Context, instance_id: str) -> Dict[str, Any]:
        """Get details of a specific instance."""
        return get_instance(oci_clients["compute"], instance_id)
  • Core helper function implementing the OCI API calls to retrieve instance details including VNIC attachments and shape configuration.
    def get_instance(compute_client: oci.core.ComputeClient, instance_id: str) -> Dict[str, Any]:
        """
        Get details of a specific instance.
        
        Args:
            compute_client: OCI Compute client
            instance_id: OCID of the instance
            
        Returns:
            Details of the instance
        """
        try:
            # Get the instance details
            instance = compute_client.get_instance(instance_id).data
            
            # Get VNIC attachments for the instance
            vnic_attachments = oci.pagination.list_call_get_all_results(
                compute_client.list_vnic_attachments,
                instance.compartment_id,
                instance_id=instance_id
            ).data
            
            # Format the instance details
            instance_details = {
                "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",
                "metadata": instance.metadata,
                "vnic_attachments": [
                    {
                        "id": vnic.id,
                        "display_name": vnic.display_name,
                        "lifecycle_state": vnic.lifecycle_state,
                        "vnic_id": vnic.vnic_id,
                    }
                    for vnic in vnic_attachments
                ],
            }
            
            # Include shape config if available
            if instance.shape_config:
                instance_details.update({
                    "ocpu_count": instance.shape_config.ocpus if hasattr(instance.shape_config, "ocpus") else None,
                    "memory_in_gbs": instance.shape_config.memory_in_gbs if hasattr(instance.shape_config, "memory_in_gbs") else None,
                    "processors": instance.shape_config.processors if hasattr(instance.shape_config, "processors") else None,
                })
            
            logger.info(f"Retrieved details for instance {instance_id}")
            return instance_details
            
        except Exception as e:
            logger.exception(f"Error getting instance details: {e}")
            raise
  • Import of the get_instance helper function from instances.py, required for the MCP tool handler.
    from mcp_server_oci.tools.compartments import list_compartments
    from mcp_server_oci.tools.instances import (
        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