Skip to main content
Glama
ZatesloFL

Google Workspace MCP Server

by ZatesloFL

get_drive_file_permissions

Retrieve detailed sharing permissions and metadata for a Google Drive file using the user's email and file ID to manage access and ensure data security.

Instructions

Gets detailed metadata about a Google Drive file including sharing permissions.

Args: user_google_email (str): The user's Google email address. Required. file_id (str): The ID of the file to check permissions for.

Returns: str: Detailed file metadata including sharing status and URLs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_idYes
user_google_emailYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Registers the get_drive_file_permissions tool with the MCP server using decorators for tool registration, HTTP error handling, and Google Drive service authentication.
    @server.tool()
    @handle_http_errors("get_drive_file_permissions", is_read_only=True, service_type="drive")
    @require_google_service("drive", "drive_read")
  • Core implementation of the get_drive_file_permissions tool. Fetches detailed file metadata and permissions from Google Drive API, formats sharing information, lists permissions, provides URLs, and checks for public link access.
    async def get_drive_file_permissions(
        service,
        user_google_email: str,
        file_id: str,
    ) -> str:
        """
        Gets detailed metadata about a Google Drive file including sharing permissions.
        
        Args:
            user_google_email (str): The user's Google email address. Required.
            file_id (str): The ID of the file to check permissions for.
        
        Returns:
            str: Detailed file metadata including sharing status and URLs.
        """
        logger.info(f"[get_drive_file_permissions] Checking file {file_id} for {user_google_email}")
        
        try:
            # Get comprehensive file metadata including permissions
            file_metadata = await asyncio.to_thread(
                service.files().get(
                    fileId=file_id,
                    fields="id, name, mimeType, size, modifiedTime, owners, permissions, "
                           "webViewLink, webContentLink, shared, sharingUser, viewersCanCopyContent",
                    supportsAllDrives=True
                ).execute
            )
            
            # Format the response
            output_parts = [
                f"File: {file_metadata.get('name', 'Unknown')}",
                f"ID: {file_id}",
                f"Type: {file_metadata.get('mimeType', 'Unknown')}",
                f"Size: {file_metadata.get('size', 'N/A')} bytes",
                f"Modified: {file_metadata.get('modifiedTime', 'N/A')}",
                "",
                "Sharing Status:",
                f"  Shared: {file_metadata.get('shared', False)}",
            ]
            
            # Add sharing user if available
            sharing_user = file_metadata.get('sharingUser')
            if sharing_user:
                output_parts.append(f"  Shared by: {sharing_user.get('displayName', 'Unknown')} ({sharing_user.get('emailAddress', 'Unknown')})")
            
            # Process permissions
            permissions = file_metadata.get('permissions', [])
            if permissions:
                output_parts.append(f"  Number of permissions: {len(permissions)}")
                output_parts.append("  Permissions:")
                for perm in permissions:
                    perm_type = perm.get('type', 'unknown')
                    role = perm.get('role', 'unknown')
                    
                    if perm_type == 'anyone':
                        output_parts.append(f"    - Anyone with the link ({role})")
                    elif perm_type == 'user':
                        email = perm.get('emailAddress', 'unknown')
                        output_parts.append(f"    - User: {email} ({role})")
                    elif perm_type == 'domain':
                        domain = perm.get('domain', 'unknown')
                        output_parts.append(f"    - Domain: {domain} ({role})")
                    elif perm_type == 'group':
                        email = perm.get('emailAddress', 'unknown')
                        output_parts.append(f"    - Group: {email} ({role})")
                    else:
                        output_parts.append(f"    - {perm_type} ({role})")
            else:
                output_parts.append("  No additional permissions (private file)")
            
            # Add URLs
            output_parts.extend([
                "",
                "URLs:",
                f"  View Link: {file_metadata.get('webViewLink', 'N/A')}",
            ])
            
            # webContentLink is only available for files that can be downloaded
            web_content_link = file_metadata.get('webContentLink')
            if web_content_link:
                output_parts.append(f"  Direct Download Link: {web_content_link}")
            
            # Check if file has "anyone with link" permission
            from gdrive.drive_helpers import check_public_link_permission
            has_public_link = check_public_link_permission(permissions)
            
            if has_public_link:
                output_parts.extend([
                    "",
                    "✅ This file is shared with 'Anyone with the link' - it can be inserted into Google Docs"
                ])
            else:
                output_parts.extend([
                    "",
                    "❌ This file is NOT shared with 'Anyone with the link' - it cannot be inserted into Google Docs",
                    "   To fix: Right-click the file in Google Drive → Share → Anyone with the link → Viewer"
                ])
            
            return "\n".join(output_parts)
            
        except Exception as e:
            logger.error(f"Error getting file permissions: {e}")
            return f"Error getting file permissions: {e}"
  • Supporting helper function called by the handler to check if the Drive file has 'anyone with the link' permission enabled.
    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
        )
Behavior3/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 of behavioral disclosure. It indicates this is a read operation ('Gets'), which implies it's non-destructive, but doesn't specify authentication requirements, rate limits, error conditions, or what 'detailed metadata' entails beyond permissions. The description adds some context (it returns sharing status and URLs) but lacks comprehensive behavioral details for a tool with no annotation support.

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 and appropriately sized. It starts with a clear purpose statement, followed by an 'Args' section that explains parameters concisely, and a 'Returns' section that summarizes the output. There's no wasted text, and information is front-loaded, though the bullet-point style is slightly less efficient than a single flowing paragraph.

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 tool's moderate complexity (2 parameters, no annotations, but has an output schema), the description is reasonably complete. It explains what the tool does, the parameters, and the return value. The presence of an output schema means the description doesn't need to detail return values extensively. However, it could improve by addressing behavioral aspects like authentication or error handling, given the lack of annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, meaning parameters are undocumented in the schema. The description adds value by explaining that 'user_google_email' is 'The user's Google email address' and 'file_id' is 'The ID of the file to check permissions for', which clarifies their roles. However, it doesn't provide format details (e.g., email validation, file ID structure) or examples, leaving some ambiguity. With 2 parameters and no schema documentation, this is adequate but not thorough.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Gets detailed metadata about a Google Drive file including sharing permissions.' It specifies the verb ('Gets'), resource ('Google Drive file'), and scope ('including sharing permissions'). However, it doesn't explicitly differentiate from sibling tools like 'check_drive_file_public_access' or 'get_drive_file_content', which is why it doesn't earn a 5.

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. It doesn't mention sibling tools like 'check_drive_file_public_access' (which might check public access specifically) or 'get_drive_file_content' (which retrieves file content rather than permissions), nor does it specify prerequisites or exclusions. This leaves the agent with minimal context for 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