get_policy
Retrieve detailed IAM policy information including all statements by providing the policy OCID to manage Oracle Cloud Infrastructure access controls.
Instructions
Get detailed information about a specific IAM policy.
Args:
policy_id: OCID of the policy to retrieve
Returns:
Detailed policy information including all policy statements
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| policy_id | Yes |
Implementation Reference
- mcp_server_oci/mcp_server.py:1150-1167 (handler)MCP tool handler for the 'get_policy' tool. Wraps the helper function with error handling and logging, calls OCI Identity client via the imported helper.@mcp.tool(name="get_policy") @mcp_tool_wrapper( start_msg="Getting policy details for {policy_id}...", success_msg="Retrieved policy details successfully", error_prefix="Error getting policy details" ) async def mcp_get_policy(ctx: Context, policy_id: str) -> Dict[str, Any]: """ Get detailed information about a specific IAM policy. Args: policy_id: OCID of the policy to retrieve Returns: Detailed policy information including all policy statements """ return get_policy(oci_clients["identity"], policy_id)
- Core helper function that executes the OCI Identity API call to retrieve policy details and formats the response dictionary.def get_policy(identity_client: oci.identity.IdentityClient, policy_id: str) -> Dict[str, Any]: """ Get details of a specific policy. Args: identity_client: OCI Identity client policy_id: OCID of the policy Returns: Details of the policy """ try: policy = identity_client.get_policy(policy_id).data policy_details = { "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"Retrieved details for policy {policy_id}") return policy_details except Exception as e: logger.exception(f"Error getting policy details: {e}") raise
- mcp_server_oci/mcp_server.py:42-51 (registration)Import statement registering the get_policy helper function from identity.py for use in the MCP tool handlers.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, )