AgentSkillsCN

google-docs

借助 Google Docs/Drive API 与 gcloud ADC,轻松查看并编辑 Google Docs,支持丰富的格式设置、表格以及现代化的 Google Drawings 图表。

SKILL.md
--- frontmatter
name: google-docs
description: View and edit Google Docs with rich formatting, tables, and modern Google Drawings diagrams using Google Docs/Drive APIs with gcloud ADC
license: MIT
compatibility: opencode
metadata:
  category: productivity
  system: google-workspace

Google Docs Integration

Use this skill when working with Google Docs, Slides, Sheets, or Drive using the OpenCode custom tools.

Authentication

The Google Workspace tools use gcloud auth application-default credentials. If you encounter a 403 error with ACCESS_TOKEN_SCOPE_INSUFFICIENT, the user needs to re-authenticate with the correct scopes.

Required Scopes

ScopePurpose
cloud-platformGCP resources, Secret Manager, etc.
documentsGoogle Docs read/write
presentationsGoogle Slides read/write
driveGoogle Drive files and folders
drive.fileFiles created by this app
spreadsheetsGoogle Sheets read/write
calendarGoogle Calendar events
calendar.eventsCalendar event management
gmail.modifyRead/write Gmail messages
gmail.readonlyRead-only Gmail access
gmail.sendSend emails
gmail.labelsManage Gmail labels
tasksGoogle Tasks
userinfo.emailUser email address
userinfo.profileUser profile info

Detecting Current Quota Project

The quota project is stored in the ADC credentials file. To detect it:

bash
cat ~/.config/gcloud/application_default_credentials.json | grep quota_project_id

Or use jq:

bash
jq -r '.quota_project_id // empty' ~/.config/gcloud/application_default_credentials.json

Full Authentication Setup

When you see errors like:

  • Request had insufficient authentication scopes
  • ACCESS_TOKEN_SCOPE_INSUFFICIENT
  • PERMISSION_DENIED on Google Docs/Slides/Drive APIs
  • SERVICE_DISABLED
  • API requires a quota project

First, detect or ask for the quota project:

bash
# Try to get existing quota project
PROJECT=$(jq -r '.quota_project_id // empty' ~/.config/gcloud/application_default_credentials.json 2>/dev/null)
echo "Current quota project: ${PROJECT:-not set}"

If not set, ask the user for their GCP project ID.

Then run the setup commands:

Step 1: Enable the required APIs on the quota project:

bash
gcloud services enable \
  docs.googleapis.com \
  slides.googleapis.com \
  drive.googleapis.com \
  sheets.googleapis.com \
  calendar-json.googleapis.com \
  gmail.googleapis.com \
  tasks.googleapis.com \
  --project=$PROJECT

Step 2: Authenticate with all scopes and set quota project:

bash
gcloud auth application-default login \
  --billing-project=$PROJECT \
  --scopes="\
https://www.googleapis.com/auth/cloud-platform,\
https://www.googleapis.com/auth/documents,\
https://www.googleapis.com/auth/presentations,\
https://www.googleapis.com/auth/drive,\
https://www.googleapis.com/auth/drive.file,\
https://www.googleapis.com/auth/spreadsheets,\
https://www.googleapis.com/auth/calendar,\
https://www.googleapis.com/auth/calendar.events,\
https://www.googleapis.com/auth/gmail.modify,\
https://www.googleapis.com/auth/gmail.readonly,\
https://www.googleapis.com/auth/gmail.send,\
https://www.googleapis.com/auth/gmail.labels,\
https://www.googleapis.com/auth/tasks,\
https://www.googleapis.com/auth/userinfo.email,\
https://www.googleapis.com/auth/userinfo.profile"

Note: --billing-project sets the quota project in ADC automatically.

One-liner Setup (Auto-detect or Prompt)

This command auto-detects existing quota project or prompts for one, enables APIs, and authenticates with all scopes in a single flow:

