Skip to main content
Glama

list_network_security_groups

Retrieve Network Security Groups (NSGs) and their security rules from a specified Oracle Cloud Infrastructure compartment, optionally filtered by VCN.

Instructions

List all Network Security Groups (NSGs) in a compartment.

Args:
    compartment_id: OCID of the compartment to list NSGs from
    vcn_id: Optional OCID of the VCN to filter NSGs

Returns:
    List of NSGs with their security rules

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes
vcn_idNo

Implementation Reference

  • Core handler function that executes the OCI API call to list network security groups in a compartment, optionally filtered by VCN, using pagination and formatting the response.
    def list_network_security_groups(network_client: oci.core.VirtualNetworkClient, compartment_id: str,
                                      vcn_id: Optional[str] = None) -> List[Dict[str, Any]]:
        """
        List all network security groups 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 network security groups with their details
        """
        try:
            nsgs_response = oci.pagination.list_call_get_all_results(
                network_client.list_network_security_groups,
                compartment_id,
                vcn_id=vcn_id
            )
            
            nsgs = []
            for nsg in nsgs_response.data:
                nsgs.append({
                    "id": nsg.id,
                    "display_name": nsg.display_name,
                    "compartment_id": nsg.compartment_id,
                    "vcn_id": nsg.vcn_id,
                    "lifecycle_state": nsg.lifecycle_state,
                    "time_created": str(nsg.time_created),
                })
            
            logger.info(f"Found {len(nsgs)} network security groups in compartment {compartment_id}")
            return nsgs
            
        except Exception as e:
            logger.exception(f"Error listing network security groups: {e}")
            raise
  • MCP tool registration using @mcp.tool decorator. This async wrapper function handles context, logging, error handling via mcp_tool_wrapper, and delegates to the core handler.
    @mcp.tool(name="list_network_security_groups")
    @mcp_tool_wrapper(
        start_msg="Listing network security groups in compartment {compartment_id}...",
        error_prefix="Error listing network security groups"
    )
    async def mcp_list_network_security_groups(ctx: Context, compartment_id: str, vcn_id: Optional[str] = None) -> List[Dict[str, Any]]:
        """
        List all Network Security Groups (NSGs) in a compartment.
    
        Args:
            compartment_id: OCID of the compartment to list NSGs from
            vcn_id: Optional OCID of the VCN to filter NSGs
    
        Returns:
            List of NSGs with their security rules
        """
        return list_network_security_groups(oci_clients["network"], compartment_id, vcn_id)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states it's a list operation, implying read-only behavior, but doesn't mention critical details like pagination, rate limits, authentication requirements, error conditions, or what 'List of NSGs with their security rules' entails (e.g., format, depth). For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It starts with a clear purpose statement, followed by 'Args:' and 'Returns:' sections that efficiently document inputs and outputs. Each sentence adds value without redundancy, though it could be slightly more concise by integrating the args/returns into the main flow.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, 0% schema description coverage, and no output schema, the description is moderately complete. It covers the basic purpose and parameters adequately, but lacks details on behavioral aspects (e.g., pagination, errors) and output specifics. For a list tool with simple parameters, it meets minimum viability but misses opportunities to fully compensate for the missing structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaningful context for both parameters: 'compartment_id: OCID of the compartment to list NSGs from' and 'vcn_id: Optional OCID of the VCN to filter NSGs.' This clarifies the purpose and usage of each parameter beyond their schema titles ('Compartment Id', 'Vcn Id'), though it doesn't specify format details like OCID structure or filtering logic.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'List all Network Security Groups (NSGs) in a compartment.' It specifies the verb ('List'), resource ('Network Security Groups'), and scope ('in a compartment'), which is clear and specific. However, it doesn't explicitly differentiate from sibling tools like 'get_network_security_group' (singular vs. plural), though the naming convention implies 'list' vs. 'get' distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_network_security_group' for retrieving a specific NSG or other list tools for different resources. There's no context on prerequisites, filtering options beyond the optional vcn_id, or comparison to similar operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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