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
        """

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.5/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions default behaviors for destination_blob_name and content_type, and states a return value, but it does not disclose whether existing blobs are overwritten, required permissions, or what the 'Result' actually looks like. This is a significant gap for a mutating operation.

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 description is structured as a Python docstring with a clear purpose sentence followed by Args and Returns sections. It is concise and front-loaded, avoiding unnecessary filler, though the Args list could be more compact.

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 5 parameters, no annotations, and no output schema, the description should provide more complete context. It lacks crucial details about overwrite semantics, error behavior, prerequisites, and the exact shape of the return value. This leaves the agent with ambiguity when invoking the tool.

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%, but the description explains every parameter's purpose and provides default behavior for destination_blob_name and content_type. This adds meaningful context beyond the schema, though it could provide more details on valid formats or constraints.

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 clearly states 'Upload a file to a Cloud Storage bucket,' which is a specific verb-resource pair. It distinguishes itself from sibling tools like download_object, delete_object, and list_objects by focusing solely on the upload action.

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

Usage Guidelines3/5

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

The description implies when to use the tool (when uploading files to GCS) but does not explicitly mention alternatives or exclusions. No guidance is given on prerequisites like bucket existence or permissions, or when to choose this over other object operations.

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