Skip to main content

Google Docs MCP Server

Create a powerful Model Context Protocol (MCP) server for Google Docs in minutes with our AI Gateway. This guide walks you through setting up seamless document automation with enterprise-grade security and instant OAuth authentication.

About Google Docs API

The Google Docs API enables programmatic creation, editing, and formatting of documents. It provides fine-grained control over document structure, styling, and collaborative features, making it ideal for document automation and content management workflows.

Key Capabilities

  • Document Creation: Generate documents from templates
  • Content Manipulation: Insert, update, and delete text
  • Rich Formatting: Apply styles, fonts, and colors
  • Structural Elements: Headers, lists, tables, images
  • Collaborative Features: Comments, suggestions, revisions
  • Template Management: Create reusable document templates
  • Batch Operations: Multiple edits in single request
  • Export Options: PDF, Word, HTML formats

API Features

  • REST API v1: Document manipulation
  • Real-time Updates: Live document changes
  • Revision History: Track document versions
  • OAuth 2.0: Secure authentication
  • Batch Requests: Efficient operations
  • Rich Text Support: Full formatting control
  • Named Ranges: Reference document sections
  • Merge Fields: Dynamic content insertion

What You Can Do with Google Docs MCP Server

The MCP server transforms Google Docs API into a natural language interface, enabling AI agents to:

Document Creation & Management

  • Document Operations

    • "Create new report from quarterly template"
    • "Generate contract with client details"
    • "Copy document and update for new project"
    • "Create meeting notes template"
  • Batch Creation

    • "Generate 10 personalized letters"
    • "Create individual reports for each team"
    • "Produce certificates for all attendees"
    • "Generate invoices from spreadsheet data"
  • Template Management

    • "Save document as reusable template"
    • "Update company letterhead in templates"
    • "Create template with merge fields"
    • "Clone template for department use"

Content Editing & Formatting

  • Text Operations

    • "Insert executive summary at beginning"
    • "Replace all instances of old company name"
    • "Update date fields to current month"
    • "Append signature block at end"
  • Formatting Control

    • "Format headings as title style"
    • "Apply company brand colors"
    • "Set document to double spacing"
    • "Create numbered list from bullets"
  • Advanced Formatting

    • "Insert page breaks between sections"
    • "Add table of contents"
    • "Create footnotes for references"
    • "Apply conditional formatting"

Tables & Structured Content

  • Table Management

    • "Insert 5x3 table after paragraph 2"
    • "Add row with totals to existing table"
    • "Format table with alternating colors"
    • "Convert list to table format"
  • Data Integration

    • "Import CSV data as table"
    • "Update table from spreadsheet"
    • "Calculate column totals"
    • "Sort table by date column"
  • Table Formatting

    • "Merge header cells"
    • "Set column widths"
    • "Apply borders and shading"
    • "Center align numeric columns"

Images & Media

  • Image Operations

    • "Insert company logo in header"
    • "Add chart from Google Sheets"
    • "Replace placeholder images"
    • "Resize images to fit page"
  • Layout Control

    • "Wrap text around images"
    • "Center align all images"
    • "Create image gallery"
    • "Add captions to figures"
  • Media Management

    • "Update all image links"
    • "Compress images for size"
    • "Convert images to inline"
    • "Extract images from document"

Collaboration Features

  • Comments & Suggestions

    • "Add comment requesting review"
    • "Suggest edit to paragraph 3"
    • "Reply to all open comments"
    • "Resolve completed discussions"
  • Review Workflow

    • "Accept all suggestions"
    • "Reject formatting changes only"
    • "Assign action items in comments"
    • "Export comments to task list"
  • Sharing & Permissions

    • "Share with team as editors"
    • "Create view-only link"
    • "Set expiration for access"
    • "Transfer ownership to manager"

