Skip to main content
Glama

list_compartments

Retrieve all Oracle Cloud Infrastructure compartments accessible to your user account for resource management and organization.

Instructions

List all compartments accessible to the user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler function that retrieves the identity client from global oci_clients and calls the helper function to list compartments.
    """List all compartments accessible to the user."""
    return list_compartments(oci_clients["identity"])
  • Registration of the 'list_compartments' tool using the @mcp.tool decorator.
    @mcp_tool_wrapper(
  • Core helper function that implements the logic to list all compartments (root and nested) using the OCI Identity SDK, formatting them into a standardized dictionary structure.
    def list_compartments(identity_client: oci.identity.IdentityClient) -> List[Dict[str, Any]]:
        """
        List all compartments accessible to the user.
        
        Args:
            identity_client: OCI Identity client
            
        Returns:
            List of compartments with their details
        """
        try:
            # Get tenant ID (root compartment)
            tenant_id = identity_client.get_user(identity_client.base_client.config.get("user")).data.compartment_id
            
            # Get all compartments (including nested ones)
            compartments = []
            
            # Get root compartment first
            try:
                root_compartment = identity_client.get_compartment(tenant_id).data
                compartments.append({
                    "id": root_compartment.id,
                    "name": root_compartment.name,
                    "description": root_compartment.description,
                    "lifecycle_state": root_compartment.lifecycle_state,
                    "is_accessible": True,
                    "time_created": str(root_compartment.time_created),
                    "is_root": True,
                })
            except Exception as e:
                logger.warning(f"Could not get root compartment: {e}")
            
            # Get all compartments in the tenancy
            list_compartments_response = oci.pagination.list_call_get_all_results(
                identity_client.list_compartments,
                tenant_id,
                compartment_id_in_subtree=True,
                lifecycle_state="ACTIVE",
            )
            
            # Format the compartments
            for compartment in list_compartments_response.data:
                compartments.append({
                    "id": compartment.id,
                    "name": compartment.name,
                    "description": compartment.description,
                    "parent_compartment_id": compartment.compartment_id,
                    "lifecycle_state": compartment.lifecycle_state,
                    "is_accessible": compartment.lifecycle_state == "ACTIVE",
                    "time_created": str(compartment.time_created),
                    "is_root": False,
                })
            
            logger.info(f"Found {len(compartments)} compartments")
            return compartments
            
        except Exception as e:
            logger.exception(f"Error listing compartments: {e}")
            raise
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states 'accessible to the user', hinting at permission-based filtering, but doesn't disclose behavioral traits like pagination, rate limits, error conditions, or output format. For a list operation with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any fluff. It's front-loaded and wastes no words, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (a list operation with many sibling tools), no annotations, and no output schema, the description is incomplete. It lacks details on return values, pagination, or how 'accessible' is determined, which are crucial for an agent to use this tool effectively in context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so no parameter documentation is needed. The description doesn't add parameter details, which is appropriate here, earning a baseline score of 4 for adequately handling the lack of parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List all compartments') and the resource ('compartments accessible to the user'), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'get_tenancy_info' or 'list_oci_profiles', but the verb 'list' and resource 'compartments' provide enough specificity for basic clarity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. With many sibling tools (e.g., 'get_tenancy_info', 'list_oci_profiles'), the description lacks context about whether this is for general compartment discovery, permission checks, or other use cases, leaving the agent to infer usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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