# Google Drive Tool

> Agent tool for performing authenticated Google Drive API actions using per-user stored Google Drive access tokens.

**URL:** https://caywork.com/learn/docs/node/google-drive-tool-node

## Content


This node exposes a single tool that routes multiple Google Drive actions. It retrieves a per-user Google Drive access token from the user API, issues authenticated requests to the Drive v3 REST API, and returns parsed JSON (or raw text when parsing fails).

### Actions

- **Retrieves per-user Drive token** (access token); raises RuntimeError if missing.
- **Supports the following actions** (action-specific params described briefly below):
  - **list_files** — list files with optional Drive query. Optional params: q (Drive query string), page_size (default 20), page_token, fields (default "nextPageToken, files(id,name,mimeType,parents,size,modifiedTime)").
  - **get_file** — get file metadata. Required: file_id. Optional: fields (default "id,name,mimeType,parents,size,modifiedTime").
  - **create_folder** — create a folder. Required: name. Optional: parents (list of folder IDs) or llm_default_folder_id (single ID used when parents omitted).
  - **delete_file** — delete a file. Required: file_id.
  - **create_permission** — create a permission on a file. Required: file_id, role, type. Optional: emailAddress, allowFileDiscovery.
  - **list_permissions** — list permissions for a file. Required: file_id.

### Outputs

- Returns the parsed Google Drive API response (JSON-decoded) or raw text if JSON decoding fails.
- Pagination tokens (nextPageToken) and file lists are returned per the Drive API fields parameter when listing files.
- Errors surface as raised exceptions with logged context (network errors, validation errors, unexpected HTTP status codes).

### Behavior and Constraints

- **Per-user token**: Uses a per-user access token retrieved from the user Secret key store.
- **Fields selection**: Listing and metadata endpoints accept a fields parameter to control returned properties defaults favor commonly useful metadata.

### Error Handling

- Missing Google Drive config raises a RuntimeError indicating the missing key.
- Network/request errors raise RuntimeError with logged exception details.
- Non-success HTTP responses raise RuntimeError including HTTP status and response body.
- Action-specific parameter validation errors raise ValueError or Pydantic ValidationError as appropriate.
