UNPKG

@coretext-ai/qa-gsuite-f47ac10b-58cc-4372-a567-0e02b2c3d479

Version:

MCP server with GSuite (Contacts, Drive, Gmail, Calendar) integration

1,272 lines 58.5 kB
import { Logger } from '../services/logger.js';
export class GoogleDriveTools {
    constructor(client) {
        this.initialized = false;
        this.client = client;
        // Get logger from client if available, otherwise create fallback
        this.logger = client.logger || new Logger({
            logLevel: 'ERROR',
            component: 'tools',
            enableConsole: true,
            enableShipping: false,
            serverName: ''
        });
    }
    async ensureInitialized() {
        if (!this.initialized) {
            // Log tools initialization now that client is ready
            this.logger.info('TOOLS_INIT', 'Tools instance initialization started', {
                integration: 'google-drive',
                isOAuth: true
            });
            this.logger.info('CLIENT_INITIALIZATION', 'Starting client initialization', {
                isOAuth: true
            });
            await this.client.initialize();
            this.initialized = true;
            this.logger.info('CLIENT_INITIALIZATION', 'Client initialization completed', {
                initialized: this.initialized
            });
        }
    }
    getToolDefinitions() {
        return [
            {
                name: 'google-drive_upload_file_simple',
                description: 'Simple upload for files ≤5MB. Upload file content directly',
                inputSchema: {
                    type: 'object',
                    properties: {
                        uploadType: {
                            type: 'string',
                            description: 'Must be 'media' for simple upload'
                        },
                        name: {
                            type: 'string',
                            description: 'File name (can be specified in metadata or derived from content)'
                        },
                        parents: {
                            type: 'string',
                            description: 'Comma-separated list of parent folder IDs'
                        },
                        fileContent: {
                            type: 'string',
                            description: 'Raw file content to upload'
                        },
                    },
                    required: ['uploadType', 'fileContent']
                }
            },
            {
                name: 'google-drive_upload_file_multipart',
                description: 'Multipart upload for files with metadata. Combines metadata and content in single request',
                inputSchema: {
                    type: 'object',
                    properties: {
                        uploadType: {
                            type: 'string',
                            description: 'Must be 'multipart' for multipart upload'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return (e.g., 'id,name,mimeType,size,parents')'
                        },
                        metadata: {
                            type: 'object',
                            description: 'File metadata including name, parents, mimeType, description, etc.'
                        },
                        fileContent: {
                            type: 'string',
                            description: 'Raw file content to upload'
                        },
                    },
                    required: ['uploadType', 'metadata', 'fileContent']
                }
            },
            {
                name: 'google-drive_upload_file_resumable',
                description: 'Initiate resumable upload for large files with progress tracking',
                inputSchema: {
                    type: 'object',
                    properties: {
                        uploadType: {
                            type: 'string',
                            description: 'Must be 'resumable' for resumable upload'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return'
                        },
                        metadata: {
                            type: 'object',
                            description: 'File metadata for the upload session'
                        },
                    },
                    required: ['uploadType', 'metadata']
                }
            },
            {
                name: 'google-drive_get_file',
                description: 'Get file metadata by ID',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to retrieve'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return (e.g., 'id,name,mimeType,size,parents,modifiedTime,createdTime,webViewLink')'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                        acknowledgeAbuse: {
                            type: 'boolean',
                            description: 'Whether to acknowledge virus scan warnings'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_download_file',
                description: 'Download file content or export Google Workspace documents',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to download'
                        },
                        alt: {
                            type: 'string',
                            description: 'Response format: 'media' for file content'
                        },
                        acknowledgeAbuse: {
                            type: 'boolean',
                            description: 'Whether to acknowledge virus scan warnings'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                    },
                    required: ['fileId', 'alt',]
                }
            },
            {
                name: 'google-drive_export_file',
                description: 'Export Google Workspace document to specified format',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the Google Workspace file to export'
                        },
                        mimeType: {
                            type: 'string',
                            description: 'MIME type to export to (e.g., 'application/pdf', 'text/plain', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')'
                        },
                    },
                    required: ['fileId', 'mimeType']
                }
            },
            {
                name: 'google-drive_update_file',
                description: 'Update file metadata',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to update'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return in response'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                        name: {
                            type: 'string',
                            description: 'New name for the file'
                        },
                        description: {
                            type: 'string',
                            description: 'New description for the file'
                        },
                        parents: {
                            type: 'object',
                            description: 'Array of parent folder IDs'
                        },
                        starred: {
                            type: 'boolean',
                            description: 'Whether to star the file'
                        },
                        trashed: {
                            type: 'boolean',
                            description: 'Whether to move the file to trash'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_update_file_content',
                description: 'Update file content using multipart upload',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to update'
                        },
                        uploadType: {
                            type: 'string',
                            description: 'Must be 'multipart' for content update'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return'
                        },
                        metadata: {
                            type: 'object',
                            description: 'Optional metadata updates'
                        },
                        fileContent: {
                            type: 'string',
                            description: 'New file content'
                        },
                    },
                    required: ['fileId', 'uploadType', 'fileContent']
                }
            },
            {
                name: 'google-drive_delete_file',
                description: 'Permanently delete a file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to delete'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_copy_file',
                description: 'Create a copy of an existing file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to copy'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                        name: {
                            type: 'string',
                            description: 'Name for the copied file'
                        },
                        parents: {
                            type: 'object',
                            description: 'Array of parent folder IDs for the copy'
                        },
                        description: {
                            type: 'string',
                            description: 'Description for the copied file'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_create_folder',
                description: 'Create a new folder',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return (e.g., 'id,name,parents,mimeType')'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                        name: {
                            type: 'string',
                            description: 'Name of the new folder'
                        },
                        mimeType: {
                            type: 'string',
                            description: 'Must be 'application/vnd.google-apps.folder' for folders'
                        },
                        parents: {
                            type: 'object',
                            description: 'Array of parent folder IDs (default: root folder)'
                        },
                        description: {
                            type: 'string',
                            description: 'Description of the folder'
                        },
                        folderColorRgb: {
                            type: 'string',
                            description: 'Folder color in RGB hex format (e.g., '#ff0000')'
                        },
                    },
                    required: ['name', 'mimeType',]
                }
            },
            {
                name: 'google-drive_move_file',
                description: 'Move a file to different parent folders',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to move'
                        },
                        addParents: {
                            type: 'string',
                            description: 'Comma-separated list of parent folder IDs to add'
                        },
                        removeParents: {
                            type: 'string',
                            description: 'Comma-separated list of parent folder IDs to remove'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_get_folder_contents',
                description: 'List files and folders within a specific folder',
                inputSchema: {
                    type: 'object',
                    properties: {
                        q: {
                            type: 'string',
                            description: 'Query to filter by parent folder (e.g., "'folderId' in parents and trashed=false")'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of files to return (default 100, max 1000)'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return for each file'
                        },
                        orderBy: {
                            type: 'string',
                            description: 'Sort order (e.g., 'name', 'folder,name', 'modifiedTime desc')'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                        includeItemsFromAllDrives: {
                            type: 'boolean',
                            description: 'Whether to include files from all drives'
                        },
                    },
                    required: ['q',]
                }
            },
            {
                name: 'google-drive_get_folder_tree',
                description: 'Get folder hierarchy and structure',
                inputSchema: {
                    type: 'object',
                    properties: {
                        q: {
                            type: 'string',
                            description: 'Query to get folders (e.g., "mimeType='application/vnd.google-apps.folder' and trashed=false")'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of folders to return'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return (recommend: 'files(id,name,parents,mimeType)')'
                        },
                        orderBy: {
                            type: 'string',
                            description: 'Sort order for folders'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                    },
                    required: ['q',]
                }
            },
            {
                name: 'google-drive_list_files',
                description: 'List files in Google Drive with optional search query and filtering',
                inputSchema: {
                    type: 'object',
                    properties: {
                        q: {
                            type: 'string',
                            description: 'Search query using Drive query syntax (e.g., 'name contains "test"', 'mimeType="application/pdf"', 'parents in "folderId"')'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of files to return (default 100, max 1000)'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return (e.g., 'files(id,name,mimeType,size,modifiedTime,parents,webViewLink)')'
                        },
                        orderBy: {
                            type: 'string',
                            description: 'Sort order: 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', 'viewedByMeTime''
                        },
                        spaces: {
                            type: 'string',
                            description: 'Comma-separated list of spaces to query: 'drive', 'appDataFolder', 'photos''
                        },
                        corpora: {
                            type: 'string',
                            description: 'Corpora to search: 'user' (default), 'domain', 'drive', 'allDrives''
                        },
                        driveId: {
                            type: 'string',
                            description: 'ID of the shared drive to search (if corpora is 'drive')'
                        },
                        includeItemsFromAllDrives: {
                            type: 'boolean',
                            description: 'Whether to include files from all drives'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support files in shared drives'
                        },
                        includePermissionsForView: {
                            type: 'string',
                            description: 'Specifies which additional view's permissions to include ('published')'
                        },
                        includeLabels: {
                            type: 'string',
                            description: 'Comma-separated list of label IDs to include'
                        },
                    },
                    required: []
                }
            },
            {
                name: 'google-drive_search_files',
                description: 'Advanced file search with complex query syntax',
                inputSchema: {
                    type: 'object',
                    properties: {
                        q: {
                            type: 'string',
                            description: 'Advanced search query (e.g., 'fullText contains "keyword" and mimeType contains "google-apps"')'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of results to return'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return in search results'
                        },
                        orderBy: {
                            type: 'string',
                            description: 'Sort order for search results'
                        },
                        includeItemsFromAllDrives: {
                            type: 'boolean',
                            description: 'Whether to include files from all drives'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                    },
                    required: ['q',]
                }
            },
            {
                name: 'google-drive_list_file_revisions',
                description: 'List revisions of a specific file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to get revisions for'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of revisions to return (default 20, max 1000)'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_get_file_revision',
                description: 'Get a specific revision of a file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        revisionId: {
                            type: 'string',
                            description: 'ID of the revision'
                        },
                        fields: {
                            type: 'string',
                            description: 'Comma-separated list of fields to return'
                        },
                        acknowledgeAbuse: {
                            type: 'boolean',
                            description: 'Whether to acknowledge virus scan warnings'
                        },
                    },
                    required: ['fileId', 'revisionId',]
                }
            },
            {
                name: 'google-drive_update_file_revision',
                description: 'Update revision metadata (e.g., set keepForever)',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        revisionId: {
                            type: 'string',
                            description: 'ID of the revision to update'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return in response'
                        },
                        keepForever: {
                            type: 'boolean',
                            description: 'Whether to keep this revision forever'
                        },
                        publishAuto: {
                            type: 'boolean',
                            description: 'Whether to automatically publish this revision'
                        },
                        published: {
                            type: 'boolean',
                            description: 'Whether this revision is published'
                        },
                    },
                    required: ['fileId', 'revisionId',]
                }
            },
            {
                name: 'google-drive_delete_file_revision',
                description: 'Delete a specific revision of a file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        revisionId: {
                            type: 'string',
                            description: 'ID of the revision to delete'
                        },
                    },
                    required: ['fileId', 'revisionId']
                }
            },
            {
                name: 'google-drive_create_permission',
                description: 'Create a permission for a file or folder (sharing)',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file or folder to share'
                        },
                        sendNotificationEmail: {
                            type: 'boolean',
                            description: 'Whether to send notification email (default: true)'
                        },
                        emailMessage: {
                            type: 'string',
                            description: 'Custom message to include in notification email'
                        },
                        transferOwnership: {
                            type: 'boolean',
                            description: 'Whether to transfer ownership (only for role='owner')'
                        },
                        moveToNewOwnersRoot: {
                            type: 'boolean',
                            description: 'Whether to move file to new owner's root folder'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return in response'
                        },
                        role: {
                            type: 'string',
                            description: 'Permission role: 'owner', 'organizer', 'fileOrganizer', 'writer', 'commenter', 'reader''
                        },
                        type: {
                            type: 'string',
                            description: 'Permission type: 'user', 'group', 'domain', 'anyone''
                        },
                        emailAddress: {
                            type: 'string',
                            description: 'Email address for user or group permissions'
                        },
                        domain: {
                            type: 'string',
                            description: 'Domain name for domain permissions'
                        },
                        allowFileDiscovery: {
                            type: 'boolean',
                            description: 'Whether to allow file discovery for 'anyone' or 'domain' types'
                        },
                        expirationTime: {
                            type: 'string',
                            description: 'Expiration time in RFC 3339 format'
                        },
                    },
                    required: ['fileId', 'role', 'type',]
                }
            },
            {
                name: 'google-drive_list_permissions',
                description: 'List permissions for a file or folder',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file or folder'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of permissions to return (default 100)'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return for each permission'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                        useDomainAdminAccess: {
                            type: 'boolean',
                            description: 'Whether to use domain admin access'
                        },
                        includePermissionsForView: {
                            type: 'string',
                            description: 'Specifies which additional view's permissions to include'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_get_permission',
                description: 'Get a specific permission for a file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file or folder'
                        },
                        permissionId: {
                            type: 'string',
                            description: 'ID of the permission to retrieve'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                        useDomainAdminAccess: {
                            type: 'boolean',
                            description: 'Whether to use domain admin access'
                        },
                    },
                    required: ['fileId', 'permissionId',]
                }
            },
            {
                name: 'google-drive_update_permission',
                description: 'Update an existing permission',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file or folder'
                        },
                        permissionId: {
                            type: 'string',
                            description: 'ID of the permission to update'
                        },
                        transferOwnership: {
                            type: 'boolean',
                            description: 'Whether to transfer ownership'
                        },
                        removeExpiration: {
                            type: 'boolean',
                            description: 'Whether to remove expiration time'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return in response'
                        },
                        role: {
                            type: 'string',
                            description: 'New role for the permission'
                        },
                        expirationTime: {
                            type: 'string',
                            description: 'New expiration time in RFC 3339 format'
                        },
                    },
                    required: ['fileId', 'permissionId',]
                }
            },
            {
                name: 'google-drive_delete_permission',
                description: 'Remove a permission from a file or folder',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file or folder'
                        },
                        permissionId: {
                            type: 'string',
                            description: 'ID of the permission to remove'
                        },
                        supportsAllDrives: {
                            type: 'boolean',
                            description: 'Whether to support shared drives'
                        },
                        useDomainAdminAccess: {
                            type: 'boolean',
                            description: 'Whether to use domain admin access'
                        },
                    },
                    required: ['fileId', 'permissionId',]
                }
            },
            {
                name: 'google-drive_create_comment',
                description: 'Create a comment on a file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file to comment on'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return in response'
                        },
                        content: {
                            type: 'string',
                            description: 'Content of the comment'
                        },
                        anchor: {
                            type: 'string',
                            description: 'Anchor for the comment (for specific location in document)'
                        },
                        quotedFileContent: {
                            type: 'object',
                            description: 'Quoted content from the file'
                        },
                    },
                    required: ['fileId', 'content',]
                }
            },
            {
                name: 'google-drive_list_comments',
                description: 'List comments on a file',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        pageSize: {
                            type: 'number',
                            description: 'Maximum number of comments to return (default 20, max 100)'
                        },
                        pageToken: {
                            type: 'string',
                            description: 'Page token for pagination'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return for each comment'
                        },
                        includeDeleted: {
                            type: 'boolean',
                            description: 'Whether to include deleted comments'
                        },
                        startModifiedTime: {
                            type: 'string',
                            description: 'Start time for comments in RFC 3339 format'
                        },
                    },
                    required: ['fileId',]
                }
            },
            {
                name: 'google-drive_get_comment',
                description: 'Get a specific comment',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        commentId: {
                            type: 'string',
                            description: 'ID of the comment'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return'
                        },
                        includeDeleted: {
                            type: 'boolean',
                            description: 'Whether to include deleted comment'
                        },
                    },
                    required: ['fileId', 'commentId',]
                }
            },
            {
                name: 'google-drive_update_comment',
                description: 'Update a comment',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        commentId: {
                            type: 'string',
                            description: 'ID of the comment to update'
                        },
                        fields: {
                            type: 'string',
                            description: 'Fields to return in response'
                        },
                        content: {
                            type: 'string',
                            description: 'New content for the comment'
                        },
                    },
                    required: ['fileId', 'commentId',]
                }
            },
            {
                name: 'google-drive_delete_comment',
                description: 'Delete a comment',
                inputSchema: {
                    type: 'object',
                    properties: {
                        fileId: {
                            type: 'string',
                            description: 'ID of the file'
                        },
                        commentId: {
                            type: 'string',
                            description: 'ID of the comment to delete'
                        },
                    },
                    required: ['fileId', 'commentId']
                }
            }
        ];
    }
    canHandle(toolName) {
        const supportedTools = [
            'google-drive_upload_file_simple',
            'google-drive_upload_file_multipart',
            'google-drive_upload_file_resumable',
            'google-drive_get_file',
            'google-drive_download_file',
            'google-drive_export_file',
            'google-drive_update_file',
            'google-drive_update_file_content',
            'google-drive_delete_file',
            'google-drive_copy_file',
            'google-drive_create_folder',
            'google-drive_move_file',
            'google-drive_get_folder_contents',
            'google-drive_get_folder_tree',
            'google-drive_list_files',
            'google-drive_search_files',
            'google-drive_list_file_revisions',
            'google-drive_get_file_revision',
            'google-drive_update_file_revision',
            'google-drive_delete_file_revision',
            'google-drive_create_permission',
            'google-drive_list_permissions',
            'google-drive_get_permission',
            'google-drive_update_permission',
            'google-drive_delete_permission',
            'google-drive_create_comment',
            'google-drive_list_comments',
            'google-drive_get_comment',
            'google-drive_update_comment',
            'google-drive_delete_comment'
        ];
        return supportedTools.includes(toolName);
    }
    async executeTool(name, args) {
        const startTime = Date.now();
        this.logger.logToolStart(name, args);
        await this.ensureInitialized();
        // Validate tool is supported
        if (!this.canHandle(name)) {
            this.logger.error('TOOL_ERROR', 'Unknown tool requested', {
                tool: name,
                supportedTools: ['google-drive_upload_file_simple', 'google-drive_upload_file_multipart', 'google-drive_upload_file_resumable', 'google-drive_get_file', 'google-drive_download_file', 'google-drive_export_file', 'google-drive_update_file', 'google-drive_update_file_content', 'google-drive_delete_file', 'google-drive_copy_file', 'google-drive_create_folder', 'google-drive_move_file', 'google-drive_get_folder_contents', 'google-drive_get_folder_tree', 'google-drive_list_files', 'google-drive_search_files', 'google-drive_list_file_revisions', 'google-drive_get_file_revision', 'google-drive_update_file_revision', 'google-drive_delete_file_revision', 'google-drive_create_permission', 'google-drive_list_permissions', 'google-drive_get_permission', 'google-drive_update_permission', 'google-drive_delete_permission', 'google-drive_create_comment', 'google-drive_list_comments', 'google-drive_get_comment', 'google-drive_update_comment', 'google-drive_delete_comment']
            });
            throw new Error(`Unknown tool: ${name}`);
        }
        // Validate required parameters
        this.logger.debug('PARAM_VALIDATION', 'Validating tool parameters', {
            tool: name,
            providedArgs: Object.keys(args || {})
        });
        try {
            let result;
            switch (name) {
                case 'google-drive_upload_file_simple':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_upload_file_simple',
                        clientMethod: 'uploadFileSimple'
                    });
                    result = await this.client.uploadFileSimple(args);
                    break;
                case 'google-drive_upload_file_multipart':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_upload_file_multipart',
                        clientMethod: 'uploadFileMultipart'
                    });
                    result = await this.client.uploadFileMultipart(args);
                    break;
                case 'google-drive_upload_file_resumable':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_upload_file_resumable',
                        clientMethod: 'uploadFileResumable'
                    });
                    result = await this.client.uploadFileResumable(args);
                    break;
                case 'google-drive_get_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_get_file',
                        clientMethod: 'getFile'
                    });
                    result = await this.client.getFile(args);
                    break;
                case 'google-drive_download_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_download_file',
                        clientMethod: 'downloadFile'
                    });
                    result = await this.client.downloadFile(args);
                    break;
                case 'google-drive_export_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_export_file',
                        clientMethod: 'exportFile'
                    });
                    result = await this.client.exportFile(args);
                    break;
                case 'google-drive_update_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_update_file',
                        clientMethod: 'updateFile'
                    });
                    result = await this.client.updateFile(args);
                    break;
                case 'google-drive_update_file_content':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_update_file_content',
                        clientMethod: 'updateFileContent'
                    });
                    result = await this.client.updateFileContent(args);
                    break;
                case 'google-drive_delete_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_delete_file',
                        clientMethod: 'deleteFile'
                    });
                    result = await this.client.deleteFile(args);
                    break;
                case 'google-drive_copy_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_copy_file',
                        clientMethod: 'copyFile'
                    });
                    result = await this.client.copyFile(args);
                    break;
                case 'google-drive_create_folder':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_create_folder',
                        clientMethod: 'createFolder'
                    });
                    result = await this.client.createFolder(args);
                    break;
                case 'google-drive_move_file':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_move_file',
                        clientMethod: 'moveFile'
                    });
                    result = await this.client.moveFile(args);
                    break;
                case 'google-drive_get_folder_contents':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_get_folder_contents',
                        clientMethod: 'getFolderContents'
                    });
                    result = await this.client.getFolderContents(args);
                    break;
                case 'google-drive_get_folder_tree':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_get_folder_tree',
                        clientMethod: 'getFolderTree'
                    });
                    result = await this.client.getFolderTree(args);
                    break;
                case 'google-drive_list_files':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_list_files',
                        clientMethod: 'listFiles'
                    });
                    result = await this.client.listFiles(args);
                    break;
                case 'google-drive_search_files':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_search_files',
                        clientMethod: 'searchFiles'
                    });
                    result = await this.client.searchFiles(args);
                    break;
                case 'google-drive_list_file_revisions':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_list_file_revisions',
                        clientMethod: 'listFileRevisions'
                    });
                    result = await this.client.listFileRevisions(args);
                    break;
                case 'google-drive_get_file_revision':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_get_file_revision',
                        clientMethod: 'getFileRevision'
                    });
                    result = await this.client.getFileRevision(args);
                    break;
                case 'google-drive_update_file_revision':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_update_file_revision',
                        clientMethod: 'updateFileRevision'
                    });
                    result = await this.client.updateFileRevision(args);
                    break;
                case 'google-drive_delete_file_revision':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_delete_file_revision',
                        clientMethod: 'deleteFileRevision'
                    });
                    result = await this.client.deleteFileRevision(args);
                    break;
                case 'google-drive_create_permission':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_create_permission',
                        clientMethod: 'createPermission'
                    });
                    result = await this.client.createPermission(args);
                    break;
                case 'google-drive_list_permissions':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_list_permissions',
                        clientMethod: 'listPermissions'
                    });
                    result = await this.client.listPermissions(args);
                    break;
                case 'google-drive_get_permission':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_get_permission',
                        clientMethod: 'getPermission'
                    });
                    result = await this.client.getPermission(args);
                    break;
                case 'google-drive_update_permission':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_update_permission',
                        clientMethod: 'updatePermission'
                    });
                    result = await this.client.updatePermission(args);
                    break;
                case 'google-drive_delete_permission':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_delete_permission',
                        clientMethod: 'deletePermission'
                    });
                    result = await this.client.deletePermission(args);
                    break;
                case 'google-drive_create_comment':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_create_comment',
                        clientMethod: 'createComment'
                    });
                    result = await this.client.createComment(args);
                    break;
                case 'google-drive_list_comments':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_list_comments',
                        clientMethod: 'listComments'
                    });
                    result = await this.client.listComments(args);
                    break;
                case 'google-drive_get_comment':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_get_comment',
                        clientMethod: 'getComment'
                    });
                    result = await this.client.getComment(args);
                    break;
                case 'google-drive_update_comment':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_update_comment',
                        clientMethod: 'updateComment'
                    });
                    result = await this.client.updateComment(args);
                    break;
                case 'google-drive_delete_comment':
                    this.logger.debug('TOOL_EXECUTE', 'Calling client method', {
                        tool: 'google-drive_delete_comment',
                        clientMethod: 'deleteComment'
                    });
                    result = await this.client.deleteComment(args);
                    break;
                default:
                    throw new Error(`Unknown tool: ${name}`);
            }
            const duration = Date.now() - startTime;
            this.logger.logToolSuccess(name, duration, result);
            // Format the result for MCP (OAuth templates only)
            return {
                content: [
                    {
                        type: 'text',
                        text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            const errorMessage = error instanceof Error ? error.message : String(error);
            this.logger.logToolError(name, error, duration, args);
            return {
                content: [
                    {
                        type: 'text',
                        text: `Error: ${errorMessage}`
                    }
                ],
                isError: true
            };
        }
    }
}
//# sourceMappingURL=google-drive-tools.js.map