Document Structure

  • Headers & Footers

    • "Add page numbers to footer"
    • "Insert date in header"
    • "Create different first page header"
    • "Add document title to all pages"
  • Sections & Navigation

    • "Create table of contents"
    • "Add bookmarks to sections"
    • "Insert hyperlinks to headings"
    • "Create index of terms"
  • Page Layout

    • "Set margins to 1 inch"
    • "Change to landscape orientation"
    • "Create two-column layout"
    • "Add page borders"

Automation & Integration

  • Mail Merge

    • "Merge contact list into letters"
    • "Generate personalized certificates"
    • "Create name tags from roster"
    • "Produce customized reports"
  • Dynamic Content

    • "Update date fields automatically"
    • "Insert data from API"
    • "Refresh charts from Sheets"
    • "Pull content from database"
  • Workflow Integration

    • "Export to PDF when complete"
    • "Send notification on changes"
    • "Trigger approval workflow"
    • "Archive to Drive folder"

Prerequisites

  • Access to Cequence AI Gateway
  • Google Workspace account
  • Google Docs API enabled
  • Appropriate Drive permissions

Step 1: Enable Google Docs API

1.1 Access Google Cloud Console

  1. Go to console.cloud.google.com
  2. Select or create a project
  3. Enable billing if required

1.2 Enable APIs

  1. Navigate to APIs & Services Library
  2. Search and enable:
    • Google Docs API
    • Google Drive API (required for file operations)

1.3 Create OAuth 2.0 Credentials

  1. Go to APIs & Services Credentials
  2. Click Create Credentials OAuth client ID
  3. Configure consent screen if needed
  4. Application type: Web application
  5. Add redirect URI:
    https://auth.aigateway.cequence.ai/v1/outbound/oauth/callback

1.4 Get Credentials

  1. Copy Client ID
  2. Copy Client Secret
  3. Note authorized redirect URIs

Step 2-4: Standard Setup

Follow standard steps to access AI Gateway, find Google Docs API, and create MCP server.

Step 5: Configure API Endpoints

  1. Base URL: https://docs.googleapis.com/v1
  2. Select endpoints:
    • Document creation endpoints
    • Batch update endpoints
    • Get document endpoints
  3. Click Next

Step 6: MCP Server Configuration

  1. Name: "Google Docs Automation"
  2. Description: "Document creation and editing"
  3. Configure production mode
  4. Click Next

Step 7: Configure Authentication

  1. Authentication Type: OAuth 2.0
  2. Authorization URL:
    https://accounts.google.com/o/oauth2/v2/auth
  3. Token URL:
    https://oauth2.googleapis.com/token
  4. Enter Client ID and Secret
  5. Select required scopes

Available Google Docs OAuth Scopes

Document Access

  • https://www.googleapis.com/auth/documents

    • Full read/write access
    • Create new documents
    • Edit existing documents
    • Delete documents
  • https://www.googleapis.com/auth/documents.readonly

    • Read document content
    • View formatting
    • Access revision history
    • Export documents

Drive Integration

  • https://www.googleapis.com/auth/drive.file

    • Access files created by app
    • Required for document creation
    • Manage document metadata
    • Organize in folders
  • https://www.googleapis.com/auth/drive.readonly

    • List user's documents
    • Search for documents
    • View folder structure
    • Access shared documents

Additional Scopes

  • https://www.googleapis.com/auth/drive.metadata.readonly
    • View document metadata
    • List document properties
    • Check sharing status
    • See revision info

For Document Automation:

https://www.googleapis.com/auth/documents
https://www.googleapis.com/auth/drive.file

For Full Document Management:

https://www.googleapis.com/auth/documents
https://www.googleapis.com/auth/drive

For Read-Only Access:

https://www.googleapis.com/auth/documents.readonly
https://www.googleapis.com/auth/drive.readonly

Step 8-10: Complete Setup

Configure security, choose deployment, and deploy.

Using Your Google Docs MCP Server

With Claude Desktop

{
"servers": {
"google-docs": {
"url": "your-mcp-server-url",
"auth": {
"type": "oauth2",
"client_id": "your-client-id"
}
}
}
}

