gdrive-mcp-server

v-odoo-testing/gdrive-mcp-server

3.2

If you are the rightful owner of gdrive-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This document provides a structured summary of the Google Drive MCP Server - Enhanced Authentication & Download Edition, highlighting its key features, tools, and usage instructions.

Tools
  1. download_folder_recursive

    Download entire folders with automatic conversion.

  2. download_file

    Download individual files with proper handling.

  3. export_google_file

    Convert Google files to Office formats.

  4. get_folder_structure

    Analyze folder contents before downloading.

  5. check_auth_status

    Check authentication status and diagnose issues.

Google Drive MCP Server - Enhanced Authentication & Download Edition

Overview

This is an enhanced version of the Google Drive MCP server with robust authentication management and powerful download capabilities. The server now features:

āœ… Automatic token refresh - Seamless authentication handling
āœ… Enhanced error reporting - Clear, actionable error messages
āœ… Modular architecture - Clean, maintainable codebase
āœ… Bulk download operations - Recursive downloads with smart features ⭐ NEW!
āœ… File conversion - Google Docs/Sheets/Slides to Office formats ⭐ NEW!
āœ… Shared Drive support - Full team drive compatibility
āœ… Smart retry logic - Handles rate limits and network issues
āœ… Version deduplication - Automatic duplicate removal ⭐ NEW!

šŸš€ New Features

šŸ“„ Download & Export Tools ⭐ NEW!

  • download_folder_recursive - Download entire folders with automatic conversion
  • download_file - Download individual files with proper handling
  • export_google_file - Convert Google files to Office formats
  • get_folder_structure - Analyze folder contents before downloading
  • Smart conversion - Google Docs → Word, Sheets → Excel, Slides → PowerPoint
  • Version deduplication - Keeps latest versions, removes duplicates
  • Progress tracking - Real-time download progress and statistics

šŸ” Enhanced Authentication System

  • Automatic token refresh - No more mid-operation failures
  • Proactive token management - Checks expiry before operations
  • Graceful degradation - Clear error messages when re-auth needed
  • Authentication status tool - Debug auth issues easily
  • Hybrid error handling - Combines auto-retry with user guidance

šŸ—ļø Modular Architecture

  • Clean separation - 400-line main file vs previous 1500+ lines
  • Organized structure - Tool handlers, utilities, and auth management
  • Maintainable code - Easy to extend and debug
  • Type safety - Full TypeScript support with proper error handling

Quick Start

1. Build the server

npm install
npm run build

2. Authenticate (first time only)

node dist/index.js auth

3. Run the server

node dist/index.js

Project Structure

šŸ“¦ gdrive-custom/
ā”œā”€ā”€ šŸ“„ index.ts                    # Main server (416 lines - clean!)
ā”œā”€ā”€ šŸ“ src/                        
│   ā”œā”€ā”€ šŸ“„ auth-manager.ts          # Authentication management
│   ā”œā”€ā”€ šŸ“ tool-handlers/           
│   │   ā”œā”€ā”€ šŸ“„ basic-operations.ts  # Search, copy, move, create, list
│   │   └── šŸ“„ shared-drive-operations.ts # Team drive operations
│   └── šŸ“ utils/                   
│       ā”œā”€ā”€ šŸ“„ error-handling.ts    # Enhanced error context & messages
│       └── šŸ“„ file-utils.ts        # File operations & retry logic
ā”œā”€ā”€ šŸ“ dist/                        # Compiled output
└── šŸ“„ README.md                    # This file

šŸ”§ Available Tools

Basic Operations

ToolDescriptionEnhanced Features
searchSearch files in Driveāœ… Auto-retry, validation
copy_fileCopy files/foldersāœ… ID validation, clear feedback
move_fileMove files between foldersāœ… Parent validation, error context
create_folderCreate new foldersāœ… Name validation, duplicate handling
list_filesList folder contentsāœ… MIME filtering, pagination

Shared Drive Operations

ToolDescriptionEnhanced Features
list_shared_drivesList accessible team drivesāœ… Permission-aware listing
search_shared_driveSearch in team drivesāœ… Cross-drive search capability
list_shared_drive_filesList team drive filesāœ… Folder-specific listing
enhanced_searchSearch across all drivesāœ… Combined personal + team results
identify_folder_typeIdentify drive locationāœ… Detailed metadata analysis

Download & Export Operations ⭐ NEW!

ToolDescriptionEnhanced Features
download_folder_recursiveDownload entire foldersāœ… NEW! Bulk download with conversion
download_fileDownload individual filesāœ… NEW! Smart format handling
export_google_fileConvert Google filesāœ… NEW! Office format conversion
get_folder_structureAnalyze folder structureāœ… NEW! Pre-download analysis

System & Debugging

ToolDescriptionEnhanced Features
check_auth_statusCheck authenticationāœ… NEW! Detailed token analysis

šŸ” Authentication Features

Automatic Token Management

  • Smart refresh - Automatically refreshes tokens when they're about to expire
  • Background monitoring - Continuous token health checking
  • Transparent operation - Users don't see authentication interruptions

Enhanced Error Handling

The system now provides context-aware error messages with specific recovery instructions:

Token Expired
āŒ Your Google Drive access token has expired.

šŸ”§ Recovery Instructions:
1. The system will attempt to refresh your token automatically.
2. If this fails repeatedly, please re-authenticate:
3. Run: node dist/index.js auth
4. Follow the browser authentication flow
5. Restart the MCP server
Permission Denied
āŒ Permission denied for this Google Drive operation.

