Skip to main content
Glama

upload_object

Transfer files from local storage to a Google Cloud Storage bucket using specified project and bucket details. Automates file uploads with customizable destination names and content types for efficient cloud storage management.

Instructions

    Upload a file to a Cloud Storage bucket.
    
    Args:
        project_id: The ID of the GCP project
        bucket_name: The name of the bucket to upload to
        source_file_path: The local file path to upload
        destination_blob_name: The name to give the file in GCS (default: filename from source)
        content_type: The content type of the file (default: auto-detect)
    
    Returns:
        Result of the upload operation
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_nameYes
content_typeNo
destination_blob_nameNo
project_idYes
source_file_pathYes

Implementation Reference

  • The core handler function for the 'upload_object' tool, which uploads a local file to a GCP Cloud Storage bucket using the Google Cloud Storage client.
        @mcp.tool()
        def upload_object(project_id: str, bucket_name: str, source_file_path: str, destination_blob_name: Optional[str] = None, content_type: Optional[str] = None) -> str:
            """
            Upload a file to a Cloud Storage bucket.
            
            Args:
                project_id: The ID of the GCP project
                bucket_name: The name of the bucket to upload to
                source_file_path: The local file path to upload
                destination_blob_name: The name to give the file in GCS (default: filename from source)
                content_type: The content type of the file (default: auto-detect)
            
            Returns:
                Result of the upload operation
            """
            try:
                import os
                from google.cloud import storage
                
                # Initialize the Storage client
                client = storage.Client(project=project_id)
                
                # Get the bucket
                bucket = client.get_bucket(bucket_name)
                
                # If no destination name is provided, use the source filename
                if not destination_blob_name:
                    destination_blob_name = os.path.basename(source_file_path)
                
                # Create a blob object
                blob = bucket.blob(destination_blob_name)
                
                # Upload the file
                blob.upload_from_filename(source_file_path, content_type=content_type)
                
                return f"""
    File successfully uploaded:
    - Source: {source_file_path}
    - Destination: gs://{bucket_name}/{destination_blob_name}
    - Size: {blob.size / (1024 * 1024):.2f} MB
    - Content-Type: {blob.content_type}
    """
            except Exception as e:
                return f"Error uploading file: {str(e)}"
  • Registers all storage tools, including 'upload_object', by invoking the module's register_tools function on the MCP server instance.
    # Register storage tools
    storage_tools.register_tools(mcp)
  • Imports the storage tools module containing the 'upload_object' tool implementation and registration logic.
    from .gcp_modules.storage import tools as storage_tools
  • The function signature and docstring defining the input schema (parameters) and output description for the 'upload_object' tool.
    def upload_object(project_id: str, bucket_name: str, source_file_path: str, destination_blob_name: Optional[str] = None, content_type: Optional[str] = None) -> str:
        """
        Upload a file to a Cloud Storage bucket.
        
        Args:
            project_id: The ID of the GCP project
            bucket_name: The name of the bucket to upload to
            source_file_path: The local file path to upload
            destination_blob_name: The name to give the file in GCS (default: filename from source)
            content_type: The content type of the file (default: auto-detect)
        
        Returns:
            Result of the upload operation
        """

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