mcp-gdrive

dennisonbertram/mcp-gdrive

3.2

If you are the rightful owner of mcp-gdrive 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.

Google Drive MCP Server provides secure access to Google Drive and Google Sheets functionality, enabling AI assistants to perform various operations.

Tools
5
Resources
0
Prompts
0

Google Drive MCP Server

A comprehensive Model Context Protocol (MCP) server that provides secure access to Google Drive and Google Sheets functionality. This server enables AI assistants to perform file operations, manage permissions, and interact with spreadsheets through a well-structured set of tools.

Features

🗂️ File Operations

  • List, search, and filter files
  • Create, read, update, and delete files
  • Upload and download content
  • Copy and move files
  • Export Google Workspace documents to various formats

📁 Folder Management

  • Create and organize folder hierarchies
  • Move files between folders
  • Get complete folder trees
  • Batch folder operations

🔐 Permission Control

  • Share files and folders with users or groups
  • Create public links with expiration
  • Manage access levels (view, comment, edit)
  • Batch permission updates

📊 Google Sheets Integration

  • Create and manage spreadsheets
  • Read and write cell values
  • Batch operations for efficiency
  • Format cells and ranges
  • Append data to sheets

📋 Dynamic Resources

  • Recent files list
  • Folder structure visualization
  • Storage quota information
  • Shared files tracking
  • Spreadsheet discovery

💬 Interactive Prompts

  • Organize files by patterns
  • Backup folders
  • Share projects with teams
  • Clean up duplicates
  • Generate reports from spreadsheets
  • Archive old files

Installation

Using Claude Desktop App

Add to your Claude desktop configuration:

{
  "mcpServers": {
    "gdrive": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/gdrive-mcp"],
      "env": {
        "GDRIVE_CLIENT_ID": "your_client_id",
        "GDRIVE_CLIENT_SECRET": "your_client_secret",
        "GDRIVE_REDIRECT_URI": "http://localhost:3000/oauth2callback",
        "GDRIVE_CREDS_DIR": "~/.config/gdrive-mcp"
      }
    }
  }
}

Using Claude CLI

# Install globally
npm install -g @modelcontextprotocol/gdrive-mcp

# Add to MCP
claude mcp add gdrive \
  --env GDRIVE_CLIENT_ID=your_client_id \
  --env GDRIVE_CLIENT_SECRET=your_client_secret \
  -- npx -y @modelcontextprotocol/gdrive-mcp

Using Cursor

Add to your Cursor settings:

{
  "mcp": {
    "servers": {
      "gdrive": {
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/gdrive-mcp"],
        "env": {
          "GDRIVE_CLIENT_ID": "your_client_id",
          "GDRIVE_CLIENT_SECRET": "your_client_secret"
        }
      }
    }
  }
}

Using Cline

Add to your Cline configuration:

{
  "mcp": {
    "gdrive": {
      "command": "npx",
      "args": ["@modelcontextprotocol/gdrive-mcp"],
      "env": {
        "GDRIVE_CLIENT_ID": "your_client_id",
        "GDRIVE_CLIENT_SECRET": "your_client_secret"
      }
    }
  }
}

Configuration

Prerequisites

  1. Google Cloud Project

    • Go to Google Cloud Console
    • Create a new project or select an existing one
    • Enable Google Drive API and Google Sheets API
  2. OAuth2 Credentials

    • Go to APIs & Services > Credentials
    • Click "Create Credentials" > "OAuth client ID"
    • Choose "Desktop app" or "Web application"
    • Add http://localhost:3000/oauth2callback to redirect URIs
    • Download the credentials JSON
  3. Environment Variables

    Create a .env file:

    # OAuth2 Configuration
    GDRIVE_CLIENT_ID=your_client_id.apps.googleusercontent.com
    GDRIVE_CLIENT_SECRET=your_client_secret
    GDRIVE_REDIRECT_URI=http://localhost:3000/oauth2callback
    GDRIVE_CREDS_DIR=~/.config/gdrive-mcp
    
    # Alternative: Service Account
    # GDRIVE_SERVICE_ACCOUNT_KEY=/path/to/service-account-key.json
    
    # Optional Configuration
    GDRIVE_LOG_LEVEL=info
    GDRIVE_MAX_RETRIES=3
    GDRIVE_DEFAULT_FIELDS=id,name,mimeType,modifiedTime
    

Authentication Methods

OAuth2 (Recommended for User Access)

The server will open a browser for authentication on first use. Tokens are stored securely and refreshed automatically.

Service Account (For Server-to-Server)
export GDRIVE_AUTH_METHOD=service_account
export GDRIVE_SERVICE_ACCOUNT_KEY=/path/to/key.json

Usage

Basic File Operations

// List files
await use_mcp_tool("gdrive", "gdrive_list_files", {
  pageSize: 10,
  query: "name contains 'report'"
});

// Create a file
await use_mcp_tool("gdrive", "gdrive_create_file", {
  name: "meeting-notes.txt",
  content: "Meeting notes from today...",
  mimeType: "text/plain"
});

