gmail-mcp
Enables Gmail operations via IMAP/SMTP with app password authentication, including sending, reading, searching, and managing labels.
README
Gmail MCP
A Model Context Protocol (MCP) server for Gmail operations using IMAP/SMTP with app password authentication.
Features
Email Management
- listMessages: List the last 10 messages (or more if specified)
- listUnread: List unread messages (default: last 10)
- findMessage: Search for messages containing specific words or phrases (supports folder search:
in:sent,in:trash, etc.) - sendMessage: Send emails with HTML formatting and multiple CC/BCC recipients
- markAsRead: Mark messages (by ID) as read
- deleteMessage: Delete messages (move to Trash)
Label Management
- listLabels: List all available labels in your mailbox
- createLabel: Create a new label (supports sub-labels like
Parent/Child) - renameLabel: Rename an existing label
- moveLabel: Move a label to nest it under another parent label
- deleteLabel: Delete a label
- moveMessage: Move a message to a different label/folder
- labelMessage: Apply labels to a message
Simple Setup (No OAuth Required!)
1. Gmail App Password Setup
- Enable 2-Factor Authentication on your Gmail account
- Go to Google Account Settings → Security → App passwords
- Generate an App password for "Mail"
- Copy the 16-character app password
2. Local Development
-
Install dependencies:
npm install -
Create a
.envfile:EMAIL_ADDRESS=your_email@gmail.com EMAIL_PASSWORD=your_16_char_app_password IMAP_HOST=imap.gmail.com IMAP_PORT=993 SMTP_HOST=smtp.gmail.com SMTP_PORT=587 -
Build and start:
npm run build npm start
3. Docker Usage
-
Create your
.envfile (as above) -
Build and run:
npm run docker:build docker run --rm -i --env-file .env gmail-mcp
MCP Client Integration
Simple Docker Configuration
Add this to your MCP client settings:
{
"mcpServers": {
"email": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"--env-file", ".env",
"gmail-mcp"
]
}
}
}
Using with Docker Compose
{
"mcpServers": {
"email": {
"command": "docker-compose",
"args": ["run", "--rm", "gmail-mcp"]
}
}
}
Supported Email Providers
Gmail (Default)
- IMAP:
imap.gmail.com:993(SSL) - SMTP:
smtp.gmail.com:587(TLS) - Requires: App password (not regular password)
Outlook/Hotmail
Update .env:
IMAP_HOST=outlook.office365.com
SMTP_HOST=smtp-mail.outlook.com
Other Providers
Just update the IMAP/SMTP settings in your .env file!
Usage Examples
List Recent Messages
{
"count": 20
}
Search Messages
{
"query": "important meeting"
}
Send Email
{
"to": "recipient@example.com",
"subject": "Hello from MCP!",
"body": "This email was sent via the Email MCP Server"
}
Why IMAP/SMTP vs Gmail API?
✅ IMAP/SMTP Advantages:
- Simple app password authentication
- Works with any email provider
- No OAuth2 complexity
- No Google Cloud Console setup
- Immediate setup (2 minutes)
❌ Gmail API Disadvantages:
- Complex OAuth2 flow
- Google Cloud Console configuration
- Token management and refresh
- Gmail-only (vendor lock-in)
Usage with Claude Desktop
Configuration
-
Add the MCP server configuration to your Claude Desktop config file:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- Windows:
-
Add this configuration:
{
"mcpServers": {
"gmail-mcp": {
"command": "node",
"args": ["C:\\path\\to\\your\\Gmail-MCP\\dist\\index.js"],
"cwd": "C:\\path\\to\\your\\Gmail-MCP",
"env": {
"NODE_ENV": "production",
"EMAIL_ADDRESS": "your-email@gmail.com",
"EMAIL_PASSWORD": "your-app-password",
"IMAP_HOST": "imap.gmail.com",
"IMAP_PORT": "993",
"SMTP_HOST": "smtp.gmail.com",
"SMTP_PORT": "587"
}
}
}
}
- Update the paths and credentials with your actual values
- Restart Claude Desktop
- Test with commands like:
- "List my recent emails"
- "Search for emails from john@example.com"
- "Send an email to test@example.com with subject 'Test' and message 'Hello!'"
Docker Usage
npm run docker:build
npm run docker:up
# Check logs:
npm run docker:logs
Troubleshooting
Authentication Errors
- Ensure 2FA is enabled on Gmail
- Use App Password, not your regular password
- Check that IMAP is enabled in Gmail settings
Connection Issues
- Verify IMAP/SMTP settings for your provider
- Check firewall/network restrictions
- Ensure ports 993 (IMAP) and 587 (SMTP) are open
Docker Issues
- Make sure
.envfile exists and is properly formatted - Build the image first:
npm run docker:build - Check Docker logs:
npm run docker:logs
Usage
The server provides the following tools:
listMessages
Lists recent messages from your Gmail inbox.
- Parameters:
count(optional, default: 10, max: 100) - Number of messages to retrieve
Example:
{
"count": 20
}
listUnread
Lists unread messages from your Gmail inbox.
- Parameters:
count(optional, default: 10, max: 100) - Number of unread messages to retrieve
Example:
{
"count": 15
}
findMessage
Searches for messages containing specific words.
- Parameters:
query(required) - Search query using Gmail search syntax
Example:
{
"query": "from:example@gmail.com subject:important"
}
sendMessage
Sends an email message with support for HTML formatting and multiple recipients.
- Parameters:
to(required) - Recipient email addresssubject(required) - Email subjectbody(required) - Plain text message bodyhtml(optional) - HTML version of the email for rich formattingcc(optional) - Single email or array of emails for CCbcc(optional) - Single email or array of emails for BCC
Basic Example:
{
"to": "recipient@example.com",
"subject": "Hello from MCP Server",
"body": "This is a test message sent from the Email MCP Server!"
}
HTML Email Example:
{
"to": "recipient@example.com",
"subject": "Welcome!",
"body": "Welcome to our service. This is the plain text version.",
"html": "<h1>Welcome!</h1><p>Welcome to our <strong>service</strong>.</p><p>This is the <em>HTML</em> version.</p>"
}
Multiple Recipients Example:
{
"to": "recipient@example.com",
"subject": "Team Update",
"body": "Important team update",
"cc": ["manager@example.com", "colleague@example.com"],
"bcc": ["archive@example.com"]
}
Single CC/BCC Example:
{
"to": "recipient@example.com",
"subject": "Quick Note",
"body": "Just a quick note",
"cc": "manager@example.com"
}
markAsRead
Marks one or more messages (by UID) as read.
- Parameters:
messageIds(required array of message UIDs returned by other tools)
Example:
{
"messageIds": ["12345", "12346"]
}
deleteMessage
Deletes one or more messages (by UID) by moving them to the Trash folder.
- Parameters:
messageIds(required array of message UIDs returned by other tools)
Example:
{
"messageIds": ["12345", "12346"]
}
listLabels
Lists all available labels in your Gmail mailbox.
- Parameters: None required
Example:
{}
createLabel
Creates a new label in your Gmail mailbox. Supports hierarchical labels using forward slashes (e.g., Parent/Child).
- Parameters:
labelName(required) - Name of the label to create. Use/to create nested labels.
Example:
{
"labelName": "Important/Work"
}
deleteLabel
Deletes an existing label from your Gmail mailbox.
- Parameters:
labelName(required) - Name of the label to delete
Example:
{
"labelName": "OldLabel"
}
renameLabel
Renames an existing label in your Gmail mailbox.
- Parameters:
oldLabelName(required) - Current name of the labelnewLabelName(required) - New name for the label
Example:
{
"oldLabelName": "testLabel",
"newLabelName": "productionLabel"
}
moveLabel
Moves a label to nest it under a parent label, creating a hierarchical structure.
- Parameters:
labelName(required) - Name of the label to movenewParentLabel(required) - Name of the parent label to nest under
Example:
{
"labelName": "ProjectA",
"newParentLabel": "Archive"
}
This would move ProjectA to become Archive/ProjectA.
moveMessage
Moves a message from one folder/label to another.
- Parameters:
messageId(required) - UID of the message to movefolder(required) - Destination folder/label namesourceFolder(optional, default: "INBOX") - Source folder/label name
Example:
{
"messageId": "12345",
"folder": "Archive/2024",
"sourceFolder": "INBOX"
}
labelMessage
Applies one or more labels to a message.
- Parameters:
messageId(required) - UID of the message to labellabels(required array) - Array of label names to apply
Example:
{
"messageId": "12345",
"labels": ["Important", "Work", "Follow-up"]
}
Gmail Search Syntax
The findMessage tool supports Gmail's advanced search syntax:
Basic Search
keyword- Search for keyword in subject or bodyfrom:sender@example.com- Find emails from specific senderto:recipient@example.com- Find emails to specific recipientsubject:keyword- Find emails with keyword in subject
Folder Search (Gmail-style)
in:inbox test- Search for "test" in INBOXin:sent meeting- Search for "meeting" in Sent Mailin:trash important- Search for "important" in Trashin:spam- List messages in Spam folderin:drafts- List messages in Draftsin:starred- List starred messagesin:all- Search in All Mail
Date Filters
is:unread- Find unread emailsafter:2023/01/01- Find emails after specific datebefore:2023/12/31- Find emails before specific date
Important Note About Search Indexing
Gmail's search index may take a few seconds to a few minutes to update after sending or receiving emails. If you search for a recently sent email and don't find it immediately, this is normal behavior. The email was sent successfully, but Gmail's IMAP search index hasn't been updated yet. Try searching again after waiting 30-60 seconds.
Development
Run in development mode:
npm run dev
Watch for changes:
npm run watch
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.