list_groups
Retrieve all IAM groups within a specified Oracle Cloud compartment, including member counts and status details for access management.
Instructions
List all IAM groups in a compartment.
Args:
compartment_id: OCID of the compartment to list groups from
Returns:
List of groups with their members count and state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes |
Implementation Reference
- mcp_server_oci/mcp_server.py:1094-1110 (handler)MCP tool registration and handler for 'list_groups'. This async function is decorated with @mcp.tool(name='list_groups') and wraps the core list_groups implementation, handling context, errors, and OCI client access.@mcp.tool(name="list_groups") @mcp_tool_wrapper( start_msg="Listing IAM groups in compartment {compartment_id}...", error_prefix="Error listing groups" ) async def mcp_list_groups(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """ List all IAM groups in a compartment. Args: compartment_id: OCID of the compartment to list groups from Returns: List of groups with their members count and state """ return list_groups(oci_clients["identity"], compartment_id)
- Core helper function implementing the logic to list OCI Identity groups using the OCI SDK, formatting results into a list of dictionaries.def list_groups(identity_client: oci.identity.IdentityClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all groups in a compartment. Args: identity_client: OCI Identity client compartment_id: OCID of the compartment Returns: List of groups with their details """ try: groups_response = oci.pagination.list_call_get_all_results( identity_client.list_groups, compartment_id ) groups = [] for group in groups_response.data: groups.append({ "id": group.id, "name": group.name, "description": group.description, "lifecycle_state": group.lifecycle_state, "time_created": str(group.time_created), "compartment_id": group.compartment_id, }) logger.info(f"Found {len(groups)} groups in compartment {compartment_id}") return groups except Exception as e: logger.exception(f"Error listing groups: {e}") raise
- mcp_server_oci/mcp_server.py:42-51 (registration)Import statement registering the list_groups helper function for use in the MCP server.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, )