Skip to main content
Glama
ZatesloFL

Google Workspace MCP Server

by ZatesloFL

create_drive_file

Create and store new files in Google Drive or shared drives with specified content or by fetching from a URL. Requires user email, file name, and optional folder ID, MIME type, or content source.

Instructions

Creates a new file in Google Drive, supporting creation within shared drives. Accepts either direct content or a fileUrl to fetch the content from.

Args: user_google_email (str): The user's Google email address. Required. file_name (str): The name for the new file. content (Optional[str]): If provided, the content to write to the file. folder_id (str): The ID of the parent folder. Defaults to 'root'. For shared drives, this must be a folder ID within the shared drive. mime_type (str): The MIME type of the file. Defaults to 'text/plain'. fileUrl (Optional[str]): If provided, fetches the file content from this URL.

Returns: str: Confirmation message of the successful file creation with file link.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentNo
fileUrlNo
file_nameYes
folder_idNoroot
mime_typeNotext/plain
user_google_emailYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function implementing the create_drive_file tool. It creates a new file in the user's Google Drive (including shared drives) either from provided content string or by fetching from a URL. Includes decorators for MCP server registration (@server.tool()), HTTP error handling, and Google service authentication.
    @server.tool()
    @handle_http_errors("create_drive_file", service_type="drive")
    @require_google_service("drive", "drive_file")
    async def create_drive_file(
        service,
        user_google_email: str,
        file_name: str,
        content: Optional[str] = None,  # Now explicitly Optional
        folder_id: str = 'root',
        mime_type: str = 'text/plain',
        fileUrl: Optional[str] = None,  # Now explicitly Optional
    ) -> str:
        """
        Creates a new file in Google Drive, supporting creation within shared drives.
        Accepts either direct content or a fileUrl to fetch the content from.
    
        Args:
            user_google_email (str): The user's Google email address. Required.
            file_name (str): The name for the new file.
            content (Optional[str]): If provided, the content to write to the file.
            folder_id (str): The ID of the parent folder. Defaults to 'root'. For shared drives, this must be a folder ID within the shared drive.
            mime_type (str): The MIME type of the file. Defaults to 'text/plain'.
            fileUrl (Optional[str]): If provided, fetches the file content from this URL.
    
        Returns:
            str: Confirmation message of the successful file creation with file link.
        """
        logger.info(f"[create_drive_file] Invoked. Email: '{user_google_email}', File Name: {file_name}, Folder ID: {folder_id}, fileUrl: {fileUrl}")
    
        if not content and not fileUrl:
            raise Exception("You must provide either 'content' or 'fileUrl'.")
    
        file_data = None
        # Prefer fileUrl if both are provided
        if fileUrl:
            logger.info(f"[create_drive_file] Fetching file from URL: {fileUrl}")
            async with httpx.AsyncClient() as client:
                resp = await client.get(fileUrl)
                if resp.status_code != 200:
                    raise Exception(f"Failed to fetch file from URL: {fileUrl} (status {resp.status_code})")
                file_data = await resp.aread()
                # Try to get MIME type from Content-Type header
                content_type = resp.headers.get("Content-Type")
                if content_type and content_type != "application/octet-stream":
                    mime_type = content_type
                    logger.info(f"[create_drive_file] Using MIME type from Content-Type header: {mime_type}")
        elif content:
            file_data = content.encode('utf-8')
    
        file_metadata = {
            'name': file_name,
            'parents': [folder_id],
            'mimeType': mime_type
        }
        media = io.BytesIO(file_data)
    
        created_file = await asyncio.to_thread(
            service.files().create(
                body=file_metadata,
                media_body=MediaIoBaseUpload(media, mimetype=mime_type, resumable=True),
                fields='id, name, webViewLink',
                supportsAllDrives=True
            ).execute
        )
    
        link = created_file.get('webViewLink', 'No link available')
        confirmation_message = f"Successfully created file '{created_file.get('name', file_name)}' (ID: {created_file.get('id', 'N/A')}) in folder '{folder_id}' for {user_google_email}. Link: {link}"
        logger.info(f"Successfully created file. Link: {link}")
        return confirmation_message
  • MCP tool registration decorator @server.tool() applied to the create_drive_file handler.
    @server.tool()
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the creation behavior and mentions shared drive support, but doesn't cover important aspects like required permissions, rate limits, error conditions, or whether the operation is idempotent. For a write operation with zero annotation coverage, this leaves significant behavioral gaps.

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 well-structured with a clear opening statement followed by organized Args and Returns sections. While efficient, the parameter explanations could be slightly more concise, and the opening sentence could be more front-loaded with the core purpose before diving into details.

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

Completeness4/5

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

Given the complexity of a 6-parameter file creation tool with no annotations, the description does well by explaining all parameters and mentioning shared drive support. However, it lacks behavioral context about permissions, errors, and limitations. The presence of an output schema reduces the need to explain return values, but more operational guidance would be beneficial.

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?

With 0% schema description coverage, the description fully compensates by explaining all 6 parameters in detail. It clarifies the purpose of user_google_email, distinguishes between content and fileUrl options, explains folder_id defaults and shared drive requirements, and specifies mime_type defaults. This adds substantial meaning beyond the bare 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 clearly states the specific action ('Creates a new file'), resource ('in Google Drive'), and scope ('supporting creation within shared drives'), distinguishing it from sibling tools like create_doc or create_spreadsheet that create specific file types. It precisely defines what the tool does beyond just restating the name.

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 usage context by mentioning shared drives and the content/fileUrl options, but doesn't explicitly state when to use this tool versus alternatives like create_doc for Google Docs or create_spreadsheet for Sheets. No explicit exclusions or prerequisites are provided, leaving some ambiguity about tool selection.

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

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/ZatesloFL/google_workspace_mcp'

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