Skip to main content
Glama

list_keys

Retrieve all encryption keys stored in an Oracle Cloud vault compartment to manage cryptographic assets and their configurations.

Instructions

List all encryption keys in a vault's compartment.

Note: You must first get a vault to obtain its management_endpoint.

Args:
    compartment_id: OCID of the compartment
    management_endpoint: Management endpoint from the vault (get from vault details)

Returns:
    List of keys with their algorithm, protection mode, and state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes
management_endpointYes

Implementation Reference

  • MCP tool handler function 'mcp_list_keys' decorated with @mcp.tool(name='list_keys'). It calls the helper list_keys with OCI config and parameters.
    @mcp.tool(name="list_keys")
    @mcp_tool_wrapper(
        start_msg="Listing encryption keys in vault...",
        error_prefix="Error listing keys"
    )
    async def mcp_list_keys(ctx: Context, compartment_id: str, management_endpoint: str) -> List[Dict[str, Any]]:
        """
        List all encryption keys in a vault's compartment.
    
        Note: You must first get a vault to obtain its management_endpoint.
    
        Args:
            compartment_id: OCID of the compartment
            management_endpoint: Management endpoint from the vault (get from vault details)
    
        Returns:
            List of keys with their algorithm, protection mode, and state
        """
        return list_keys(oci_clients["config"], management_endpoint, compartment_id)
  • Core helper function 'list_keys' that creates OCI KmsManagementClient and lists keys using OCI pagination, formatting the response.
    def list_keys(config: dict, management_endpoint: str, compartment_id: str) -> List[Dict[str, Any]]:
        """
        List all keys in a vault's compartment.
    
        Args:
            config: OCI config dict
            management_endpoint: Management endpoint from the vault
            compartment_id: OCID of the compartment
    
        Returns:
            List of keys with their details
        """
        try:
            # Create KMS Management client with the vault's management endpoint
            kms_management_client = oci.key_management.KmsManagementClient(config, service_endpoint=management_endpoint)
    
            keys_response = oci.pagination.list_call_get_all_results(
                kms_management_client.list_keys,
                compartment_id
            )
    
            keys = []
            for key in keys_response.data:
                keys.append({
                    "id": key.id,
                    "display_name": key.display_name,
                    "compartment_id": key.compartment_id,
                    "lifecycle_state": key.lifecycle_state,
                    "time_created": str(key.time_created),
                    "vault_id": key.vault_id,
                    "protection_mode": key.protection_mode,
                    "algorithm": key.algorithm,
                })
    
            logger.info(f"Found {len(keys)} keys in compartment {compartment_id}")
            return keys
    
        except Exception as e:
            logger.exception(f"Error listing keys: {e}")
            raise

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