Skip to main content
Glama

list_databases

Retrieve databases in an Oracle Cloud compartment, with optional filtering by DB System to identify available database resources and their connection details.

Instructions

List all databases in a compartment, optionally filtered by DB System.

Args:
    compartment_id: OCID of the compartment to list databases from
    db_system_id: Optional OCID of the DB System to filter databases

Returns:
    List of databases with their state, version, and connection information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
compartment_idYes
db_system_idNo

Implementation Reference

  • Core handler function implementing the logic to list OCI databases in a compartment using the OCI SDK, optionally filtered by db_system_id. Returns formatted list of database details.
    def list_databases(database_client: oci.database.DatabaseClient, compartment_id: str, 
                       db_system_id: Optional[str] = None) -> List[Dict[str, Any]]:
        """
        List all databases in a compartment, optionally filtered by DB system.
        
        Args:
            database_client: OCI Database client
            compartment_id: OCID of the compartment
            db_system_id: Optional OCID of the DB system to filter by
            
        Returns:
            List of databases with their details
        """
        try:
            databases_response = oci.pagination.list_call_get_all_results(
                database_client.list_databases,
                compartment_id,
                db_system_id=db_system_id
            )
            
            databases = []
            for database in databases_response.data:
                databases.append({
                    "id": database.id,
                    "db_name": database.db_name,
                    "compartment_id": database.compartment_id,
                    "character_set": database.character_set,
                    "ncharacter_set": database.ncharacter_set,
                    "db_workload": database.db_workload,
                    "pdb_name": database.pdb_name,
                    "lifecycle_state": database.lifecycle_state,
                    "time_created": str(database.time_created),
                    "db_unique_name": database.db_unique_name,
                    "db_system_id": database.db_system_id,
                    "vm_cluster_id": database.vm_cluster_id,
                    "kms_key_id": database.kms_key_id,
                    "vault_id": database.vault_id,
                })
            
            logger.info(f"Found {len(databases)} databases in compartment {compartment_id}")
            return databases
            
        except Exception as e:
            logger.exception(f"Error listing databases: {e}")
            raise
  • MCP tool registration for 'list_databases' using @mcp.tool decorator. This async wrapper function handles MCP context, logging, error handling via mcp_tool_wrapper, and delegates to the core handler.
    @mcp.tool(name="list_databases")
    @mcp_tool_wrapper(
        start_msg="Listing databases in compartment {compartment_id}...",
        error_prefix="Error listing databases"
    )
    async def mcp_list_databases(ctx: Context, compartment_id: str, db_system_id: Optional[str] = None) -> List[Dict[str, Any]]:
        """
        List all databases in a compartment, optionally filtered by DB System.
    
        Args:
            compartment_id: OCID of the compartment to list databases from
            db_system_id: Optional OCID of the DB System to filter databases
    
        Returns:
            List of databases with their state, version, and connection information
        """
        return list_databases(oci_clients["database"], compartment_id, db_system_id)

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