Natural Language Commands

  • "Create monthly report from template"
  • "Insert table with Q4 sales data"
  • "Format document with company branding"
  • "Add executive summary at beginning"
  • "Export as PDF and share with team"

API Integration Example

// Initialize MCP client
const mcpClient = new MCPClient({
serverUrl: 'your-mcp-server-url',
auth: {
type: 'oauth2',
token: 'access-token'
}
});

// Create document from template
const doc = await mcpClient.googleDocs.create({
title: 'Q4 2025 Sales Report',
body: {
content: [
{
paragraph: {
elements: [
{
textRun: {
content: 'Quarterly Sales Report\n',
textStyle: {
fontSize: { magnitude: 24, unit: 'PT' },
bold: true
}
}
}
],
paragraphStyle: {
alignment: 'CENTER'
}
}
}
]
}
});

// Batch update document
const requests = [
// Insert table
{
insertTable: {
rows: 4,
columns: 3,
location: { index: 50 }
}
},
// Add header row
{
insertText: {
location: { index: 51 },
text: 'Product'
}
},
{
insertText: {
location: { index: 60 },
text: 'Units Sold'
}
},
{
insertText: {
location: { index: 73 },
text: 'Revenue'
}
},
// Format table
{
updateTableCellStyle: {
tableCellStyle: {
backgroundColor: {
color: {
rgbColor: { red: 0.9, green: 0.9, blue: 0.9 }
}
}
},
fields: 'backgroundColor',
tableRange: {
tableCellLocation: {
tableStartLocation: { index: 50 },
rowIndex: 0
},
rowSpan: 1,
columnSpan: 3
}
}
}
];

await mcpClient.googleDocs.batchUpdate({
documentId: doc.documentId,
requests: requests
});

// Insert image
await mcpClient.googleDocs.batchUpdate({
documentId: doc.documentId,
requests: [
{
insertInlineImage: {
location: { index: 150 },
uri: 'https://example.com/chart.png',
objectSize: {
height: { magnitude: 200, unit: 'PT' },
width: { magnitude: 400, unit: 'PT' }
}
}
}
]
});

// Add comment
await mcpClient.googleDocs.batchUpdate({
documentId: doc.documentId,
requests: [
{
createComment: {
comment: {
content: 'Please review these numbers with finance team',
quotedText: 'Q4 Revenue: $1.2M'
}
}
}
]
});

// Export as PDF
const pdfBlob = await mcpClient.googleDocs.export({
documentId: doc.documentId,
mimeType: 'application/pdf'
});

// Create from template with merge
const letters = await mcpClient.googleDocs.mailMerge({
templateId: 'template-doc-id',
data: [
{ name: 'John Doe', amount: '$1,000', date: '2025-01-15' },
{ name: 'Jane Smith', amount: '$2,500', date: '2025-01-15' }
],
fields: ['name', 'amount', 'date']
});

Common Use Cases

Document Automation

  • Report generation
  • Contract creation
  • Letter templates
  • Certificate production

Content Management

  • Blog post drafting
  • Documentation updates
  • Policy management
  • Handbook maintenance

Business Processes

  • Invoice generation
  • Proposal creation
  • Meeting minutes
  • Status reports

Educational Content

  • Worksheet creation
  • Lesson plans
  • Study guides
  • Assessment forms

Security Best Practices

  1. OAuth Security:

    • Use minimal scopes
    • Implement token refresh
    • Monitor access logs
    • Revoke unused tokens
  2. Document Protection:

    • Set appropriate sharing
    • Use view-only where possible
    • Audit document access
    • Enable revision history
  3. Content Security:

    • Validate input data
    • Sanitize merge fields
    • Check image sources
    • Monitor API usage

Troubleshooting

Common Issues

  1. Authentication Errors

    • Verify OAuth credentials
    • Check token expiration
    • Validate redirect URI
    • Review consent screen
  2. Document Errors

    • Check document permissions
    • Verify document exists
    • Validate request syntax
    • Review index positions
  3. Formatting Issues

    • Verify style syntax
    • Check color values
    • Validate font sizes
    • Test in UI first

Getting Help