Skip to main content
Glama

get_key

Retrieve detailed encryption key information from Oracle Cloud Infrastructure, including algorithm, shape, and version details for security management.

Instructions

Get detailed information about a specific encryption key.

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

Args:
    key_id: OCID of the key to retrieve
    management_endpoint: Management endpoint from the vault (get from vault details)

Returns:
    Detailed key information including algorithm, shape, and versions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
key_idYes
management_endpointYes

Implementation Reference

  • MCP tool registration and handler for 'get_key'. This async function is decorated with @mcp.tool(name='get_key') and handles the tool execution by calling the underlying helper with OCI config and parameters.
    @mcp.tool(name="get_key")
    @mcp_tool_wrapper(
        start_msg="Getting encryption key details for {key_id}...",
        success_msg="Retrieved key details successfully",
        error_prefix="Error getting key details"
    )
    async def mcp_get_key(ctx: Context, key_id: str, management_endpoint: str) -> Dict[str, Any]:
        """
        Get detailed information about a specific encryption key.
    
        Note: You must first get a vault to obtain its management_endpoint.
    
        Args:
            key_id: OCID of the key to retrieve
            management_endpoint: Management endpoint from the vault (get from vault details)
    
        Returns:
            Detailed key information including algorithm, shape, and versions
        """
        return get_key(oci_clients["config"], management_endpoint, key_id)
  • Core helper function implementing the OCI KMS key retrieval logic. Creates a KMSManagementClient using the vault's management endpoint and fetches/formats key details.
    def get_key(config: dict, management_endpoint: str, key_id: str) -> Dict[str, Any]:
        """
        Get details of a specific key.
    
        Args:
            config: OCI config dict
            management_endpoint: Management endpoint from the vault
            key_id: OCID of the key
    
        Returns:
            Details of the key
        """
        try:
            # Create KMS Management client with the vault's management endpoint
            kms_management_client = oci.key_management.KmsManagementClient(config, service_endpoint=management_endpoint)
    
            key = kms_management_client.get_key(key_id).data
    
            key_details = {
                "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,
                "current_key_version": key.current_key_version,
                "key_shape": {
                    "algorithm": key.key_shape.algorithm if key.key_shape else None,
                    "length": key.key_shape.length if key.key_shape else None,
                    "curve_id": key.key_shape.curve_id if key.key_shape else None,
                } if key.key_shape else None,
                "is_primary": key.is_primary,
                "replica_details": {
                    "replication_id": key.replica_details.replication_id if key.replica_details else None,
                } if key.replica_details else None,
            }
    
            logger.info(f"Retrieved details for key {key_id}")
            return key_details
    
        except Exception as e:
            logger.exception(f"Error getting key details: {e}")
            raise
  • Import statement registering the get_key helper function from the security tools module for use in the MCP server.
    from mcp_server_oci.tools.security import (
        list_security_lists,
        get_security_list,
        list_network_security_groups,
        get_network_security_group,
        list_vaults,
        get_vault,
        list_keys,
        get_key,
    )

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