MCP Server for Gmail & Google Docs
Enables sending and drafting emails via Gmail and appending content to Google Docs through natural language commands.
README
MCP Server for Gmail & Google Docs
A standalone Model Context Protocol (MCP) server that exposes tools for sending/drafting emails via Gmail and appending content to Google Docs. Built with the official MCP Python SDK using FastMCP.
Features
| Tool | Description |
|---|---|
gmail_send_email |
Send an email immediately via Gmail |
gmail_create_draft |
Create a draft email (no auto-send) |
gdoc_append_content |
Append text to an existing Google Doc |
- Generic & reusable — works with any MCP-compatible client
- OAuth 2.0 — browser-based consent flow, auto-refresh tokens
- Structured responses — always returns
status+ IDs orerror_message - Retry logic — exponential backoff on rate limits and server errors
- Secure — credentials never logged, secrets gitignored
Prerequisites
- Python 3.10+
- Google Cloud project with Gmail API and Google Docs API enabled
- OAuth credentials (
credentials.json) downloaded from Google Cloud Console
Setup
1. Google Cloud Configuration
- Go to Google Cloud Console
- Create a new project (or select an existing one)
- Navigate to APIs & Services > Library
- Enable Gmail API and Google Docs API
- Go to APIs & Services > OAuth consent screen
- Set up the consent screen
- Add your email as a test user
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Desktop app
- Download the JSON file and save it as
credentials.jsonin the project root
2. Install Dependencies
pip install -r requirements.txt
3. Configure Environment (Optional)
cp .env.example .env
# Edit .env if you need custom paths
| Variable | Default | Description |
|---|---|---|
GOOGLE_CREDENTIALS_PATH |
./credentials.json |
Path to OAuth client secrets |
GOOGLE_TOKEN_PATH |
./token.json |
Path to cached token |
LOG_LEVEL |
INFO |
Logging level |
4. First Run (OAuth Consent)
python -m src.server
On the first run, a browser window will open asking you to authorize the app. After granting access, a token.json file will be created and future runs will not require re-authorization.
Usage
Running the Server
python -m src.server
The server communicates over stdio using the MCP protocol.
Connecting from an MCP Client
Antigravity / Claude Desktop
Add to your MCP client configuration:
{
"mcpServers": {
"google-workspace": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/MCP-SERVER"
}
}
}
Tool Schemas
gmail_send_email
{
"to": "recipient@example.com",
"subject": "Hello from MCP",
"body": "This is a test email.",
"cc": ["cc@example.com"],
"bcc": ["bcc@example.com"],
"body_type": "text"
}
Response (success):
{"status": "success", "message_id": "18a1b2c3d4e5f6"}
gmail_create_draft
Same input schema as gmail_send_email.
Response (success):
{"status": "success", "draft_id": "r123456789"}
gdoc_append_content
{
"document_id": "1AbCdEfGhIjKlMnOpQrStUvWxYz",
"content": "Text to append at the end of the document.",
"add_newline_before": true
}
Response (success):
{"status": "success", "document_id": "1AbCdEfGhIjKlMnOpQrStUvWxYz", "revision_id": "ALm37BWx..."}
Error Response (all tools)
{"status": "error", "error_message": "Document not found: bad_id_123"}
Testing
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=src
Architecture
[Any MCP Client]
|
| MCP protocol (stdio)
v
[MCP Server: google-workspace]
├── server.py → Tool definitions + input validation
├── auth.py → OAuth2 token management + refresh
├── gmail_client.py → Gmail API (send, draft)
├── gdoc_client.py → Docs API (append)
└── config.py → Environment configuration
|
v
[Google Workspace APIs]
Project Structure
MCP-SERVER/
├── requirements.txt # Python dependencies
├── .env.example # Environment variable template
├── .gitignore # Secrets & cache exclusions
├── README.md # This file
├── credentials.json # (user-provided, gitignored)
├── token.json # (auto-generated, gitignored)
├── src/
│ ├── __init__.py
│ ├── server.py # FastMCP server + tools
│ ├── auth.py # OAuth2 authentication
│ ├── gmail_client.py # Gmail API wrapper
│ ├── gdoc_client.py # Google Docs API wrapper
│ └── config.py # Configuration loading
└── tests/
├── __init__.py
├── test_server.py # Tool + validation tests
├── test_gmail_client.py # Gmail client tests
└── test_gdoc_client.py # Docs client tests
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。