Gmail MCP Server
Provides tools for searching emails, retrieving content, managing labels, sending and forwarding emails, and batch operations on Gmail accounts via IMAP and SMTP.
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., "@Gmail MCP Server List my most recent emails in inbox"
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.
Gmail MCP Server
This project implements a Model Context Protocol (MCP) server that allows interaction with Gmail accounts via IMAP and SMTP. It provides tools for searching emails, retrieving content, managing labels (creating, deleting, renaming, applying, removing), and sending/forwarding emails.
Features
Email Search: Search emails by date range, keyword, or raw Gmail query string. Supports searching specific folders (inbox, sent) and limiting results. Uses Gmail's
X-GM-RAWextension for efficient inbox searching (e.g., filtering bycategory:primary).Email Content Retrieval: Fetch the full content (headers, body, attachments) of a specific email using its sequence ID.
Label Management (CRUD):
List all available Gmail labels (folders).
Create new custom labels.
Rename existing custom labels.
Delete existing custom labels (cannot delete system labels).
Apply labels to individual emails.
Remove labels from individual emails.
Batch Operations:
Apply labels to multiple emails simultaneously using sequence IDs.
Remove labels from multiple emails simultaneously.
Move multiple emails to a specific label/folder.
Email Sending: Send new emails (requires SMTP configuration).
Email Forwarding: Forward existing emails, including attachments (requires SMTP configuration).
Daily Email Count: Count emails received per day within a specified date range.
Related MCP server: Moist
Project Structure
.
├── .gitignore # Specifies intentionally untracked files that Git should ignore
├── .python-version # Specifies Python version (used by pyenv)
├── LICENSE # Project license file
├── pyproject.toml # Python project configuration (dependencies, build system)
├── README.md # This file
├── task_list.md # Tracks development progress
├── uv.lock # Lock file for uv package manager
├── src/
│ └── email_client/
│ ├── __init__.py
│ ├── config.py # Handles loading configuration from environment variables (.env)
│ ├── handlers.py # Implements the logic for handling MCP tool calls
│ ├── imap_client.py # Contains functions for interacting with IMAP server
│ ├── server.py # Main MCP server script using @modelcontextprotocol/sdk
│ ├── smtp_client.py # Contains functions for interacting with SMTP server
│ ├── tool_definitions.py # Defines the available MCP tools and their schemas
│ └── utils.py # Utility functions (e.g., email parsing, date formatting)
└── ... (other potential files like test scripts, helper scripts)Setup
Clone the repository (if applicable):
git clone https://github.com/david-strejc/gmail-mcp-server.git cd gmail-mcp-serverInstall Dependencies: This project uses
uvfor package management.# Ensure uv is installed (e.g., pip install uv) uv venv # Create virtual environment (.venv) uv sync # Install dependencies from pyproject.toml and uv.lock source .venv/bin/activate # Activate the virtual environment(Alternatively, if not using
uv, create a virtual environment and install usingpip install -r requirements.txtif arequirements.txtis generated).Configure Environment Variables: Create a
.envfile in the project root directory and add your Gmail credentials and server settings:# .env file GMAIL_EMAIL=your_email@gmail.com GMAIL_PASSWORD=your_app_password # Use an App Password if 2FA is enabled GMAIL_IMAP_SERVER=imap.gmail.com GMAIL_SMTP_SERVER=smtp.gmail.com GMAIL_SMTP_PORT=587 # Or 465 for SSLImportant: For Gmail, if you have 2-Factor Authentication enabled, you must generate and use an "App Password". Standard passwords will not work. See Google's documentation on App Passwords.
Ensure "Less secure app access" is enabled if you are not using 2FA (this is generally discouraged).
Running the MCP Server
Activate the virtual environment and run the server script:
source .venv/bin/activate
python src/email_client/server.pyThe server will start and listen for MCP requests via standard input/output.
Integrating with an MCP Client (e.g., Cline)
Add the server configuration to your MCP client's settings file (e.g., cline_mcp_settings.json or claude_desktop_config.json).
Example cline_mcp_settings.json entry:
{
"mcpServers": {
"gmail": {
"command": "/path/to/your/project/gmail-mcp-server/.venv/bin/python",
"args": ["/path/to/your/project/gmail-mcp-server/src/email_client/server.py"],
"env": {}, // Environment variables are loaded from .env by the script
"enabled": true, // Set to true to enable
"autoApprove": [] // Configure auto-approval if desired
}
// ... other servers
}
}Replace
/path/to/your/project/gmail-mcp-serverwith the actual absolute path to this project directory.Ensure the
commandpoints to the python executable within the project's virtual environment (.venv/bin/python).
Once configured and enabled, the client should connect to the server, and the defined tools will become available.
Available Tools (Summary)
search-emails: Search emails.get-email-content: Get full email details.count-daily-emails: Count emails per day.list-labels: List all labels/folders.create-label: Create a new label.rename-label: Rename an existing label.delete-label: Delete a label.apply-label: Apply a label to one email.remove-label: Remove a label from one email.apply-label-batch: Apply a label to multiple emails.remove-label-batch: Remove a label from multiple emails.move-email: Move a single email to a label.move-email-batch: Move multiple emails to a label.send-email: Send a new email.forward-email: Forward an existing email.
Refer to src/email_client/tool_definitions.py for detailed input schemas for each tool.
Available Tools
15 toolsapply-labelB
Apply a label to an email
Inputs: email_id (required), label_name (required).
apply-label-batchA
Apply a label to multiple emails using their sequence IDs (from search results)
Inputs: email_ids (required), label_name (required).
count-daily-emailsB
Count emails received for each day in a date range
Inputs: start_date (required), end_date (required).
create-labelB
Create a new Gmail label/folder
Inputs: label_name (required).
delete-labelA
Delete a Gmail label/folder entirely. Cannot delete system labels.
Inputs: label_name (required).
forward-emailA
Forward an email with its attachments to new recipients. Required fields: email_id and recipients (to). Optional: subject_prefix, additional_message, and CC recipients.
Inputs: email_id (required), to (required), subject_prefix, additional_message, +1 more.
get-email-contentB
Get the full content of a specific email by its ID
Inputs: email_id (required).
list-labelsA
List all available Gmail labels/folders
Inputs: no named parameters.
move-emailB
Move an email to a specific folder/label
Inputs: email_id (required), destination_label (required).
move-email-batchB
Move multiple emails to a specific folder/label using their sequence IDs (from search results)
Inputs: email_ids (required), destination_label (required).
remove-labelB
Remove a label from an email
Inputs: email_id (required), label_name (required).
remove-label-batchA
Remove a label from multiple emails using their sequence IDs (from search results)
Inputs: email_ids (required), label_name (required).
rename-labelA
Rename an existing Gmail label/folder. Cannot rename system labels.
Inputs: old_label_name (required), new_label_name (required).
search-emailsC
Search emails within a date range and/or with specific keywords
Inputs: start_date, end_date, keyword, raw_query, +2 more.
send-emailA
CONFIRMATION STEP: Actually send the email after user confirms the details. Before calling this, first show the email details to the user for confirmation. Required fields: recipients (to), subject, and content. Optional: CC recipients.
Inputs: to (required), subject (required), content (required), cc.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Each tool has a clearly distinct purpose: individual vs batch operations are separated, and all actions (apply label, remove label, move, etc.) target different aspects of Gmail management. No overlap that would cause confusion.
Tool names follow a consistent verb_noun pattern (e.g., apply-label, create-label, search-emails). Batch variants include '-batch' suffix, and 'count-daily-emails' is the only slight deviation but still clear. Overall predictable and uniform.
With 15 tools covering email search, retrieval, sending, forwarding, label management (CRUD plus batch operations), and counting, the scope is well-balanced for a Gmail server. Each tool serves a distinct purpose and the count feels right.
The tool set covers core operations like sending, forwarding, searching, and label management, but lacks common email actions such as marking as read/unread, trashing, archiving, or managing drafts. Batch operations are a plus, but some expected Gmail features are missing.
Maintenance
Related MCP Connectors
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
A MCP server for Gmail that lets you search, read, and draft emails and replies.
Hosted MCP server for your Gmail, Outlook and IMAP mail, with mailboxes and scopes set per agent.
Email inboxes for AI agents: send, receive, reply, search, and manage threaded email over MCP.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables interaction with Gmail through MCP-compatible clients to list, read, search, and send emails. It supports advanced features such as managing labels, handling threaded replies, and utilizing Gmail's native search syntax.28 npm2MIT
- AlicenseNot gradedqualityDmaintenanceEnables Gmail operations such as reading, sending, searching, and managing emails, threads, labels, and drafts via MCP tools.1MIT
- FlicenseNot gradedqualityDmaintenanceEnables searching, reading, and drafting emails across multiple Gmail accounts through a single MCP server.-
- AlicenseNot gradedqualityCmaintenanceEnables Gmail operations like listing, searching, sending emails, and managing labels via MCP tools.127 npmMIT