Gmail MCP Server
Enables programmatic access to Gmail to search emails using Gmail query syntax, list unread messages, archive or mark emails as read, and manage account labels.
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 search for unread emails from GitHub from the last 24 hours"
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
A Model Context Protocol (MCP) server that provides Gmail access for Claude Code and other MCP clients. Built with FastMCP.
Features
list_unread - List unread emails from inbox
search - Search emails using Gmail query syntax
archive - Archive emails (removes from inbox)
mark_as_read - Mark emails as read without archiving
get_labels - Get all Gmail labels
Related MCP server: Gmail MCP Server
Installation
No local installation required! Run directly from GitHub using uvx:
uvx --from git+https://github.com/fred-drake/gmail-mcp gmail-mcpSetup
1. Create Google Cloud OAuth Credentials
Go to Google Cloud Console
Create a new project or select an existing one:
Click the project dropdown at the top of the page
Click "New Project", give it a name, and create it
Make sure your new project is selected
Enable the Gmail API:
Navigate to "APIs & Services" > "Library"
Search for "Gmail API" and click on it
Click "Enable"
Configure the OAuth consent screen (required before creating credentials):
Go to "APIs & Services" > "OAuth consent screen"
Select "External" as the user type and click "Create"
Fill in the required fields:
App name: Choose any name (e.g., "Gmail MCP")
User support email: Select your email
Developer contact email: Enter your email
Click "Save and Continue"
On the "Scopes" page, click "Save and Continue" (no changes needed)
On the "Test users" page:
Click "Add Users"
Enter the Gmail address you want to access (this is critical!)
Click "Add" then "Save and Continue"
Click "Back to Dashboard"
Create OAuth credentials:
Go to "APIs & Services" > "Credentials"
Click "Create Credentials" > "OAuth client ID"
Choose "Desktop app" as the application type
Give it a name (e.g., "Gmail MCP Desktop")
Click "Create"
Click "Download JSON" to save the credentials file
Store this file securely - you'll need the path for configuration
2. Set Environment Variables
Set the path to your OAuth credentials file:
export GMAIL_MCP_CREDENTIALS_PATH="/path/to/your/credentials.json"Optionally, customize the token cache location (default: ~/.config/gmail-mcp/token.json):
export GMAIL_MCP_TOKEN_PATH="/custom/path/token.json"3. Run OAuth Setup
Run the interactive setup to authenticate:
uvx --from git+https://github.com/fred-drake/gmail-mcp gmail-mcp --setupThis will open a browser window for Google OAuth authentication. After authorizing, the token will be cached for future use.
MCP Client Configuration
Claude Code
Add to your Claude Code MCP settings:
{
"mcpServers": {
"gmail": {
"command": "uvx",
"args": ["--from", "git+https://github.com/fred-drake/gmail-mcp", "gmail-mcp"],
"env": {
"GMAIL_MCP_CREDENTIALS_PATH": "/path/to/your/credentials.json"
}
}
}
}With Custom Token Path
{
"mcpServers": {
"gmail": {
"command": "uvx",
"args": ["--from", "git+https://github.com/fred-drake/gmail-mcp", "gmail-mcp"],
"env": {
"GMAIL_MCP_CREDENTIALS_PATH": "/path/to/your/credentials.json",
"GMAIL_MCP_TOKEN_PATH": "/custom/path/token.json"
}
}
}
}Environment Variables
Variable | Required | Default | Description |
| Yes | - | Path to OAuth credentials JSON |
| No |
| Path to token cache file |
Tool Reference
list_unread
List unread emails from inbox.
Parameters:
max_results(int, optional): Maximum emails to return (1-100). Default: 20.
Returns: List of email objects with id, from, subject, date, snippet, labels, body_preview.
search
Search emails using Gmail query syntax.
Parameters:
query(str): Gmail search query (e.g., "from:user@example.com is:unread")max_results(int, optional): Maximum results (1-100). Default: 20.
Returns: List of matching email objects.
Example queries:
from:notifications@github.com- Emails from GitHubis:unread newer_than:1d- Unread emails from last 24 hourssubject:invoice- Emails with "invoice" in subjecthas:attachment larger:5M- Emails with attachments over 5MB
archive
Archive emails by removing INBOX and UNREAD labels.
Parameters:
message_ids(list[str]): List of message IDs to archive.
Returns: Dict with archived_count, failed_count, and details.
mark_as_read
Mark emails as read without archiving.
Parameters:
message_ids(list[str]): List of message IDs to mark as read.
Returns: Dict with marked_count, failed_count, and details.
get_labels
Get all Gmail labels for the authenticated user.
Returns: List of label objects with id, name, type, and message counts.
Development
Prerequisites
Python 3.13+
Nix (optional, for reproducible environment)
Setup with Nix
cd gmail-mcp
nix developSetup with pip
cd gmail-mcp
pip install -e ".[dev]"Running Tests
pytestLinting
ruff check .
ruff format .License
MIT
Available Tools
5 toolsarchiveA
Archive emails by removing INBOX and UNREAD labels.
Args: message_ids: List of message IDs to archive.
Returns: Dict with archived_count, failed_count, and details.
Inputs: message_ids (required). Returns: object
get_labelsB
Get all Gmail labels for the authenticated user.
Returns: List of label objects with id, name, type, and message counts.
Inputs: no named parameters. Returns: result
list_unreadB
List unread emails from inbox.
Args: max_results: Maximum number of emails to return (1-100). Default: 20.
Returns: List of email objects with id, from, subject, date, snippet, labels, body_preview.
Inputs: max_results. Returns: result
mark_as_readA
Mark emails as read without archiving.
Args: message_ids: List of message IDs to mark as read.
Returns: Dict with marked_count, failed_count, and details.
Inputs: message_ids (required). Returns: object
searchA
Search emails using Gmail query syntax.
Args: query: Gmail search query (e.g., "from:user@example.com is:unread", "subject:invoice", "newer_than:1d"). max_results: Maximum number of results (1-100). Default: 20.
Returns: List of email objects matching the query.
Inputs: query (required), max_results. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a distinct and clear purpose: archive emails, get labels, list unread emails, mark emails as read, and search emails. There is no overlap in functionality, making it easy for an agent to select the correct tool without confusion.
All tool names follow a consistent verb_noun pattern (e.g., archive, get_labels, list_unread, mark_as_read, search). The naming is straightforward and predictable, enhancing usability and clarity.
With 5 tools, the server is well-scoped for basic Gmail operations, covering key actions like reading, archiving, and searching emails. However, it lacks some advanced features like sending or deleting emails, which slightly limits its completeness but keeps the count reasonable.
The tool set covers essential read and modify operations (list, search, mark as read, archive) and label management, but it has notable gaps: there are no tools for sending emails, deleting emails, or managing drafts. This could lead to agent failures for common email workflows like composing or removing messages.
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.
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
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 interaction with Gmail through the MCP protocol, supporting sending, reading, searching, replying, forwarding, managing drafts and labels, and saving attachments.2 npm3MIT
- AlicenseNot gradedqualityDmaintenanceEnables Gmail operations such as reading, sending, searching, and managing emails, threads, labels, and drafts via MCP tools.1MIT
- AlicenseNot gradedqualityCmaintenanceEnables Gmail operations like listing, searching, sending emails, and managing labels via MCP tools.445 npmMIT