šŸ”§ Recovery Instructions:
1. This could be due to:
2. Insufficient Google Drive permissions
3. File/folder access restrictions
4. Organization policy limitations
5. Try re-authenticating with full permissions

Debugging Tools

Use the new check_auth_status tool to diagnose authentication issues:

{
  "name": "check_auth_status",
  "arguments": {}
}

Sample Output:

šŸ” Authentication Status: āœ… Authenticated (expires in 42 minutes)

šŸ“Š Token Details:
{
  "isValid": true,
  "expiresAt": 1751780116482,
  "needsRefresh": false,
  "timeUntilExpiry": 2537266
}

šŸ’” Usage Examples

Basic File Operations

// Search for files
{
  "name": "search",
  "arguments": {
    "query": "project documents"
  }
}

// Copy with validation
{
  "name": "copy_file", 
  "arguments": {
    "fileId": "1ABC123...",
    "name": "Project Copy",
    "parentId": "1XYZ789..."
  }
}

Enhanced Search

// Search across all drives with limits
{
  "name": "enhanced_search",
  "arguments": {
    "query": "quarterly reports",
    "searchSharedDrives": true,
    "searchPersonalDrive": true,
    "maxResults": 50
  }
}

Download Operations ⭐ NEW!

// Download entire folder recursively
{
  "name": "download_folder_recursive",
  "arguments": {
    "folderId": "1ABC123...",
    "driveId": "0XYZ789...",
    "localPath": "/path/to/download/",
    "deduplicateVersions": true,
    "dryRun": false
  }
}

// Download individual file
{
  "name": "download_file",
  "arguments": {
    "fileId": "1ABC123...",
    "outputPath": "/path/to/file.pdf",
    "driveId": "0XYZ789..."
  }
}

// Export Google file to Office format
{
  "name": "export_google_file",
  "arguments": {
    "fileId": "1ABC123...",
    "mimeType": "application/vnd.google-apps.document",
    "outputPath": "/path/to/document.docx",
    "format": "auto"
  }
}

// Analyze folder structure first
{
  "name": "get_folder_structure",
  "arguments": {
    "folderId": "1ABC123...",
    "driveId": "0XYZ789...",
    "maxDepth": 10
  }
}

Authentication Debugging

// Check current auth status
{
  "name": "check_auth_status",
  "arguments": {}
}

šŸ› ļø Advanced Configuration

Environment Variables

# Optional: Custom credential paths
GDRIVE_CREDENTIALS_PATH="/path/to/saved/credentials.json"
GDRIVE_OAUTH_PATH="/path/to/oauth/credentials.json"

Authentication Setup

  1. Create credentials at Google Cloud Console
  2. Enable Google Drive API
  3. Download OAuth2 credentials JSON
  4. Place credentials at ~/.google_sheet_secrets/credentials.json
  5. Run node dist/index.js auth to authenticate

🧰 Development & Maintenance

Building

npm run build        # Compile TypeScript
npm run watch        # Watch mode for development

Testing Authentication

# Quick auth test
echo '{"method": "tools/call", "params": {"name": "check_auth_status", "arguments": {}}}' | node dist/index.js

File Structure Benefits

  • Maintainable: Each component has a single responsibility
  • Testable: Utilities and handlers can be tested independently
  • Extensible: New tools can be added without touching core logic
  • Debuggable: Clear separation makes issues easier to isolate

šŸ”„ Migration from Previous Version

If upgrading from the monolithic version:

  1. Build the new version: npm run build
  2. Test authentication: Use check_auth_status tool
  3. Verify operations: Test basic operations first
  4. Full compatibility: All existing tool names remain the same

āš ļø Note: Some bulk operations are currently being refactored for the new architecture. Basic operations and shared drive features are fully functional.

šŸ› Troubleshooting

Authentication Issues

  • Use check_auth_status tool for diagnosis
  • Check credentials file permissions
  • Verify Google Drive API is enabled
  • Re-run authentication: node dist/index.js auth

API Errors

  • Rate limits: Automatically handled with exponential backoff
  • Network issues: Automatic retry with progressive delays
  • Permission errors: Clear instructions provided in error messages

Development Issues

  • Build errors: Check TypeScript compilation with npm run build
  • Import errors: Verify file structure matches expected paths
  • Runtime errors: Check authentication status first

šŸ“Š Performance & Reliability

Enhanced Reliability

  • Automatic retries for transient failures
  • Smart backoff for rate limit handling
  • Connection resilience for network issues
  • Token proactive management prevents mid-operation failures

Performance Optimizations

  • Modular loading - Only load needed components
  • Efficient compilation - TypeScript with optimized output
  • Memory management - Better resource utilization
  • Reduced overhead - Cleaner architecture with less bloat

šŸŽÆ Architecture Achievement Summary

āœ… Reduced complexity: 1543 lines → 416 lines main file
āœ… Enhanced authentication: Automatic token refresh + clear error handling
āœ… Improved maintainability: Modular structure with separation of concerns
āœ… Better user experience: Context-aware error messages + debugging tools
āœ… Bulk download operations: Complete recursive download with smart conversion ⭐ NEW!
āœ… File format conversion: Google files → Office formats automatically ⭐ NEW!
āœ… Version deduplication: Intelligent duplicate removal ⭐ NEW!
āœ… Production-ready: Handles large-scale folder downloads (750+ files) ⭐ NEW!

Latest Achievement: Implemented complete download functionality with enterprise-grade features for automated Google Drive backups.