bash
PROJECT=${PROJECT:-$(jq -r '.quota_project_id // empty' ~/.config/gcloud/application_default_credentials.json 2>/dev/null)} && \
[ -z "$PROJECT" ] && read -p "Enter GCP project ID: " PROJECT && \
gcloud services enable docs.googleapis.com slides.googleapis.com drive.googleapis.com sheets.googleapis.com calendar-json.googleapis.com gmail.googleapis.com tasks.googleapis.com --project=$PROJECT && \
gcloud auth application-default login \
  --billing-project=$PROJECT \
  --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/documents,https://www.googleapis.com/auth/presentations,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/spreadsheets,https://www.googleapis.com/auth/calendar,https://www.googleapis.com/auth/calendar.events,https://www.googleapis.com/auth/gmail.modify,https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/gmail.send,https://www.googleapis.com/auth/gmail.labels,https://www.googleapis.com/auth/tasks,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile"

Note: --billing-project sets the quota project automatically, no need to run set-quota-project separately.

This opens a browser for the user to authenticate with all required scopes.

Automatic Auth Check

If any Google Workspace tool returns a 403/permission error:

  1. Tell the user they need to authenticate
  2. Provide the command above
  3. Wait for them to confirm authentication is complete
  4. Retry the operation

Available Tools

Google Docs

ToolPurpose
google-docs_createCreate a new Google Doc
google-docs_readRead document contents
google-docs_appendAppend text to end of doc
google-docs_find_replaceFind and replace text
google-docs_get_structureGet document headings structure

Google Slides

ToolPurpose
google-slides_createCreate a new presentation
google-slides_readRead slide contents
google-slides_add_slideAdd a new slide
google-slides_update_textUpdate text in a shape
google-slides_get_infoGet presentation info
google-slides_get_slide_elementsGet elements on a slide

Google Drive

ToolPurpose
google-drive_searchSearch for files
google-drive_listList files in a folder
google-drive_downloadDownload file content
google-drive_get_file_infoGet file metadata

Google Sheets

ToolPurpose
google-sheets_createCreate a new spreadsheet
google-sheets_readRead cell values
google-sheets_writeWrite cell values
google-sheets_append_rowsAppend rows to sheet
google-sheets_clearClear a range
google-sheets_get_infoGet spreadsheet info

Google Calendar

ToolPurpose
google-calendar_list_eventsList upcoming events
google-calendar_create_eventCreate a new event
google-calendar_update_eventUpdate an event
google-calendar_delete_eventDelete an event
google-calendar_search_eventsSearch events by query
google-calendar_list_calendarsList all calendars

Google Gmail

ToolPurpose
google-gmail_listList recent emails
google-gmail_readRead email content
google-gmail_searchSearch emails
google-gmail_get_threadGet email thread
google-gmail_mark_readMark as read
google-gmail_mark_unreadMark as unread

Creating Design Documents

When creating design documents:

  1. Create the base document with google-docs_create
  2. Add content in sections - the tool accepts plain text, structure with newlines
  3. For diagrams, create a separate Google Slides presentation and link to it
  4. Use markdown-style formatting in the content (will appear as plain text, can be formatted later)

Example: Create a Design Doc

code
1. google-docs_create(title="My Design Doc", content="# Title\n\n## Overview\n...")
2. google-slides_create(title="My Design Doc - Diagrams")
3. google-slides_add_slide(presentation_id="...", layout="BLANK")
4. Link the slides in the doc

Slide Layouts

Available layouts for google-slides_add_slide:

LayoutDescription
BLANKEmpty slide
TITLETitle slide
TITLE_AND_BODYTitle with body text
TITLE_AND_TWO_COLUMNSTitle with two columns
TITLE_ONLYJust a title
SECTION_HEADERSection divider
CAPTION_ONLYCaption at bottom
BIG_NUMBERLarge number display

Troubleshooting

Error: ACCESS_TOKEN_SCOPE_INSUFFICIENT

User needs to re-authenticate with scopes. Run Step 3 then Step 4 from Authentication section.

Error: SERVICE_DISABLED or "API requires a quota project"

The APIs are not enabled on the quota project, or no quota project is set:

  1. Ask user for their GCP project ID (e.g., ck-orp-nick-dev)
  2. Run Step 1 and Step 2 from Authentication section
  3. If still failing, run the full one-liner setup

Error: Document not found

  • Check the document ID is correct
  • Verify user has access to the document
  • Use google-drive_search to find the correct ID

Error: Rate limit exceeded

Google APIs have rate limits. Wait a few seconds and retry.

Error: Permission denied (not scope-related)

User may not have access to the document/resource. Check sharing settings in Google Drive.

Dependencies

  • gcloud CLI installed and configured
  • bun runtime for OpenCode tools
  • @opencode-ai/plugin npm package