Skip to main content
Glama

list_dynamic_groups

Retrieve dynamic groups from an Oracle Cloud Infrastructure compartment to manage access control policies and permissions based on matching rules.

Instructions

List all dynamic groups in a compartment.

Args:
    compartment_id: OCID of the compartment to list dynamic groups from

Returns:
    List of dynamic groups with their matching rules and state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes

Implementation Reference

  • The primary MCP tool handler for 'list_dynamic_groups'. It is registered via @mcp.tool decorator, wrapped with error handling, and delegates to the helper function in identity.py.
    @mcp.tool(name="list_dynamic_groups")
    @mcp_tool_wrapper(
        start_msg="Listing dynamic groups in compartment {compartment_id}...",
        error_prefix="Error listing dynamic groups"
    )
    async def mcp_list_dynamic_groups(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]:
        """
        List all dynamic groups in a compartment.
    
        Args:
            compartment_id: OCID of the compartment to list dynamic groups from
    
        Returns:
            List of dynamic groups with their matching rules and state
        """
        return list_dynamic_groups(oci_clients["identity"], compartment_id)
  • Helper function that performs the actual OCI API call to list_dynamic_groups, paginates results, formats the response dictionary, and handles logging/errors.
    def list_dynamic_groups(identity_client: oci.identity.IdentityClient, compartment_id: str) -> List[Dict[str, Any]]:
        """
        List all dynamic groups in a compartment.
        
        Args:
            identity_client: OCI Identity client
            compartment_id: OCID of the compartment
            
        Returns:
            List of dynamic groups with their details
        """
        try:
            dynamic_groups_response = oci.pagination.list_call_get_all_results(
                identity_client.list_dynamic_groups,
                compartment_id
            )
            
            dynamic_groups = []
            for dynamic_group in dynamic_groups_response.data:
                dynamic_groups.append({
                    "id": dynamic_group.id,
                    "name": dynamic_group.name,
                    "description": dynamic_group.description,
                    "matching_rule": dynamic_group.matching_rule,
                    "lifecycle_state": dynamic_group.lifecycle_state,
                    "time_created": str(dynamic_group.time_created),
                    "compartment_id": dynamic_group.compartment_id,
                })
            
            logger.info(f"Found {len(dynamic_groups)} dynamic groups in compartment {compartment_id}")
            return dynamic_groups
            
        except Exception as e:
            logger.exception(f"Error listing dynamic groups: {e}")
            raise
  • Import statement that brings the helper function into scope for use in the MCP tool handler.
    from mcp_server_oci.tools.identity import (
        list_users,
        get_user,
        list_groups,
        get_group,
        list_policies,
        get_policy,
        list_dynamic_groups,
        get_dynamic_group,
    )

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