google-drive-automation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Google Drive Automation via Rube MCP

通过Rube MCP实现Google Drive自动化

Automate Google Drive workflows including file upload/download, search, folder management, sharing/permissions, and organization through Composio's Google Drive toolkit.
通过Composio的Google Drive工具包,自动化Google Drive工作流,包括文件上传/下载、搜索、文件夹管理、分享/权限设置以及文件整理。

Prerequisites

前提条件

  • Rube MCP must be connected (RUBE_SEARCH_TOOLS available)
  • Active Google Drive connection via
    RUBE_MANAGE_CONNECTIONS
    with toolkit
    googledrive
  • Always call
    RUBE_SEARCH_TOOLS
    first to get current tool schemas
  • 必须已连接Rube MCP(可使用RUBE_SEARCH_TOOLS)
  • 通过
    RUBE_MANAGE_CONNECTIONS
    工具包
    googledrive
    建立有效的Google Drive连接
  • 请始终先调用
    RUBE_SEARCH_TOOLS
    以获取当前工具架构

Setup

设置步骤

Get Rube MCP: Add
https://rube.app/mcp
as an MCP server in your client configuration. No API keys needed — just add the endpoint and it works.
  1. Verify Rube MCP is available by confirming
    RUBE_SEARCH_TOOLS
    responds
  2. Call
    RUBE_MANAGE_CONNECTIONS
    with toolkit
    googledrive
  3. If connection is not ACTIVE, follow the returned auth link to complete Google OAuth
  4. Confirm connection status shows ACTIVE before running any workflows
获取Rube MCP:在客户端配置中添加
https://rube.app/mcp
作为MCP服务器。无需API密钥,只需添加端点即可使用。
  1. 确认
    RUBE_SEARCH_TOOLS
    可正常响应,以此验证Rube MCP是否可用
  2. 调用
    RUBE_MANAGE_CONNECTIONS
    并指定工具包
    googledrive
  3. 如果连接状态未显示为ACTIVE,请按照返回的授权链接完成Google OAuth认证
  4. 在运行任何工作流之前,确认连接状态显示为ACTIVE

Core Workflows

核心工作流

1. Upload and Download Files

1. 文件上传与下载

When to use: User wants to upload files to or download files from Google Drive
Tool sequence:
  1. GOOGLEDRIVE_FIND_FILE
    - Locate target folder for upload [Prerequisite]
  2. GOOGLEDRIVE_UPLOAD_FILE
    - Upload a file (max 5MB) [Required]
  3. GOOGLEDRIVE_RESUMABLE_UPLOAD
    - Upload large files [Fallback]
  4. GOOGLEDRIVE_DOWNLOAD_FILE
    - Download a file by ID [Required]
  5. GOOGLEDRIVE_DOWNLOAD_FILE_OPERATION
    - Track long-running downloads [Fallback]
  6. GOOGLEDRIVE_GET_FILE_METADATA
    - Verify file after upload/download [Optional]
Key parameters:
  • file_to_upload
    : Object with
    name
    ,
    mimetype
    , and
    s3key
    (file must be in internal storage)
  • folder_to_upload_to
    : Target folder ID (optional; uploads to root if omitted)
  • file_id
    : ID of file to download
  • mime_type
    : Export format for Google Workspace files only (omit for native files)
Pitfalls:
  • GOOGLEDRIVE_UPLOAD_FILE
    requires
    file_to_upload.s3key
    ; files must already be in internal storage
  • For non-Google formats (Excel, PDF), do NOT set
    mime_type
    ; it causes errors for native files
  • Download responses provide a temporary URL at
    data.downloaded_file_content.s3url
    , not inline bytes
  • Use
    GOOGLEDRIVE_RESUMABLE_UPLOAD
    for files >5MB or when basic uploads fail
