list_security_lists
Retrieve security lists from an Oracle Cloud Infrastructure compartment, with optional filtering by Virtual Cloud Network to view ingress and egress rules.
Instructions
List all security lists in a compartment, optionally filtered by VCN.
Args:
compartment_id: OCID of the compartment to list security lists from
vcn_id: Optional OCID of the VCN to filter security lists
Returns:
List of security lists with their ingress and egress rules
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes | ||
| vcn_id | No |
Implementation Reference
- mcp_server_oci/tools/security.py:13-51 (handler)Core handler function implementing the logic to list OCI security lists in a compartment using the OCI VirtualNetworkClient, including pagination, error handling, and formatting the response with key details like rule counts.def list_security_lists(network_client: oci.core.VirtualNetworkClient, compartment_id: str, vcn_id: Optional[str] = None) -> List[Dict[str, Any]]: """ List all security lists in a compartment, optionally filtered by VCN. Args: network_client: OCI VirtualNetwork client compartment_id: OCID of the compartment vcn_id: Optional OCID of the VCN to filter by Returns: List of security lists with their details """ try: security_lists_response = oci.pagination.list_call_get_all_results( network_client.list_security_lists, compartment_id, vcn_id=vcn_id ) security_lists = [] for security_list in security_lists_response.data: security_lists.append({ "id": security_list.id, "display_name": security_list.display_name, "compartment_id": security_list.compartment_id, "vcn_id": security_list.vcn_id, "lifecycle_state": security_list.lifecycle_state, "time_created": str(security_list.time_created), "ingress_security_rules_count": len(security_list.ingress_security_rules) if security_list.ingress_security_rules else 0, "egress_security_rules_count": len(security_list.egress_security_rules) if security_list.egress_security_rules else 0, }) logger.info(f"Found {len(security_lists)} security lists in compartment {compartment_id}") return security_lists except Exception as e: logger.exception(f"Error listing security lists: {e}") raise
- mcp_server_oci/mcp_server.py:717-734 (registration)MCP tool registration for 'list_security_lists' using @mcp.tool decorator, wraps the security.py handler with common error handling via mcp_tool_wrapper, and passes OCI network client and parameters to the handler.@mcp.tool(name="list_security_lists") @mcp_tool_wrapper( start_msg="Listing security lists in compartment {compartment_id}...", error_prefix="Error listing security lists" ) async def mcp_list_security_lists(ctx: Context, compartment_id: str, vcn_id: Optional[str] = None) -> List[Dict[str, Any]]: """ List all security lists in a compartment, optionally filtered by VCN. Args: compartment_id: OCID of the compartment to list security lists from vcn_id: Optional OCID of the VCN to filter security lists Returns: List of security lists with their ingress and egress rules """ return list_security_lists(oci_clients["network"], compartment_id, vcn_id)