Skip to main content
Glama
ZatesloFL

Google Workspace MCP Server

by ZatesloFL

check_drive_file_public_access

Verify public link sharing status of a specific file in Google Drive by providing the user's email and file name. Ensures file access security and compliance.

Instructions

Searches for a file by name and checks if it has public link sharing enabled.

Args: user_google_email (str): The user's Google email address. Required. file_name (str): The name of the file to check.

Returns: str: Information about the file's sharing status and whether it can be used in Google Docs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_nameYes
user_google_emailYes

Implementation Reference

  • The main asynchronous handler function that executes the tool logic: searches Google Drive for a file matching the given name, retrieves its permissions, checks for public 'anyone with the link' access, and returns a formatted report including embeddable image URL if public.
    async def check_drive_file_public_access(
        service,
        user_google_email: str,
        file_name: str,
    ) -> str:
        """
        Searches for a file by name and checks if it has public link sharing enabled.
        
        Args:
            user_google_email (str): The user's Google email address. Required.
            file_name (str): The name of the file to check.
        
        Returns:
            str: Information about the file's sharing status and whether it can be used in Google Docs.
        """
        logger.info(f"[check_drive_file_public_access] Searching for {file_name}")
        
        # Search for the file
        escaped_name = file_name.replace("'", "\\'")
        query = f"name = '{escaped_name}'"
        
        list_params = {
            "q": query,
            "pageSize": 10,
            "fields": "files(id, name, mimeType, webViewLink)",
            "supportsAllDrives": True,
            "includeItemsFromAllDrives": True,
        }
        
        results = await asyncio.to_thread(
            service.files().list(**list_params).execute
        )
        
        files = results.get('files', [])
        if not files:
            return f"No file found with name '{file_name}'"
        
        if len(files) > 1:
            output_parts = [f"Found {len(files)} files with name '{file_name}':"]
            for f in files:
                output_parts.append(f"  - {f['name']} (ID: {f['id']})")
            output_parts.append("\nChecking the first file...")
            output_parts.append("")
        else:
            output_parts = []
        
        # Check permissions for the first file
        file_id = files[0]['id']
        
        # Get detailed permissions
        file_metadata = await asyncio.to_thread(
            service.files().get(
                fileId=file_id,
                fields="id, name, mimeType, permissions, webViewLink, webContentLink, shared",
                supportsAllDrives=True
            ).execute
        )
        
        permissions = file_metadata.get('permissions', [])
        from gdrive.drive_helpers import check_public_link_permission, get_drive_image_url
        has_public_link = check_public_link_permission(permissions)
        
        output_parts.extend([
            f"File: {file_metadata['name']}",
            f"ID: {file_id}",
            f"Type: {file_metadata['mimeType']}",
            f"Shared: {file_metadata.get('shared', False)}",
            ""
        ])
        
        if has_public_link:
            output_parts.extend([
                "✅ PUBLIC ACCESS ENABLED - This file can be inserted into Google Docs",
                f"Use with insert_doc_image_url: {get_drive_image_url(file_id)}"
            ])
        else:
            output_parts.extend([
                "❌ NO PUBLIC ACCESS - Cannot insert into Google Docs",
                "Fix: Drive → Share → 'Anyone with the link' → 'Viewer'"
            ])
        
        return "\n".join(output_parts)
  • Registers the tool with the MCP server using @server.tool(), applies HTTP error handling decorator, and requires Google Drive read authentication.
    @server.tool()
    @handle_http_errors("check_drive_file_public_access", is_read_only=True, service_type="drive")
    @require_google_service("drive", "drive_read")
  • Utility function called by the handler to determine if the file has public 'anyone with the link' permission (reader, writer, or commenter role).
    def check_public_link_permission(permissions: List[Dict[str, Any]]) -> bool:
        """
        Check if file has 'anyone with the link' permission.
        
        Args:
            permissions: List of permission objects from Google Drive API
            
        Returns:
            bool: True if file has public link sharing enabled
        """
        return any(
            p.get('type') == 'anyone' and p.get('role') in ['reader', 'writer', 'commenter']
            for p in permissions
        )
  • Utility function called by the handler to generate the public embed URL for Drive images when access is confirmed.
    def get_drive_image_url(file_id: str) -> str:
        """
        Get the correct Drive URL format for publicly shared images.
        
        Args:
            file_id: Google Drive file ID
            
        Returns:
            str: URL for embedding Drive images
        """
        return f"https://drive.google.com/uc?export=view&id={file_id}"
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