Enables AI assistants to interact with Gmail accounts, providing tools for fetching unread emails, creating threaded draft replies, marking emails as read/unread, and deleting emails.
Provides real-time availability checking via Google Calendar API to automatically propose meeting times when scheduling replies, following calendar-integrated meeting coordination protocols.
Requires Google Cloud Project setup with OAuth2 configuration to enable Gmail API access and authentication for email management capabilities.
Optionally fetches email writing guidelines and templates directly from Google Docs for centralized, collaborative documentation management with automatic fallback to local files.
๐ฌ๏ธ Gmail MCP Server
Overview
This project is a Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Gmail accounts. This server provides tools for reading unread emails and creating draft replies, allowing seamless email management through natural language conversations.
Built for: MCP Foundation Project Assessment
Tech Stack: Python 3.11+, Python MCP SDK, Gmail API, OAuth2
Target: Claude Desktop Integration (compatible with any MCP client)
Core Features
Email Retrieval: Fetch unread emails from Gmail.
Draft Creation: Create draft replies for selected emails.
Message Management: Mark emails as read or unread, delete emails.
AI-Assisted Email Drafting: Professional writing guidelines and templates via MCP resources and prompts.
Google Docs Integration: Optionally fetch email guidelines from Google Docs for centralized management.
MCP Capabilities
Tools
get_unread_emails: Returns sender, subject, body/snippet, and email/thread IDcreate_draft_reply: Creates correctly threaded draft replies from original email/thread ID and reply body
Resources
file:///email-guidelines/7cs-communication.md: The 7 Cs of Effective Communication frameworkfile:///email-guidelines/personal-templates.md: 11 personal email templates for common tasksfile:///email-guidelines/ai-drafting-directive.md: Comprehensive AI email drafting directive with persona and persuasion tactics
Stretch Goals
1. Professional Writing Framework via MCP Resources
Exposed three comprehensive resources that Claude can access when drafting emails:
7 Cs of Communication (
file:///email-guidelines/7cs-communication.md)Professional framework ensuring emails are: Clear, Concise, Correct, Coherent, Complete, Courteous, and Concrete
Automatically applied when using the
draft_professional_replyprompt
Personal Email Templates (
file:///email-guidelines/personal-templates.md)11 ready-to-use templates for common scenarios (appointments, quotes, neighbor communications, etc.)
Accessible via the
suggest_templateprompt with AI-powered matching
AI Drafting Directive (
file:///email-guidelines/ai-drafting-directive.md)Incorporates principles from Dale Carnegie, Robert Cialdini, and Stephen Covey
Defines persona, tone mapping, and ethical persuasion tactics
Ensures consistent voice across all communications
2. Advanced MCP Prompts with Prompt Engineering
Implemented three sophisticated prompts demonstrating different prompt engineering techniques:
Prompt | Technique | Purpose |
| Chain of Thought | 7-step reasoning process for professional emails |
| Contextual Prompting | Calendar-integrated meeting scheduling |
| Few-Shot Learning | AI-powered template matching with confidence scoring |
3. Google Docs Integration (Optional)
Fetch email guidelines directly from Google Docs for centralized, team-shareable documentation
Automatic fallback to local markdown files if Google Docs unavailable
Supports collaborative guideline updates without code changes
Configurable via
settings.tomlwith document IDs
4. Google Calendar Integration (Optional)
Real-time availability checking via Google Calendar API
The
schedule_meeting_replyprompt automatically proposes times when you're actually freeFollows the "always offer 2 time slot options" protocol from the AI directive
Impact: These enhancements transform basic email drafting into a sophisticated, context-aware system that maintains professional standards and personal voice while saving time.
Project Milestones
Core Requirements
Gmail API Setup: Google Cloud project, OAuth2 configuration, scopes
MCP Server: Python implementation with mcp SDK
Authorization: OAuth2 authentication for Gmail API
Email Retrieval Tool:
get_unread_emailswith required fieldsDraft Reply Tool:
create_draft_replywith threadingClaude Desktop Integration: Local server configuration and testing
Documentation: Setup instructions, example prompts, screenshots
Quick Start
Prerequisites
Python 3.11+
Google Cloud Project with Gmail API enabled
OAuth2 credentials (not app passwords)
Claude Desktop
Gmail API Setup
Create Google Cloud Project
Enable Gmail API
Configure OAuth2 (scopes: gmail.readonly, gmail.compose)
Download credentials.json
Claude Desktop Configuration
Step 1: Locate Your Config File
The config file location depends on your operating system:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%/Claude/claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Step 2: Add MCP Server Configuration
Add this to your claude_desktop_config.json file:
Important: Replace the paths with your actual absolute paths:
Find your project directory:
pwd(when in the gmail-mcp directory)Update both the
commandpath (to Python in .venv) andargspath (to main.py)
Example (macOS):
Example (Windows):
Step 3: Restart and Authenticate
Save the config file
Restart Claude Desktop completely (quit and reopen)
Verify connection: Look for the ๐ icon in Claude Desktop indicating MCP servers are connected
First-time authentication: On first use, a browser window will open asking you to:
Sign in to your Google account
Grant permissions for Gmail read and compose access
The server will save a
token.jsonfile in thecredentials/directory
Troubleshooting
Server not connecting?
Verify paths are absolute (not relative like
~/or./)Check Python virtual environment is activated and dependencies installed
Look at Claude Desktop logs:
~/Library/Logs/Claude/mcp*.log(macOS)
Authentication failing?
Ensure
credentials.jsonis in thecredentials/directoryDelete
credentials/token.jsonand retry to re-authenticateVerify Gmail API is enabled in Google Cloud Console
Check OAuth scopes include
gmail.readonlyandgmail.compose
Server crashes on startup?
Run manually to see errors:
.venv/bin/python main.pyCheck all dependencies installed:
uv sync
Email Writing Guidelines (MCP Resources)
This server exposes comprehensive email writing guidelines as MCP resources. Claude can access these when drafting emails to ensure professional, consistent communication.
Available Resources
Three resources are available at fixed URIs:
file:///email-guidelines/7cs-communication.md- The 7 Cs of Effective CommunicationFramework for professional emails (Clarity, Conciseness, Correctness, Coherence, Completeness, Courtesy, Concreteness)
Ensures all emails meet professional standards
file:///email-guidelines/personal-templates.md- Personal Email Templates11 templates for common personal tasks (appointments, quotes, birthday wishes, neighbor communications, etc.)
Ready-to-use formats for everyday email scenarios
file:///email-guidelines/ai-drafting-directive.md- AI Email Drafting DirectiveComprehensive guidelines incorporating Dale Carnegie, Robert Cialdini, and Stephen Covey principles
Persona definition, tone mapping by category, ethical persuasion tactics
How Resources Work
Claude Desktop automatically makes these resources available to Claude when the MCP server is connected. Claude can:
Access automatically - Resources are discoverable through the MCP protocol
Reference when needed - Claude can read resources to understand your email writing standards
Apply guidelines - Use the 7 Cs framework and templates when drafting replies
Using Resources
Simply ask Claude to draft emails - the resources are available automatically:
Or explicitly reference specific resources:
Optional: Google Docs Integration
By default, resources are read from local markdown files in the docs/ directory. You can optionally configure the server to fetch these from Google Docs instead.
Why use Google Docs?
Centralized, shareable guidelines
Update without modifying code
Collaborate with team members
Version history
Setup:
Upload your three guideline documents to Google Docs
Get document IDs from URLs:
https://docs.google.com/document/d/YOUR_DOCUMENT_ID/editConfigure in
src/gmail_mcp_server/configs/settings.toml:[default.google_docs] 7cs_doc_id = "YOUR_7CS_DOCUMENT_ID" templates_doc_id = "YOUR_TEMPLATES_DOCUMENT_ID" directive_doc_id = "YOUR_DIRECTIVE_DOCUMENT_ID"Add Google Docs scope to settings.toml:
google_scopes = [ "https://www.googleapis.com/auth/calendar.calendarlist.readonly", "https://www.googleapis.com/auth/calendar.events.freebusy", "https://www.googleapis.com/auth/drive.readonly", "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.compose" ]Delete
credentials/token.jsonand restart server to re-authenticate
Fallback: If Google Docs fetch fails, the server automatically falls back to local files.
Local Development
Setup
Clone the repository
Install dependencies:
uv installConfigure your Gmail API credentials (see docs/gcp-setup.md)
Run the server:
uv run gmail-mcp-server
Testing with MCP Inspector
For debugging and testing:
Sample Prompts
Prompt 1: Read and Summarize Unread Emails
Prompt 2: Draft Reply with Guidelines
Prompt 3: Use Personal Email Template
Prompt 4: Draft Reply Following All Guidelines
Note: After drafting, check your Gmail drafts folder to review before sending.
For more example prompts, see docs/example-prompts.md
Demo Video
Watch the Gmail MCP Server in action:
https://github.com/user-attachments/assets/demo_mcp.mov
The demo shows:
Getting unread emails from Gmail
Creating draft replies with threading
Screenshots
MCP Server Connected in Claude Desktop

Fetching Unread Emails

Drafting Professional Reply with 7 Cs Framework

Using Personal Email Templates

MCP Prompts in Action

Draft Reply Created in Gmail

MCP Prompts
This server provides three sophisticated prompts that leverage advanced prompt engineering techniques:
1. draft_professional_reply - Multi-Step Chain + Role Prompting
Purpose: Generate professional email replies following the 7 Cs framework and your personal AI directive using chain of thought reasoning.
Arguments:
thread_id(required): The email thread ID to reply tokey_points(optional): Key points to include in the replytone(optional): Desired tone - formal, professional, or friendly (default: professional)
Prompt Engineering Technique: Chain of Thought
7-step reasoning process from context retrieval to draft creation
Applies consistent persona from AI directive
Validates against 7 Cs checklist
UK English formatting
Example Usage:
2. schedule_meeting_reply - Contextual + Calendar Integration
Purpose: Draft meeting acceptance or proposal with real-time calendar availability context.
Arguments:
thread_id(required): The meeting request email thread IDdate_range_start(required): Start date for availability check (ISO format: YYYY-MM-DD)date_range_end(required): End date for availability check (ISO format: YYYY-MM-DD)proposed_times(optional): Optional specific times to propose
Prompt Engineering Technique: Contextual Prompting
Integrates live calendar availability data
Enforces AI directive's "2 time slots" scheduling protocol
UK date/time format with timezone (BST/GMT)
Contextual reasoning based on meeting request
Example Usage:
3. suggest_template - Few-Shot Learning
Purpose: Analyze an email and suggest the most appropriate personal template from your collection of 11 templates.
Arguments:
thread_id(required): The email thread ID to analyze
Prompt Engineering Technique: Few-Shot Learning
Pattern matching against 11 personal templates
Confidence scoring (0-100%)
Explains reasoning for template selection
Shows customization fields needed
Provides populated template preview
Example Usage:
Resource Usage Matrix
Prompt | 7 Cs Framework | Email Templates | AI Directive | Calendar Availability |
draft_professional_reply | โ Yes | โ Yes (optional) | โ Yes | โ No |
schedule_meeting_reply | โ Yes | โ No | โ Yes | โ Yes |
suggest_template | โ No | โ Yes | โ No | โ No |
Summary:
All prompts access at least 2 resources
draft_professional_replyuses 3 resources (7 Cs, AI directive, optionally templates)schedule_meeting_replyuses 3 resources (7 Cs, AI directive, calendar availability)suggest_templateuses 1 primary resource (email templates)
Project Status: ๐งช Testing
All core requirements and stretch goals have been successfully implemented and tested.