MCP Server for Gmail & Google Docs
Allows sending emails and creating drafts via Gmail API.
Allows appending content to existing Google Docs.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Server for Gmail & Google Docssend an email to alice@example.com with subject 'Project update'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 |
| Send an email immediately via Gmail |
| Create a draft email (no auto-send) |
| 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_messageRetry logic — exponential backoff on rate limits and server errors
Secure — credentials never logged, secrets gitignored
Related MCP server: Google MCP Server
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.txt3. Configure Environment (Optional)
cp .env.example .env
# Edit .env if you need custom pathsVariable | Default | Description |
|
| Path to OAuth client secrets |
|
| Path to cached token |
|
| Logging level |
4. First Run (OAuth Consent)
python -m src.serverOn 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.serverThe 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=srcArchitecture
[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 testsLicense
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organiz…
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to send emails via Gmail and append text to Google Docs or local files.-
- FlicenseNot gradedqualityDmaintenanceEnables interaction with Google Docs and Gmail, allowing users to append text to documents and create email drafts with explicit approval prompts.-
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to send emails and append content to Google Docs using Gmail and Google Docs APIs.-
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to send emails via Gmail and append content to Google Docs.339 npmMIT