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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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}"
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks critical behavioral details. It doesn't disclose whether this requires specific permissions, how it handles multiple matching files, error conditions, or rate limits. The description mentions the return format but doesn't explain the search behavior or limitations.

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 clear sections for purpose, arguments, and returns. It's appropriately sized with no redundant information, though the return statement could be more specific about the exact format of the information returned.

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

Completeness3/5

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

For a tool with 2 parameters, no annotations, and an output schema, the description adequately covers the basic purpose and parameters but lacks behavioral context. The presence of an output schema means the description doesn't need to detail return values, but it should provide more operational guidance given the mutation-adjacent nature of checking sharing status.

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?

The description explicitly lists both parameters with their purposes in the Args section, adding meaningful context beyond the schema which has 0% description coverage. It clarifies that 'user_google_email' is required and identifies the file to check, though it doesn't specify format constraints or search behavior details.

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 ('searches for a file by name and checks if it has public link sharing enabled'), identifies the resource (file), and distinguishes it from sibling tools like 'search_drive_files' or 'get_drive_file_permissions' by focusing on public access checking rather than general search or permission listing.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'get_drive_file_permissions' or 'search_drive_files'. It doesn't mention prerequisites, exclusions, or specific scenarios where this tool is preferred over others for checking public access.

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