ftaricano/mcp-gmail-calendar
If you are the rightful owner of mcp-gmail-calendar and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Gmail & Google Calendar MCP Server is a professional server designed to manage Gmail and Google Calendar with advanced features and multi-account support.
Gmail & Google Calendar MCP Server
Professional MCP (Model Context Protocol) server for Gmail and Google Calendar with comprehensive multi-account support, advanced email templates, and full calendar management capabilities.
Features
🔐 Multi-Account Authentication
- OAuth2 Integration: Secure Google OAuth2 authentication
- Multiple Accounts: Support for personal Gmail and Google Workspace accounts
- Account Management: Easy switching between authenticated accounts
- Token Management: Automatic token refresh and secure storage
📧 Gmail Management
- Email Operations: List, read, send, reply, forward, delete emails
- Advanced Search: Full Gmail search query support
- Label Management: Create, apply, and manage Gmail labels
- Batch Operations: Perform operations on multiple emails
- Smart Filtering: Filter by labels, dates, senders, and more
🎨 Professional Email Templates
- Built-in Themes: Professional, Modern, Minimal, Corporate
- Custom Templates: Create and manage custom HTML templates
- Handlebars Engine: Dynamic content with template variables
- CSS Inlining: Automatic CSS inlining for email client compatibility
- Responsive Design: Mobile-friendly email layouts
📎 Attachment Handling
- Upload/Download: Full attachment management
- Security Scanning: Automatic file type and size validation
- Base64 Support: Direct base64 content handling
- Storage Management: Temporary attachment storage with cleanup
📅 Google Calendar Integration
- Event Management: Create, read, update, delete calendar events
- Multi-Calendar: Support for multiple calendars per account
- Meeting Scheduling: Conference call integration (Google Meet)
- Availability Checking: Free/busy time queries
- Recurring Events: Support for recurring event patterns
- Invitation Responses: Accept, decline, tentative responses
⚡ Advanced Features
- Caching System: Intelligent caching for better performance
- Error Recovery: Robust error handling and retry logic
- Logging System: Comprehensive logging with Winston
- Input Validation: Schema validation with Zod
- Security First: HTML sanitization and attachment scanning
Installation
Prerequisites
- Node.js 18+ and npm
- Google Cloud Project with Gmail API and Calendar API enabled
- OAuth2 credentials (Desktop application type)
Setup Steps
- Clone and Install:
git clone <repository-url>
cd mcp-gmail-calendar
npm install
-
Create Google Cloud Project:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API and Google Calendar API
- Create OAuth2 credentials (Desktop application type)
- Download credentials JSON file
-
Configure Environment:
cp .env.example .env
Edit .env
file:
# Path to your Google OAuth2 credentials JSON file
GOOGLE_CREDENTIALS_PATH=./credentials.json
# OAuth callback port
OAUTH_CALLBACK_PORT=3000
# Storage paths
TOKENS_PATH=./tokens
TEMPLATE_PATH=./templates
LOG_FILE_PATH=./logs/mcp-gmail-calendar.log
# Limits
MAX_EMAIL_RESULTS=50
MAX_ATTACHMENT_SIZE=25000000
MAX_CALENDAR_EVENTS=100
# Default settings
DEFAULT_CALENDAR_TIMEZONE=America/New_York
DEFAULT_EMAIL_THEME=professional
LOG_LEVEL=info
-
Place Credentials:
- Save your Google OAuth2 credentials as
credentials.json
in the project root - Or update
GOOGLE_CREDENTIALS_PATH
in your.env
file
- Save your Google OAuth2 credentials as
-
Build and Start:
npm run build
npm start
Development Mode
npm run dev
Configuration
MCP Client Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"gmail-calendar": {
"command": "node",
"args": ["/path/to/mcp-gmail-calendar/dist/index.js"],
"env": {
"GOOGLE_CREDENTIALS_PATH": "/path/to/your/credentials.json"
}
}
}
}
Google Cloud Console Setup
-
Create Project: https://console.cloud.google.com/
-
Enable APIs:
-
Create OAuth2 Credentials:
- Go to "Credentials" → "Create Credentials" → "OAuth client ID"
- Application type: "Desktop application"
- Name: "MCP Gmail Calendar Server"
- Download JSON file
-
Configure OAuth Consent Screen:
- Add your email as a test user
- Configure app information and scopes
Usage
Account Management
Authenticate Account
{
"name": "authenticate",
"arguments": {
"email": "user@gmail.com",
"accountType": "personal"
}
}
List Accounts
{
"name": "list_accounts",
"arguments": {}
}
Switch Account
{
"name": "switch_account",
"arguments": {
"email": "work@company.com"
}
}
Email Operations
Send Email with Template
{
"name": "email_send",
"arguments": {
"to": ["recipient@example.com"],
"subject": "Professional Email",
"templateId": "professional_basic",
"templateData": {
"recipientName": "John Doe",
"emailTitle": "Important Update",
"content": "<h2>Hello!</h2><p>This is a professional email.</p>",
"senderName": "Jane Smith",
"companyName": "Acme Corp"
}
}
}
List Emails with Search
{
"name": "email_list",
"arguments": {
"maxResults": 20,
"query": "from:important@company.com has:attachment"
}
}
Reply to Email
{
"name": "email_reply",
"arguments": {
"messageId": "thread_abc123",
"bodyHtml": "<p>Thank you for your message!</p>",
"templateId": "minimal_personal"
}
}
Calendar Operations
Create Event
{
"name": "event_create",
"arguments": {
"event": {
"summary": "Team Meeting",
"description": "Weekly team sync",
"location": "Conference Room A",
"start": {
"dateTime": "2024-01-15T10:00:00-05:00",
"timeZone": "America/New_York"
},
"end": {
"dateTime": "2024-01-15T11:00:00-05:00",
"timeZone": "America/New_York"
},
"attendees": [
{"email": "team@company.com"},
{"email": "manager@company.com"}
],
"reminders": {
"useDefault": false,
"overrides": [
{"method": "popup", "minutes": 10},
{"method": "email", "minutes": 60}
]
}
}
}
}
Get Upcoming Events
{
"name": "event_upcoming",
"arguments": {
"maxResults": 10,
"daysAhead": 7
}
}
Check Availability
{
"name": "calendar_get_availability",
"arguments": {
"timeMin": "2024-01-15T09:00:00Z",
"timeMax": "2024-01-15T17:00:00Z",
"items": [
{"id": "primary"},
{"id": "work@company.com"}
]
}
}
Template Management
List Templates
{
"name": "template_list",
"arguments": {}
}
Create Custom Template
{
"name": "template_create",
"arguments": {
"name": "Company Newsletter",
"description": "Monthly company newsletter template",
"category": "marketing",
"theme": "modern",
"content": "<html>...</html>"
}
}
Email Templates
Built-in Templates
-
Professional Basic (
professional_basic
):- Clean business communication
- Company branding support
- Call-to-action buttons
-
Modern Notification (
modern_notification
):- Contemporary design
- Alert/notification styling
- Gradient backgrounds
-
Minimal Personal (
minimal_personal
):- Simple, clean design
- Personal correspondence
- Typography-focused
-
Corporate Formal (
corporate_formal
):- Formal business template
- Company letterhead
- Legal disclaimers
Template Variables
Common variables available in all templates:
recipientName
: Recipient's namesenderName
: Sender's namecompanyName
: Company/organization namelogoUrl
: Company logo URLemailTitle
: Main email titlecontent
: Main email content (HTML)signature
: Custom signatureactionUrl
: Call-to-action URLactionText
: Call-to-action button text
Custom Templates
Create custom templates using Handlebars syntax:
<!DOCTYPE html>
<html>
<head>
<title>{{emailTitle}}</title>
</head>
<body>
<h1>{{emailTitle}}</h1>
{{#if recipientName}}
<p>Dear {{recipientName}},</p>
{{/if}}
{{{content}}}
{{#if actionUrl}}
<a href="{{actionUrl}}" style="...">
{{default actionText "Learn More"}}
</a>
{{/if}}
<p>Best regards,<br>{{senderName}}</p>
</body>
</html>
API Reference
Account Tools
authenticate
- Authenticate Google accountlist_accounts
- List authenticated accountsswitch_account
- Switch active accountremove_account
- Remove accountget_current_account
- Get current account info
Email Tools
email_list
- List emailsemail_read
- Read emailemail_send
- Send emailemail_reply
- Reply to emailemail_forward
- Forward emailemail_delete
- Delete emailemail_mark_read
- Mark as reademail_mark_unread
- Mark as unreademail_search
- Search emailsemail_move
- Move emailemail_label
- Add labelemail_create_label
- Create labelemail_list_labels
- List labelsemail_batch_operations
- Batch operations
Attachment Tools
email_list_attachments
- List attachmentsemail_download_attachment
- Download attachmentemail_upload_attachment
- Upload attachment
Calendar Tools
calendar_list
- List calendarsevent_list
- List eventsevent_get
- Get eventevent_create
- Create eventevent_update
- Update eventevent_delete
- Delete eventcalendar_get_availability
- Get availabilityevent_respond
- Respond to invitationevent_search
- Search eventsevent_quick_add
- Quick add eventevent_upcoming
- Get upcoming events
Template Tools
template_list
- List templatestemplate_render
- Render templatetemplate_create
- Create template
Security
Authentication Security
- OAuth2 flow with PKCE (recommended by Google)
- Secure token storage with refresh token rotation
- Account isolation and permission scoping
Email Security
- HTML content sanitization
- Attachment type and size validation
- Executable file detection and blocking
- XSS protection in email content
Data Protection
- No email content stored permanently
- Secure credential management
- Audit logging for all operations
- Rate limiting and quota management
Troubleshooting
Common Issues
Authentication Fails
- Verify credentials.json file is valid
- Check OAuth consent screen configuration
- Ensure APIs are enabled in Google Cloud Console
- Confirm redirect URI is
http://localhost:3000/oauth2callback
Email Sending Fails
- Check Gmail API quota limits
- Verify email addresses are valid
- Ensure account has sending permissions
- Check for attachment size limits
Calendar Events Not Created
- Verify Calendar API is enabled
- Check calendar permissions
- Ensure date/time formats are valid (RFC3339)
- Confirm time zone settings
Template Rendering Issues
- Validate Handlebars syntax
- Check required template variables
- Verify HTML structure
- Test with minimal template first
Debug Mode
Enable debug logging:
LOG_LEVEL=debug
View logs:
tail -f ./logs/mcp-gmail-calendar.log
Support
For issues and questions:
- Check the troubleshooting section
- Review Google API documentation
- Enable debug logging
- Check server logs for specific errors
Contributing
- Fork the repository
- Create feature branch
- Make changes with tests
- Submit pull request
License
MIT License - see LICENSE file for details.
Changelog
v1.0.0
- Initial release
- Multi-account OAuth2 authentication
- Complete Gmail email management
- Google Calendar integration
- Professional email templates
- Attachment handling
- Comprehensive error handling
- Security features