Skip to main content
Glama

list_load_balancers

Retrieve classic load balancers in an Oracle Cloud compartment to view IP addresses, shape, and state information for infrastructure management.

Instructions

List all classic load balancers in a compartment. Args: compartment_id: OCID of the compartment to list load balancers from Returns: List of load balancers with their IP addresses, shape, and state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes

Implementation Reference

  • Core handler function that executes the logic to list OCI load balancers in a compartment using the OCI SDK.
    def list_load_balancers(load_balancer_client: oci.load_balancer.LoadBalancerClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all load balancers in a compartment. Args: load_balancer_client: OCI LoadBalancer client compartment_id: OCID of the compartment Returns: List of load balancers with their details """ try: load_balancers_response = oci.pagination.list_call_get_all_results( load_balancer_client.list_load_balancers, compartment_id ) load_balancers = [] for lb in load_balancers_response.data: load_balancers.append({ "id": lb.id, "display_name": lb.display_name, "compartment_id": lb.compartment_id, "lifecycle_state": lb.lifecycle_state, "time_created": str(lb.time_created), "shape_name": lb.shape_name, "is_private": lb.is_private, "ip_addresses": [ { "ip_address": ip.ip_address, "is_public": ip.is_public, } for ip in lb.ip_addresses ] if lb.ip_addresses else [], "subnet_ids": lb.subnet_ids, "network_security_group_ids": lb.network_security_group_ids, }) logger.info(f"Found {len(load_balancers)} load balancers in compartment {compartment_id}") return load_balancers except Exception as e: logger.exception(f"Error listing load balancers: {e}") raise
  • MCP tool registration decorator and wrapper function that registers 'list_load_balancers' tool and delegates to the core handler.
    @mcp.tool(name="list_load_balancers") @mcp_tool_wrapper( start_msg="Listing load balancers in compartment {compartment_id}...", error_prefix="Error listing load balancers" ) async def mcp_list_load_balancers(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """ List all classic load balancers in a compartment. Args: compartment_id: OCID of the compartment to list load balancers from Returns: List of load balancers with their IP addresses, shape, and state """ return list_load_balancers(oci_clients["load_balancer"], compartment_id)
  • Import statement that brings the load balancer handler functions into the MCP server scope for registration.
    from mcp_server_oci.tools.load_balancer import ( list_load_balancers, get_load_balancer, list_network_load_balancers, get_network_load_balancer, )
  • Initialization of the OCI LoadBalancerClient used by the tool, stored in oci_clients dict.
    load_balancer_client = oci.load_balancer.LoadBalancerClient(config) network_load_balancer_client = oci.network_load_balancer.NetworkLoadBalancerClient(config) kms_vault_client = oci.key_management.KmsVaultClient(config) usage_api_client = oci.usage_api.UsageapiClient(config) budget_client = oci.budget.BudgetClient(config) monitoring_client = oci.monitoring.MonitoringClient(config) logging_search_client = oci.loggingsearch.LogSearchClient(config) logging_client = oci.logging.LoggingManagementClient(config) container_engine_client = oci.container_engine.ContainerEngineClient(config) oci_clients = { "compute": compute_client, "identity": identity_client, "network": network_client, "object_storage": object_storage_client, "block_storage": block_storage_client, "file_storage": file_storage_client, "database": database_client, "load_balancer": load_balancer_client, "network_load_balancer": network_load_balancer_client,

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