list_policies
Retrieve all IAM policies within a specified Oracle Cloud Infrastructure compartment to manage access control and permissions.
Instructions
List all IAM policies in a compartment.
Args:
compartment_id: OCID of the compartment to list policies from
Returns:
List of policies with their statements and state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes |
Implementation Reference
- mcp_server_oci/mcp_server.py:1132-1148 (handler)MCP tool handler for 'list_policies': async function decorated with @mcp.tool that processes the request, uses the shared OCI identity client, calls the helper function, and returns formatted policy list.@mcp.tool(name="list_policies") @mcp_tool_wrapper( start_msg="Listing IAM policies in compartment {compartment_id}...", error_prefix="Error listing policies" ) async def mcp_list_policies(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """ List all IAM policies in a compartment. Args: compartment_id: OCID of the compartment to list policies from Returns: List of policies with their statements and state """ return list_policies(oci_clients["identity"], compartment_id)
- Core helper function implementing the OCI API call to list policies using pagination, extracts and formats policy details into list of dicts.def list_policies(identity_client: oci.identity.IdentityClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all policies in a compartment. Args: identity_client: OCI Identity client compartment_id: OCID of the compartment Returns: List of policies with their details """ try: policies_response = oci.pagination.list_call_get_all_results( identity_client.list_policies, compartment_id ) policies = [] for policy in policies_response.data: policies.append({ "id": policy.id, "name": policy.name, "description": policy.description, "statements": policy.statements, "version_date": str(policy.version_date) if policy.version_date else None, "lifecycle_state": policy.lifecycle_state, "time_created": str(policy.time_created), "compartment_id": policy.compartment_id, }) logger.info(f"Found {len(policies)} policies in compartment {compartment_id}") return policies except Exception as e: logger.exception(f"Error listing policies: {e}") raise
- mcp_server_oci/mcp_server.py:42-51 (registration)Import statement registering the list_policies helper function 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, )