适用场景:用户需要上传文件至Google Drive或从Google Drive下载文件
工具执行顺序:
  1. GOOGLEDRIVE_FIND_FILE
    - 定位用于上传的目标文件夹 [前置步骤]
  2. GOOGLEDRIVE_UPLOAD_FILE
    - 上传文件(最大5MB) [必需步骤]
  3. GOOGLEDRIVE_RESUMABLE_UPLOAD
    - 上传大文件 [备选方案]
  4. GOOGLEDRIVE_DOWNLOAD_FILE
    - 通过文件ID下载文件 [必需步骤]
  5. GOOGLEDRIVE_DOWNLOAD_FILE_OPERATION
    - 跟踪长时间运行的下载任务 [备选方案]
  6. GOOGLEDRIVE_GET_FILE_METADATA
    - 上传/下载后验证文件 [可选步骤]
关键参数:
  • file_to_upload
    : 包含
    name
    mimetype
    s3key
    的对象(文件必须已存储在内部存储中)
  • folder_to_upload_to
    : 目标文件夹ID(可选;若省略则上传至根目录)
  • file_id
    : 待下载文件的ID
  • mime_type
    : 仅针对Google Workspace文件的导出格式(原生文件请省略)
注意事项:
  • GOOGLEDRIVE_UPLOAD_FILE
    需要
    file_to_upload.s3key
    ;文件必须已存在于内部存储中
  • 对于非Google格式(如Excel、PDF),请勿设置
    mime_type
    ;这会导致原生文件出现错误
  • 下载响应会在
    data.downloaded_file_content.s3url
    提供临时URL,而非内联字节数据
  • 对于大于5MB的文件或基础上传失败时,请使用
    GOOGLEDRIVE_RESUMABLE_UPLOAD

2. Search and List Files

2. 文件搜索与列出

When to use: User wants to find specific files or browse Drive contents
Tool sequence:
  1. GOOGLEDRIVE_FIND_FILE
    - Search by name, content, type, date, or folder [Required]
  2. GOOGLEDRIVE_LIST_FILES
    - Browse files with folder scoping [Alternative]
  3. GOOGLEDRIVE_LIST_SHARED_DRIVES
    - Enumerate shared drives [Optional]
  4. GOOGLEDRIVE_GET_FILE_METADATA
    - Get detailed file info [Optional]
  5. GOOGLEDRIVE_GET_ABOUT
    - Check storage quota and supported formats [Optional]
Key parameters:
  • q
    : Drive query string (e.g., "name contains 'report'", "mimeType = 'application/pdf'")
  • corpora
    : Search scope ('user', 'domain', 'drive', 'allDrives')
  • fields
    : Response fields to include (e.g., 'files(id,name,mimeType)')
  • orderBy
    : Sort key ('modifiedTime desc', 'name', 'quotaBytesUsed desc')
  • pageSize
    : Results per page (max 1000)
  • pageToken
    : Pagination cursor from
    nextPageToken
  • folder_id
    : Scope search to a specific folder
Pitfalls:
  • 403 PERMISSION_DENIED if OAuth scopes insufficient for shared drives
  • Pagination required; files are in
    response.data.files
    ; follow
    nextPageToken
    until exhausted
  • corpora="domain"
    may trigger 400; try
    "allDrives"
    with
    includeItemsFromAllDrives=true
  • Query complexity limits: >5-10 OR clauses may error "The query is too complex"
  • Wildcards (*) NOT supported in
    name
    ; use
    contains
    for partial matching
  • 'My Drive' is NOT searchable by name; use
    folder_id='root'
    for root folder
  • User email searches: use
    'user@example.com' in owners
    (NOT
    owner:user@example.com
    )
适用场景:用户需要查找特定文件或浏览Drive内容
工具执行顺序:
  1. GOOGLEDRIVE_FIND_FILE
    - 按名称、内容、类型、日期或文件夹搜索 [必需步骤]
  2. GOOGLEDRIVE_LIST_FILES
    - 按文件夹范围浏览文件 [备选方案]
  3. GOOGLEDRIVE_LIST_SHARED_DRIVES
    - 枚举共享驱动器 [可选步骤]
  4. GOOGLEDRIVE_GET_FILE_METADATA
    - 获取文件详细信息 [可选步骤]
  5. GOOGLEDRIVE_GET_ABOUT
    - 查看存储配额和支持的格式 [可选步骤]
