Google Workspace MCP Server
Enables Claude Code to interact with Google Workspace services (Drive, Docs, Sheets, Slides, Forms, Gmail) via OAuth 2.0 authentication and natural language commands.
README
Google Workspace MCP Server
A Model Context Protocol server for seamless integration between Claude Code and Google Workspace services.
Features
✅ Complete Google Workspace Integration
- Google Drive: Full file management (search, read, create, update, delete, upload/download)
- Google Docs: Document creation, reading, and editing
- Google Sheets: Spreadsheet operations with range updates and batch processing
- Google Slides: Presentation management and slide manipulation
- Google Forms: Form creation, editing, and response collection
- Gmail: Email search, read, send, reply, and label management
🔒 Secure Authentication
- OAuth 2.0 authentication with automatic token refresh
- Encrypted token storage
- Minimal scope requirements
⚡ Performance Optimized
- Async/await architecture for concurrent operations
- Built-in caching with TTL
- Smart rate limiting to prevent API quota exhaustion
- Request batching where possible
🛡️ Robust Error Handling
- Comprehensive error management
- Automatic retry logic for transient failures
- Detailed error messages for debugging
Installation
Prerequisites
- Python 3.10 or higher
- Google Cloud Project with Workspace APIs enabled
- OAuth 2.0 credentials
Step 1: Clone and Setup
# Clone the repository
git clone https://github.com/YOUR_USERNAME/google-workspace-mcp.git
cd google-workspace-mcp
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
pip install -e .
# Create config directory
mkdir -p config
Step 2: Google Cloud Console Setup
-
Go to Google Cloud Console
-
Create a new project or select existing one
-
Enable the following APIs:
- Google Drive API
- Google Docs API
- Google Sheets API
- Google Slides API
- Google Forms API
- Gmail API
-
Configure OAuth Consent Screen:
- Go to "APIs & Services" > "OAuth consent screen"
- Choose "External" user type
- Fill in required fields (App name, User support email, Developer contact)
- Add scopes:
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/documentshttps://www.googleapis.com/auth/spreadsheetshttps://www.googleapis.com/auth/presentationshttps://www.googleapis.com/auth/formshttps://www.googleapis.com/auth/gmail.modify
-
Create OAuth 2.0 Client ID:
- Go to "Credentials" > "Create Credentials" > "OAuth client ID"
- Choose "Desktop app" as application type
- Download credentials JSON file
- Copy
config/credentials.json.exampletoconfig/credentials.json - Replace the example values with your downloaded credentials
Step 3: Initial Authentication
# Run server for first-time authentication
python3 -m google_workspace_mcp
# Browser will open for OAuth consent
# Grant necessary permissions
# Token will be saved automatically
Step 4: Claude Code Integration
Add to your Claude Code MCP settings (~/.claude/config/settings.json):
{
"mcpServers": {
"google-workspace": {
"command": "/usr/local/bin/python3",
"args": ["-m", "google_workspace_mcp"],
"cwd": "/path/to/your/google-workspace-mcp",
"env": {}
}
}
}
Note: Replace /path/to/your/google-workspace-mcp with your actual installation path.
Available Tools
Google Drive (8 tools)
drive_search_files- Search files/foldersdrive_read_file- Read file contentdrive_create_file- Create new filedrive_update_file- Update existing filedrive_delete_file- Delete filedrive_upload_file- Upload local filedrive_download_file- Download to localdrive_list_shared_drives- List Team Drives
Google Docs (4 tools)
docs_create- Create documentdocs_read- Read documentdocs_update- Update documentdocs_delete- Delete document
Google Sheets (4 tools)
sheets_create- Create spreadsheetsheets_read- Read rangesheets_update- Update rangesheets_delete- Delete spreadsheet
Google Slides (4 tools)
slides_create- Create presentationslides_read- Read presentationslides_update- Update slidesslides_delete- Delete presentation
Google Forms (5 tools)
forms_create- Create formforms_read- Read form structureforms_update- Update formforms_delete- Delete formforms_get_responses- Get form responses
Gmail (6 tools)
gmail_search_messages- Search emailsgmail_read_message- Read email contentgmail_send_message- Send new emailgmail_reply_message- Reply to emailgmail_delete_message- Delete emailgmail_list_labels- List labels
Usage Examples
Search Drive Files
In Claude Code:
"Search my Drive for files named 'project report'"
Uses: drive_search_files with query parameter
Read and Summarize Document
"Read the document with ID xyz and summarize it"
Uses: drive_read_file → Processes content
Send Email
"Send an email to team@example.com with subject 'Meeting Update' and body '...'"
Uses: gmail_send_message
Create Spreadsheet
"Create a new spreadsheet called 'Q4 Budget' with headers A1:E1"
Uses: sheets_create → sheets_update
Configuration
Environment Variables
# Optional: Custom config directory
export GW_MCP_CONFIG_DIR=~/.config/gw-mcp
# Optional: Log level
export GW_MCP_LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR
Cache Settings
Default cache TTL: 300 seconds (5 minutes) Max cache size: 1000 items
Rate Limiting
Default limits:
- 100 requests per 60 seconds per service
- Burst limit: 10 consecutive requests
Troubleshooting
Authentication Issues
# Clear stored tokens
rm ~/.config/gw-mcp/token.pickle
# Re-authenticate
python3 -m google_workspace_mcp
Permission Errors
- Verify all required APIs are enabled in Google Cloud Console
- Check OAuth scopes in consent screen configuration
- Ensure credentials.json is in correct location
Rate Limit Errors
- Server automatically handles rate limiting with exponential backoff
- Check Google Cloud Console quotas if persistent issues
Import Errors
# Reinstall dependencies
pip install -r requirements.txt --force-reinstall
Development
Running Tests
pytest tests/
pytest tests/ --cov=src --cov-report=html
Project Structure
google-workspace-mcp/
├── src/
│ ├── auth/ # OAuth authentication
│ ├── services/ # Google API wrappers
│ ├── tools/ # MCP tool definitions
│ ├── utils/ # Utilities (logging, caching, etc.)
│ └── server.py # Main MCP server
├── config/ # Configuration files
├── tests/ # Test suite
├── requirements.txt # Dependencies
├── setup.py # Package setup
└── README.md # This file
Architecture
Claude Code (MCP Client)
↓
MCP Protocol (stdio)
↓
Google Workspace MCP Server
├── MCP Handler (Tool Registry)
├── Service Layer (API Wrappers)
│ ├── Drive Service
│ ├── Docs Service
│ ├── Sheets Service
│ ├── Slides Service
│ ├── Forms Service
│ └── Gmail Service
├── Auth Manager (OAuth 2.0)
└── Infrastructure (Cache, Rate Limit, Logging)
↓
Google Workspace APIs
Security Considerations
- Token Storage: Tokens encrypted and stored securely in user config directory
- Scope Minimization: Only requests necessary permissions
- No Credential Logging: Sensitive data never logged
- Automatic Token Refresh: Expired tokens refreshed automatically
- Rate Limiting: Prevents quota exhaustion and API abuse
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
License
MIT License - see LICENSE file for details
Support
For issues and questions:
- Open an issue on GitHub
- Check troubleshooting section
- Review Google Workspace API documentation
Acknowledgments
- Built with MCP Python SDK
- Uses Google API Python Client
- Designed for Claude Code
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。