Skip to main content
Glama

list_storage_buckets

Retrieve a list of Cloud Storage buckets within a specified GCP project by providing the project ID. This tool helps manage and organize storage resources efficiently.

Instructions

    List Cloud Storage buckets in a GCP project.
    
    Args:
        project_id: The ID of the GCP project to list buckets for
    
    Returns:
        List of Cloud Storage buckets in the specified GCP project
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes

Implementation Reference

  • The handler function for the 'list_storage_buckets' tool, decorated with @mcp.tool(), which lists GCP Cloud Storage buckets for a given project using the google.cloud.storage client.
        @mcp.tool()
        def list_storage_buckets(project_id: str) -> str:
            """
            List Cloud Storage buckets in a GCP project.
            
            Args:
                project_id: The ID of the GCP project to list buckets for
            
            Returns:
                List of Cloud Storage buckets in the specified GCP project
            """
            try:
                from google.cloud import storage
                
                # Initialize the Storage client
                client = storage.Client(project=project_id)
                
                # List buckets
                buckets = client.list_buckets()
                
                # Format the response
                buckets_list = []
                for bucket in buckets:
                    location = bucket.location or "Unknown"
                    storage_class = bucket.storage_class or "Unknown"
                    created = bucket.time_created.strftime("%Y-%m-%d %H:%M:%S UTC") if bucket.time_created else "Unknown"
                    buckets_list.append(f"- {bucket.name} (Location: {location}, Class: {storage_class}, Created: {created})")
                
                if not buckets_list:
                    return f"No Cloud Storage buckets found in project {project_id}."
                
                buckets_str = "\n".join(buckets_list)
                
                return f"""
    Cloud Storage Buckets in GCP Project {project_id}:
    {buckets_str}
    """
            except Exception as e:
                return f"Error listing Cloud Storage buckets: {str(e)}"
  • Registration call for storage tools module, which includes the list_storage_buckets tool, invoked within the main register_tools function.
    # Register storage tools
    storage_tools.register_tools(mcp)
  • The register_tools function in the storage module where the list_storage_buckets tool is defined and registered via decorator when called.
    def register_tools(mcp):
        """Register all storage tools with the MCP server."""

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