Create and modify Google Docs documents. Read document content and structure, manage formatting, paragraphs, and styles. Use when working with Google Docs document management.
Resources
3Install
npx skillscat add odyssey4me/agent-skills/google-docs Install via the SkillsCat registry.
Google Docs
Interact with Google Docs for document creation, editing, and content management.
Installation
Install Python dependencies:
pip install --user google-auth google-auth-oauthlib google-api-python-client keyring pyyamlDownload the skill from Releases or use directly from this repository.
Setup Verification
After installation, verify the skill is properly configured:
python scripts/google-docs.py checkThis will check:
- Python dependencies (google-auth, google-auth-oauthlib, google-api-python-client, keyring, pyyaml)
- Authentication configuration
- Connectivity to Google Docs API
If anything is missing, the check command will provide setup instructions.
Authentication
Google Docs uses OAuth 2.0 for authentication. For complete setup instructions, see:
- GCP Project Setup Guide - Create project, enable Docs API
- Google OAuth Setup Guide - Configure credentials
Quick Start
Create
~/.config/agent-skills/google.yaml:oauth_client: client_id: your-client-id.apps.googleusercontent.com client_secret: your-client-secretRun
python scripts/google-docs.py checkto trigger OAuth flow and verify setup.
OAuth Scopes
The skill requests granular scopes for different operations:
| Scope | Permission | Used For |
|---|---|---|
documents.readonly |
Read documents | Reading document content and metadata |
documents |
Full access | Creating and modifying documents |
drive.readonly |
Read Drive files | Exporting documents as markdown or PDF |
Scope Errors
If you encounter "insufficient scope" errors, reset your token and re-authenticate:
- Reset token:
python scripts/google-docs.py auth reset - Re-run:
python scripts/google-docs.py check
Commands
check
Verify configuration and connectivity.
python scripts/google-docs.py checkThis validates:
- Python dependencies are installed
- Authentication is configured
- Can connect to Google Docs API
- Creates a test document to verify write access
auth setup
Store OAuth 2.0 client credentials for custom OAuth flow.
python scripts/google-docs.py auth setup \
--client-id YOUR_CLIENT_ID \
--client-secret YOUR_CLIENT_SECRETCredentials are saved to ~/.config/agent-skills/google-docs.yaml.
Options:
--client-id- OAuth 2.0 client ID (required)--client-secret- OAuth 2.0 client secret (required)
auth reset
Clear stored OAuth token. The next command that needs authentication will trigger re-authentication automatically.
python scripts/google-docs.py auth resetUse this when you encounter scope or authentication errors.
auth status
Show current OAuth token information without making API calls.
python scripts/google-docs.py auth statusDisplays: whether a token is stored, granted scopes, refresh token presence, token expiry, and client ID.
documents create
Create a new blank Google Doc.
python scripts/google-docs.py documents create --title "My Document"Options:
--title- Document title (required)
Example:
# Create a new document
python scripts/google-docs.py documents create --title "Project Notes"
# Output:
# ✓ Document created successfully
# Title: Project Notes
# Document ID: 1abc...xyz
# URL: https://docs.google.com/document/d/1abc...xyz/editdocuments get
Get document metadata and structure.
python scripts/google-docs.py documents get DOCUMENT_IDArguments:
document_id- The Google Docs document ID
Example:
# Get document metadata
python scripts/google-docs.py documents get 1abc...xyz
# Output:
# Title: Project Notes
# Document ID: 1abc...xyz
# Characters: 1234
# Revision ID: abc123documents read
Read document content as plain text, markdown, or PDF.
python scripts/google-docs.py documents read DOCUMENT_IDArguments:
document_id- The Google Docs document ID
Options:
--format- Output format:markdown(default, preserves tables and headings) orpdf--output,-o- Output file path (used with pdf format)
Example:
# Read as markdown (default, preserves tables and headings)
python scripts/google-docs.py documents read 1abc...xyz
# Export as PDF
python scripts/google-docs.py documents read 1abc...xyz --format pdf --output document.pdf
# Output as markdown:
# # Heading
#
# This is a paragraph.
#
# | Column 1 | Column 2 |
# |----------|----------|
# | Value 1 | Value 2 |Note: Markdown and PDF export use Google's native Drive API export. Markdown preserves tables, headings, formatting, and structure with high fidelity. Both require the drive.readonly scope.
content append
Append text to the end of a document.
python scripts/google-docs.py content append DOCUMENT_ID --text "Additional content"Arguments:
document_id- The Google Docs document ID
Options:
--text- Text to append (required)
Example:
# Append text
python scripts/google-docs.py content append 1abc...xyz --text "Meeting notes from today..."
# Output:
# ✓ Text appended successfullycontent insert
Insert text at a specific position in the document.
python scripts/google-docs.py content insert DOCUMENT_ID --text "Insert this" --index 10Arguments:
document_id- The Google Docs document ID
Options:
--text- Text to insert (required)--index- Position to insert at, 0-based (required)
Example:
# Insert text at the beginning (index 1, after title)
python scripts/google-docs.py content insert 1abc...xyz --text "Introduction\n\n" --index 1
# Output:
# ✓ Text inserted successfullyNote: Index 0 is before the document content. Index 1 is at the beginning of content.
content delete
Delete a range of content from the document.
python scripts/google-docs.py content delete DOCUMENT_ID --start-index 10 --end-index 50Arguments:
document_id- The Google Docs document ID
Options:
--start-index- Start position, inclusive (required)--end-index- End position, exclusive (required)
Example:
# Delete characters 10-50
python scripts/google-docs.py content delete 1abc...xyz --start-index 10 --end-index 50
# Output:
# ✓ Content deleted successfullyWarning: Be careful with indices. Deleting the wrong range can corrupt document structure.
formatting apply
Apply text formatting to a range of text.
python scripts/google-docs.py formatting apply DOCUMENT_ID \
--start-index 1 --end-index 20 --bold --italicArguments:
document_id- The Google Docs document ID
Options:
--start-index- Start position, inclusive (required)--end-index- End position, exclusive (required)--bold- Apply bold formatting--italic- Apply italic formatting--underline- Apply underline formatting--font-size SIZE- Set font size in points
Example:
# Make title bold and larger
python scripts/google-docs.py formatting apply 1abc...xyz \
--start-index 1 --end-index 20 --bold --font-size 18
# Apply italic to a section
python scripts/google-docs.py formatting apply 1abc...xyz \
--start-index 50 --end-index 100 --italic
# Output:
# ✓ Formatting applied successfullyExamples
Create and populate a document
# Create a new document
python scripts/google-docs.py documents create --title "Weekly Report"
# Add content
python scripts/google-docs.py content append $DOC_ID --text "Weekly Report\n\n"
python scripts/google-docs.py content append $DOC_ID --text "Summary: This week's accomplishments...\n"
# Format the title
python scripts/google-docs.py formatting apply $DOC_ID --start-index 1 --end-index 14 --bold --font-size 18
# Read it back
python scripts/google-docs.py documents read $DOC_IDRead and extract content
# Get document info
python scripts/google-docs.py documents get 1abc...xyz
# Extract plain text
python scripts/google-docs.py documents read 1abc...xyz > document.txt
# Get document structure
python scripts/google-docs.py documents get 1abc...xyzEdit existing content
# Insert a new section
python scripts/google-docs.py content insert 1abc...xyz \
--text "\n\nNew Section\n" --index 100
# Format the new section header
python scripts/google-docs.py formatting apply 1abc...xyz \
--start-index 102 --end-index 113 --bold
# Append more content
python scripts/google-docs.py content append 1abc...xyz \
--text "Additional details about the new section..."Error Handling
Authentication and scope errors are not retryable. If a command fails with an authentication error, insufficient scope error, or permission denied error (exit code 1), do NOT retry the same command. Instead:
- Inform the user about the error
- Run
python scripts/google-docs.py auth statusto check the current token state - Suggest the user run
python scripts/google-docs.py auth resetfollowed bypython scripts/google-docs.py checkto re-authenticate - The
auth resetandcheckcommands require user interaction (browser-based OAuth consent) and cannot be completed autonomously
Retryable errors: Rate limiting (HTTP 429) and temporary server errors (HTTP 5xx) may succeed on retry after a brief wait. All other errors should be reported to the user.
Model Guidance
This skill makes API calls requiring structured input/output. A standard-capability model is recommended.
Troubleshooting
Authentication failed
- Verify your OAuth client ID and client secret are correct in
~/.config/agent-skills/google-docs.yaml - Token expired or corrupted — reset and re-authenticate:
python scripts/google-docs.py auth reset python scripts/google-docs.py check
Permission denied
Your OAuth token may not have the necessary scopes. Reset your token and re-authenticate:
python scripts/google-docs.py auth reset
python scripts/google-docs.py checkCannot find document
Make sure you're using the correct document ID from the URL:
- URL:
https://docs.google.com/document/d/1abc...xyz/edit - Document ID:
1abc...xyz
Index errors when inserting/deleting
Use documents get to see the document structure and valid index ranges. Remember:
- Index 0 is before any content
- Index 1 is at the start of document body
- The last index is the document length
Dependencies not found
Install required dependencies:
pip install --user google-auth google-auth-oauthlib google-api-python-client keyring pyyamlOAuth flow fails
Ensure your GCP project has:
- Google Docs API enabled (
docs.googleapis.com) - OAuth 2.0 credentials created
- OAuth consent screen configured
- Your email added as a test user (if app is in testing mode)
See docs/gcp-project-setup.md for detailed instructions.
Related Skills
- Google Drive - File management (Drive manages file metadata, Docs manages content)
- Google Sheets - Spreadsheet management
- Google Slides - Presentation management
API Reference
For advanced usage, see: