MCP Server for Gmail & Google Docs

MCP Server for Gmail & Google Docs

Enables sending and drafting emails via Gmail and appending content to Google Docs through natural language commands.

Category
Visit Server

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 or error_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

  1. Go to Google Cloud Console
  2. Create a new project (or select an existing one)
  3. Navigate to APIs & Services > Library
  4. Enable Gmail API and Google Docs API
  5. Go to APIs & Services > OAuth consent screen
    • Set up the consent screen
    • Add your email as a test user
  6. Go to APIs & Services > Credentials
    • Click Create Credentials > OAuth client ID
    • Select Desktop app
    • Download the JSON file and save it as credentials.json in 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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured