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
        """
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 mentions pagination ('page_size') and filtering ('asset_types'), which adds some behavioral context, but lacks critical details like authentication requirements, rate limits, error handling, or whether it's read-only (implied by 'List' but not explicit). This is inadequate for a tool with no annotation coverage.

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 well-structured and front-loaded with the core purpose, followed by clear parameter explanations in a standard 'Args'/'Returns' format. Every sentence adds value without redundancy, making it efficient and easy to parse.

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?

Given no annotations and no output schema, the description covers parameters well but lacks behavioral context (e.g., auth, errors) and output details (e.g., asset structure). It's minimally adequate for a listing tool but leaves gaps that could hinder agent usage in complex scenarios.

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?

Schema description coverage is 0%, so the description must compensate. It effectively explains all three parameters: 'project_id' (GCP project ID), 'asset_types' (optional filter with example), and 'page_size' (default and max values). This adds significant meaning beyond the bare schema, though it could provide more detail on asset type formats or pagination behavior.

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 assets') and resource ('in a GCP project using Cloud Asset Inventory API'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'list_compute_instances' or 'list_gcp_projects', which also list resources but with different scopes or APIs.

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?

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools that list specific resources (e.g., 'list_compute_instances', 'list_storage_buckets'), there's no indication that this tool is for broader asset inventory across multiple resource types, leaving the agent to infer usage context.

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

Related 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/henihaddad/gcp-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server