关键参数:
  • q
    : Drive查询字符串(例如:"name contains 'report'"、"mimeType = 'application/pdf'")
  • corpora
    : 搜索范围('user'、'domain'、'drive'、'allDrives')
  • fields
    : 响应中包含的字段(例如:'files(id,name,mimeType)')
  • orderBy
    : 排序键('modifiedTime desc'、'name'、'quotaBytesUsed desc')
  • pageSize
    : 每页结果数量(最大1000)
  • pageToken
    : 来自
    nextPageToken
    的分页游标
  • folder_id
    : 将搜索范围限定到特定文件夹
注意事项:
  • 如果OAuth权限不足,访问共享驱动器会返回403 PERMISSION_DENIED错误
  • 需要分页处理;文件位于
    response.data.files
    中;需跟随
    nextPageToken
    直到无更多结果
  • 使用
    corpora="domain"
    可能触发400错误;尝试使用
    "allDrives"
    并设置
    includeItemsFromAllDrives=true
  • 查询复杂度限制:超过5-10个OR子句可能会报错“查询过于复杂”
  • 名称搜索不支持通配符(*);请使用
    contains
    进行部分匹配
  • 无法通过名称搜索“我的云端硬盘”;请使用
    folder_id='root'
    指定根文件夹
  • 用户邮箱搜索:使用
    'user@example.com' in owners
    (而非
    owner:user@example.com

3. Share Files and Manage Permissions

3. 文件分享与权限管理

When to use: User wants to share files or manage access permissions
Tool sequence:
  1. GOOGLEDRIVE_FIND_FILE
    - Locate the file to share [Prerequisite]
  2. GOOGLEDRIVE_ADD_FILE_SHARING_PREFERENCE
    - Set sharing permission [Required]
  3. GOOGLEDRIVE_LIST_PERMISSIONS
    - View current permissions [Optional]
  4. GOOGLEDRIVE_GET_PERMISSION
    - Inspect a specific permission [Optional]
  5. GOOGLEDRIVE_UPDATE_PERMISSION
    - Modify existing permission [Optional]
  6. GOOGLEDRIVE_DELETE_PERMISSION
    - Revoke access [Optional]
Key parameters:
  • file_id
    : ID of file to share
  • type
    : 'user', 'group', 'domain', or 'anyone'
  • role
    : 'owner', 'organizer', 'fileOrganizer', 'writer', 'commenter', 'reader'
  • email_address
    : Required for type='user' or 'group'
  • domain
    : Required for type='domain'
  • transfer_ownership
    : Required when role='owner'
Pitfalls:
  • Invalid type/email combinations trigger 4xx errors
  • Using
    type='anyone'
    or powerful roles is risky; get explicit user confirmation
  • Org policies may block certain sharing types, causing 403
  • Permission changes may take time to propagate
  • Use
    GMAIL_SEARCH_PEOPLE
    to resolve contact names to emails before sharing
适用场景:用户需要分享文件或管理访问权限
工具执行顺序:
  1. GOOGLEDRIVE_FIND_FILE
    - 定位待分享的文件 [前置步骤]
  2. GOOGLEDRIVE_ADD_FILE_SHARING_PREFERENCE
    - 设置分享权限 [必需步骤]
  3. GOOGLEDRIVE_LIST_PERMISSIONS
    - 查看当前权限 [可选步骤]
  4. GOOGLEDRIVE_GET_PERMISSION
    - 检查特定权限详情 [可选步骤]
  5. GOOGLEDRIVE_UPDATE_PERMISSION
    - 修改现有权限 [可选步骤]
  6. GOOGLEDRIVE_DELETE_PERMISSION
    - 撤销访问权限 [可选步骤]
关键参数:
  • file_id
    : 待分享文件的ID
  • type
    : 'user'、'group'、'domain'或'anyone'
  • role
    : 'owner'、'organizer'、'fileOrganizer'、'writer'、'commenter'、'reader'
  • email_address
    : 当type='user'或'group'时为必填项
  • domain
    : 当type='domain'时为必填项
  • transfer_ownership
    : 当role='owner'时为必填项
注意事项:
  • 无效的type/email组合会触发4xx错误
  • 使用
    type='anyone'
    或高权限角色存在风险;请获取用户明确确认
  • 组织策略可能会阻止某些分享类型,导致403错误
  • 权限变更可能需要时间才能生效
  • 分享前请使用
    GMAIL_SEARCH_PEOPLE
    将联系人姓名解析为邮箱

4. Create and Organize Folders

4. 文件夹创建与整理

When to use: User wants to create folder structures or move files between folders
Tool sequence:
  1. GOOGLEDRIVE_FIND_FILE
    - Check if folder already exists [Prerequisite]
  2. GOOGLEDRIVE_CREATE_FOLDER
    - Create a new folder [Required]
  3. GOOGLEDRIVE_GET_FILE_METADATA
    - Verify created folder [Optional]
  4. GOOGLEDRIVE_MOVE_FILE
    - Move files between folders [Optional]
  5. GOOGLEDRIVE_UPDATE_FILE_PUT
    - Update file metadata/parents [Alternative]
Key parameters:
  • name
    : Folder name
  • parent_id
    : Parent folder ID (NOT name); omit for root
  • file_id
    : File to move
  • add_parents
    : Destination folder ID for move
  • remove_parents
    : Source folder ID to remove from
Pitfalls:
  • GOOGLEDRIVE_CREATE_FOLDER
    requires
    parent_id
    as an ID, not a folder name
  • Using
    parent_id="root"
    creates at top level; for nested paths, chain folder IDs
  • GOOGLEDRIVE_FIND_FILE
    returns ~100 items/page; follow
    nextPageToken
    for large drives
  • Move operations can leave items with multiple parents; use
    remove_parents
    for true moves
  • Always verify parent folder exists before creating children
适用场景:用户需要创建文件夹结构或在文件夹之间移动文件
工具执行顺序:
  1. GOOGLEDRIVE_FIND_FILE
    - 检查文件夹是否已存在 [前置步骤]
  2. GOOGLEDRIVE_CREATE_FOLDER
    - 创建新文件夹 [必需步骤]
  3. GOOGLEDRIVE_GET_FILE_METADATA
    - 验证已创建的文件夹 [可选步骤]
  4. GOOGLEDRIVE_MOVE_FILE
    - 在文件夹之间移动文件 [可选步骤]
  5. GOOGLEDRIVE_UPDATE_FILE_PUT
    - 更新文件元数据/父文件夹 [备选方案]
关键参数:
  • name
    : 文件夹名称
  • parent_id
    : 父文件夹ID(而非名称);若省略则创建在根目录
  • file_id
    : 待移动的文件
  • add_parents
    : 移动目标文件夹的ID
  • remove_parents
    : 要移除的源文件夹ID
注意事项:
  • GOOGLEDRIVE_CREATE_FOLDER
    要求
    parent_id
    为ID,而非文件夹名称
  • 使用
    parent_id="root"
    会在顶层创建文件夹;对于嵌套路径,请链式传递文件夹ID
  • GOOGLEDRIVE_FIND_FILE
    每页返回约100条结果;对于大型驱动器,请跟随
    nextPageToken
    获取全部结果
  • 移动操作可能会让文件保留多个父文件夹;请使用
    remove_parents
    实现真正的移动
  • 创建子文件夹前,请始终验证父文件夹是否存在

Common Patterns

通用模式

ID Resolution

ID解析

  • File/folder name -> ID:
    GOOGLEDRIVE_FIND_FILE
    with
    q
    parameter
  • Root folder: Use
    folder_id='root'
    or
    'root' in parents
  • Shared drive -> driveId:
    GOOGLEDRIVE_LIST_SHARED_DRIVES
  • Contact name -> email:
    GMAIL_SEARCH_PEOPLE
    (for sharing)
  • 文件/文件夹名称 -> ID:使用带
    q
    参数的
    GOOGLEDRIVE_FIND_FILE
  • 根文件夹:使用
    folder_id='root'
    'root' in parents
  • 共享驱动器 -> driveId:使用
    GOOGLEDRIVE_LIST_SHARED_DRIVES
  • 联系人姓名 -> 邮箱:使用
    GMAIL_SEARCH_PEOPLE
    (用于分享场景)

Query Syntax

查询语法

Google Drive uses a specific query language:
  • Name search:
    "name contains 'report'"
    or
    "name = 'exact.pdf'"
  • Type filter:
    "mimeType = 'application/pdf'"
    or
    "mimeType = 'application/vnd.google-apps.folder'"
  • Folder scoping:
    "'FOLDER_ID' in parents"
  • Date filter:
    "modifiedTime > '2024-01-01T00:00:00'"
  • Combine with
    and
    /
    or
    /
    not
    :
    "name contains 'report' and trashed = false"
  • Boolean filters:
    "sharedWithMe = true"
    ,
    "starred = true"
    ,
    "trashed = false"
Google Drive使用特定的查询语言:
  • 名称搜索:
    "name contains 'report'"
    "name = 'exact.pdf'"
  • 类型筛选:
    "mimeType = 'application/pdf'"
    "mimeType = 'application/vnd.google-apps.folder'"
  • 文件夹范围:
    "'FOLDER_ID' in parents"
  • 日期筛选:
    "modifiedTime > '2024-01-01T00:00:00'"
  • 使用
    and
    /
    or
    /
    not
    组合:
    "name contains 'report' and trashed = false"
  • 布尔筛选:
    "sharedWithMe = true"
    "starred = true"
    "trashed = false"

Pagination

分页处理

  • Follow
    nextPageToken
    until absent for complete results
  • Set
    pageSize
    explicitly (default 100, max 1000)
  • De-duplicate results if running multiple searches
  • 跟随
    nextPageToken
    直到不存在,以获取完整结果
  • 显式设置
    pageSize
    (默认100,最大1000)
  • 若执行多次搜索,请对结果进行去重

Export Formats

导出格式

For Google Workspace files, set
mime_type
to export:
  • Docs:
    application/pdf
    ,
    text/plain
    ,
    text/html
    ,
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • Sheets:
    text/csv
    ,
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • Slides:
    application/pdf
    ,
    application/vnd.openxmlformats-officedocument.presentationml.presentation
对于Google Workspace文件,请设置
mime_type
以指定导出格式:
  • 文档
    application/pdf
    text/plain
    text/html
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • 表格
    text/csv
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • 幻灯片
    application/pdf
    application/vnd.openxmlformats-officedocument.presentationml.presentation

Known Pitfalls

已知注意事项

  • Internal storage required: Upload requires files in internal S3 storage (s3key)
  • Export vs download: Set
    mime_type
    ONLY for Google Workspace files; omit for native files
  • Temporary URLs: Downloaded content via
    s3url
    is temporary; fetch promptly
  • Query complexity: >5-10 OR clauses may error; split complex searches into multiple queries
  • Shared drive scoping: Missing drive permissions yield empty results; verify access first
  • No wildcards: Use
    contains
    operator instead of
    *
    for partial name matching
  • Folder creation chains: Always pass folder IDs (not names) as
    parent_id
  • Multiple parents: Move operations may leave items with multiple parents; use
    remove_parents
  • Rate limits: Heavy searches/exports can trigger 403/429; implement backoff
  • 需要内部存储:上传要求文件已存储在内部S3存储中(需提供s3key)
  • 导出与下载的区别:仅对Google Workspace文件设置
    mime_type
    ;原生文件请省略
  • 临时URL:通过
    s3url
    获取的下载内容是临时的;请及时获取
  • 查询复杂度:超过5-10个OR子句可能会报错;请将复杂查询拆分为多个查询
  • 共享驱动器范围:缺少驱动器权限会返回空结果;请先验证访问权限
  • 无通配符:请使用
    contains
    运算符代替
    *
    进行名称部分匹配
  • 文件夹创建链式操作:请始终传递文件夹ID(而非名称)作为
    parent_id
  • 多父文件夹:移动操作可能会让文件保留多个父文件夹;请使用
    remove_parents
  • 速率限制:频繁的搜索/导出操作可能会触发403/429错误;请实现退避机制

Quick Reference

快速参考

TaskTool SlugKey Params
Search files
GOOGLEDRIVE_FIND_FILE
q
,
corpora
,
pageSize
List files
GOOGLEDRIVE_LIST_FILES
folderId
,
q
,
orderBy
Upload file
GOOGLEDRIVE_UPLOAD_FILE
file_to_upload
,
folder_to_upload_to
Resumable upload
GOOGLEDRIVE_RESUMABLE_UPLOAD
file data
Download file
GOOGLEDRIVE_DOWNLOAD_FILE
file_id
,
mime_type
(Workspace only)
File metadata
GOOGLEDRIVE_GET_FILE_METADATA
fileId
,
fields
Create folder
GOOGLEDRIVE_CREATE_FOLDER
name
,
parent_id
Move file
GOOGLEDRIVE_MOVE_FILE
file_id
,
add_parents
,
remove_parents
Share file
GOOGLEDRIVE_ADD_FILE_SHARING_PREFERENCE
file_id
,
role
,
type
,
email_address
List permissions
GOOGLEDRIVE_LIST_PERMISSIONS
fileId
Update permission
GOOGLEDRIVE_UPDATE_PERMISSION
file_id, permission_id
Delete permission
GOOGLEDRIVE_DELETE_PERMISSION
file_id, permission_id
List shared drives
GOOGLEDRIVE_LIST_SHARED_DRIVES
pageSize
Drive info
GOOGLEDRIVE_GET_ABOUT
(none)
Create shortcut
GOOGLEDRIVE_CREATE_SHORTCUT_TO_FILE
target file_id
任务工具标识关键参数
搜索文件
GOOGLEDRIVE_FIND_FILE
q
,
corpora
,
pageSize
列出文件
GOOGLEDRIVE_LIST_FILES
folderId
,
q
,
orderBy
上传文件
GOOGLEDRIVE_UPLOAD_FILE
file_to_upload
,
folder_to_upload_to
可恢复上传
GOOGLEDRIVE_RESUMABLE_UPLOAD
文件数据
下载文件
GOOGLEDRIVE_DOWNLOAD_FILE
file_id
,
mime_type
(仅Workspace文件)
文件元数据
GOOGLEDRIVE_GET_FILE_METADATA
fileId
,
fields
创建文件夹
GOOGLEDRIVE_CREATE_FOLDER
name
,
parent_id
移动文件
GOOGLEDRIVE_MOVE_FILE
file_id
,
add_parents
,
remove_parents
分享文件
GOOGLEDRIVE_ADD_FILE_SHARING_PREFERENCE
file_id
,
role
,
type
,
email_address
列出权限
GOOGLEDRIVE_LIST_PERMISSIONS
fileId
更新权限
GOOGLEDRIVE_UPDATE_PERMISSION
file_id, permission_id
删除权限
GOOGLEDRIVE_DELETE_PERMISSION
file_id, permission_id
列出共享驱动器
GOOGLEDRIVE_LIST_SHARED_DRIVES
pageSize
驱动器信息
GOOGLEDRIVE_GET_ABOUT
创建快捷方式
GOOGLEDRIVE_CREATE_SHORTCUT_TO_FILE
target file_id