Skip to main content
Glama

list_assets

Retrieve assets in a GCP project via Cloud Asset Inventory API, with options to filter by specific types and control paginated results for efficient asset management.

Instructions

    List assets in a GCP project using Cloud Asset Inventory API.
    
    Args:
        project_id: The ID of the GCP project to list assets for
        asset_types: Optional list of asset types to filter by (e.g., ["compute.googleapis.com/Instance"])
        page_size: Number of assets to return per page (default: 50, max: 1000)
    
    Returns:
        List of assets in the specified GCP project
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
asset_typesNo
page_sizeNo
project_idYes

Implementation Reference

  • The handler function for the 'list_assets' tool. It uses the Google Cloud AssetServiceClient to list assets in a GCP project, supports filtering by asset types and pagination.
    @mcp.tool()
    def list_assets(project_id: str, asset_types: Optional[List[str]] = None, page_size: int = 50) -> str:
        """
        List assets in a GCP project using Cloud Asset Inventory API.
        
        Args:
            project_id: The ID of the GCP project to list assets for
            asset_types: Optional list of asset types to filter by (e.g., ["compute.googleapis.com/Instance"])
            page_size: Number of assets to return per page (default: 50, max: 1000)
        
        Returns:
            List of assets in the specified GCP project
        """
        try:
            try:
                from google.cloud import asset_v1
            except ImportError:
                return "Error: The Google Cloud Asset Inventory library is not installed. Please install it with 'pip install google-cloud-asset'."
            
            # Initialize the Asset client
            client = asset_v1.AssetServiceClient()
            
            # Format the parent resource
            parent = f"projects/{project_id}"
            
            # Create the request
            request = asset_v1.ListAssetsRequest(
                parent=parent,
                content_type=asset_v1.ContentType.RESOURCE,
                page_size=min(page_size, 1000)  # API limit is 1000
            )
            
            # Add asset types filter if provided
            if asset_types:
                request.asset_types = asset_types
            
            # List assets
            response = client.list_assets(request=request)
            
            # Format the response
            assets_list = []
            for asset in response:
                asset_type = asset.asset_type
                name = asset.name
                display_name = asset.display_name if hasattr(asset, 'display_name') and asset.display_name else name.split('/')[-1]
                
                # Extract location if available
                location = "global"
                if hasattr(asset.resource, 'location') and asset.resource.location:
                    location = asset.resource.location
                
                assets_list.append(f"- {display_name} ({asset_type})\n  Location: {location}\n  Name: {name}")
            
            if not assets_list:
                filter_msg = f" with types {asset_types}" if asset_types else ""
                return f"No assets found{filter_msg} in project {project_id}."
            
            # Add pagination info if there's a next page token
            pagination_info = ""
            if hasattr(response, 'next_page_token') and response.next_page_token:
                pagination_info = "\n\nMore assets are available. Refine your search or increase page_size to see more."
            
            return f"Assets in GCP Project {project_id}:\n\n" + "\n\n".join(assets_list) + pagination_info
        except Exception as e:
            return f"Error listing assets: {str(e)}"
  • Registration of resource management tools, which includes the 'list_assets' tool, by calling register_tools on the imported module.
    # Register resource management tools
    resource_tools.register_tools(mcp)
  • The register_tools function in the resource_management module that defines and registers the 'list_assets' tool using @mcp.tool() decorator.
    def register_tools(mcp):
        """Register all resource management tools with the MCP server."""
  • Function signature and docstring defining the input schema (parameters) and output type for the 'list_assets' tool.
    def list_assets(project_id: str, asset_types: Optional[List[str]] = None, page_size: int = 50) -> str:
        """
        List assets in a GCP project using Cloud Asset Inventory API.
        
        Args:
            project_id: The ID of the GCP project to list assets for
            asset_types: Optional list of asset types to filter by (e.g., ["compute.googleapis.com/Instance"])
            page_size: Number of assets to return per page (default: 50, max: 1000)
        
        Returns:
            List of assets in the specified GCP project
        """

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.7/5.0
Behavior3/5

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

With no annotations, the description carries the full burden. It mentions using the Cloud Asset Inventory API and lists page_size with a max of 1000, which implies pagination, but it does not disclose permission requirements, potential rate limits, cost implications, or whether all asset types are returned if no filter is provided. The read-only nature is implied by 'List' but not explicitly stated.

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

Conciseness4/5

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

The core description is a single front-loaded sentence, which is good. However, the Args and Returns sections largely duplicate schema information and the Returns line adds little value. It is somewhat over-specified for an experienced user but not excessively verbose.

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

Completeness3/5

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

The tool has no output schema and no annotations, so the description must compensate. It provides parameter details and a basic return type, but it lacks usage guidance, potential side effects, or any caveats about the Cloud Asset Inventory API. This is adequate for a simple list operation but leaves gaps around when to use it and what to expect in terms of data scope.

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

Parameters5/5

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

Although schema description coverage is reported as 0%, the description includes an Args section that thoroughly explains each parameter beyond the schema. For project_id it defines the purpose, for asset_types it gives an example and notes it's a filter, and for page_size it specifies default and max values. This significantly adds meaning to the raw schema.

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

Purpose5/5

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

The description starts with 'List assets in a GCP project using Cloud Asset Inventory API', which uses a specific verb (list) and resource (assets via Cloud Asset Inventory). This distinguishes it from sibling tools like list_compute_instances or list_storage_buckets, which target specific resource types.

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?

There is no guidance on when to use this tool versus alternatives. It does not mention exclusions or specify that this is the broad asset discovery tool while other list tools are for specific resource types. The description simply states what it does without providing decision criteria.

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