// Download a file
await use_mcp_tool("gdrive", "gdrive_download_file", {
  fileId: "abc123",
  asBase64: true
});

Folder Management

// Create folder
await use_mcp_tool("gdrive", "gdrive_create_folder", {
  name: "Project Files",
  color: "blue"
});

// Move files
await use_mcp_tool("gdrive", "gdrive_move_file", {
  fileId: "file123",
  newParentId: "folder456"
});

Sharing and Permissions

// Share with user
await use_mcp_tool("gdrive", "gdrive_share_file", {
  fileId: "doc789",
  emailAddress: "colleague@example.com",
  role: "writer"
});

// Create public link
await use_mcp_tool("gdrive", "gdrive_create_public_link", {
  fileId: "doc789",
  linkType: "view",
  expirationDays: 7
});

Google Sheets Operations

// Create spreadsheet
await use_mcp_tool("gdrive", "sheets_create_spreadsheet", {
  title: "Sales Data",
  sheets: [{
    title: "Q1 2024",
    rowCount: 1000
  }]
});

// Write data
await use_mcp_tool("gdrive", "sheets_write_range", {
  spreadsheetId: "sheet123",
  range: "A1:B2",
  values: [
    ["Product", "Sales"],
    ["Widget A", 1500]
  ]
});

Using Resources

// Get recent files
const recent = await use_mcp_resource("gdrive", "gdrive://recent-files");

// Check storage quota
const quota = await use_mcp_resource("gdrive", "gdrive://storage-quota");

// Get file details
const file = await use_mcp_resource("gdrive", "gdrive://file/abc123");

Using Prompts

// Organize files
await use_mcp_prompt("gdrive", "organize_files", {
  pattern: "*.pdf",
  folderName: "PDF Documents"
});

// Create backup
await use_mcp_prompt("gdrive", "backup_folder", {
  folderId: "important-folder",
  backupName: "Backup_2024"
});

Available Tools

File Operations

  • gdrive_list_files - List files with filtering
  • gdrive_search_files - Advanced file search
  • gdrive_get_file - Get file metadata
  • gdrive_create_file - Create new file
  • gdrive_update_file - Update file content/metadata
  • gdrive_delete_file - Delete or trash file
  • gdrive_copy_file - Copy file
  • gdrive_download_file - Download file content
  • gdrive_export_file - Export Google Workspace files

Folder Management

  • gdrive_create_folder - Create folder
  • gdrive_list_folders - List folders
  • gdrive_move_file - Move files/folders
  • gdrive_get_folder_tree - Get folder hierarchy

Permissions

  • gdrive_share_file - Share with users
  • gdrive_list_permissions - List file permissions
  • gdrive_update_permission - Update permissions
  • gdrive_remove_permission - Remove permissions
  • gdrive_create_public_link - Create public link

Google Sheets

  • sheets_create_spreadsheet - Create spreadsheet
  • sheets_read_range - Read cell values
  • sheets_write_range - Write cell values
  • sheets_append_data - Append rows
  • sheets_batch_get - Read multiple ranges
  • sheets_batch_update - Update multiple ranges
  • sheets_clear_range - Clear cells
  • sheets_get_info - Get spreadsheet info
  • sheets_add_sheet - Add new sheet
  • sheets_format_cells - Format cells

Development

Local Development

# Clone repository
git clone https://github.com/your-org/gdrive-mcp.git
cd gdrive-mcp

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Start development server
npm run dev

Testing

# Run all tests
npm test

# Run specific test suite
npm test -- --grep "File Operations"

# Test with coverage
npm run test:coverage

Docker

# Build image
docker build -t gdrive-mcp .

# Run container
docker run -it \
  -e GDRIVE_CLIENT_ID=$GDRIVE_CLIENT_ID \
  -e GDRIVE_CLIENT_SECRET=$GDRIVE_CLIENT_SECRET \
  -v ~/.config/gdrive-mcp:/root/.config/gdrive-mcp \
  gdrive-mcp

Troubleshooting

Authentication Issues

Problem: "Authentication failed"

  • Verify CLIENT_ID and CLIENT_SECRET are correct
  • Check redirect URI matches configuration
  • Ensure APIs are enabled in Google Cloud Console

Problem: "Token expired"

  • Delete token file: rm ~/.config/gdrive-mcp/tokens.json
  • Re-authenticate by running the server again

Permission Errors

Problem: "Insufficient permissions"

  • Check OAuth scopes include necessary permissions
  • Verify file ownership for operations requiring owner access

Rate Limiting

Problem: "Rate limit exceeded"

  • Server implements automatic retry with exponential backoff
  • Consider batching operations for efficiency

Security

  • Credentials are stored securely with 0600 permissions
  • Tokens are encrypted at rest (optional)
  • No credentials are logged
  • Automatic token refresh prevents expiration
  • State parameter prevents CSRF attacks

Contributing

We welcome contributions! Please see our for details.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

MIT License - see file for details.

Support

Acknowledgments

Built with the Model Context Protocol SDK by Anthropic.