Gmail MCP Server
Enables interaction with Gmail through the Gmail API with OAuth2 authentication. Supports reading, sending, searching emails, and managing read status through natural language.
README
Gmail MCP Server
A Model Context Protocol (MCP) server that provides tools for interacting with Gmail through the Gmail API.
Features
- 🔐 OAuth2 Authentication - Secure authentication with Google's OAuth2
- 📧 Read Emails - List and read emails from your Gmail inbox
- ✉️ Send Emails - Send emails through Gmail
- 🔍 Search Emails - Search emails using Gmail's powerful search syntax
- 📌 Mark as Read/Unread - Manage email read status
- 🛡️ Secure - Uses Google's official authentication flow
Quick Start
-
Install dependencies:
pip install -r requirements.txt -
Run the server:
python gmail_mcp_server.py -
First time setup:
- Use the
authenticate_gmailtool to authorize access - This will open your browser for Google OAuth consent
- Use the
Available Tools
authenticate_gmail
Authenticate with Gmail API using OAuth2. Must be run first.
list_emails
List emails from your Gmail inbox.
max_results(optional): Maximum number of emails to return (default: 10)query(optional): Gmail search query
read_email
Read a specific email by its ID.
email_id(required): The ID of the email to read
send_email
Send an email through Gmail.
to(required): Recipient email addresssubject(required): Email subjectbody(required): Email body (plain text)cc(optional): CC email addresses (comma-separated)bcc(optional): BCC email addresses (comma-separated)
search_emails
Search emails using Gmail search syntax.
query(required): Gmail search querymax_results(optional): Maximum number of results (default: 10)
mark_as_read / mark_as_unread
Mark an email as read or unread.
email_id(required): The ID of the email to modify
Gmail Search Syntax
is:unread- Unread emailsfrom:example@gmail.com- Emails from specific sendersubject:important- Emails with "important" in subjecthas:attachment- Emails with attachmentsafter:2024/01/01- Emails after specific date
Configuration
- Credentials file:
gcp-oauth.keys.json(your GCP OAuth credentials - seegcp-oauth.keys.json.example) - Token file:
token.pickle(created automatically after authentication) - MCP config:
mcp_config.json(for MCP client configuration)
Setup Credentials
- Copy
gcp-oauth.keys.json.exampletogcp-oauth.keys.json - Replace the placeholder values with your actual GCP OAuth credentials
- Ensure Gmail API is enabled in your Google Cloud project
Integration
To integrate this server with other projects:
-
Copy the core files:
gmail_mcp_server.py- Main serverrequirements.txt- Dependenciesgcp-oauth.keys.json- Your OAuth credentials
-
Install dependencies:
pip install -r requirements.txt -
Configure MCP client using
mcp_config.json:{ "mcpServers": { "gmail": { "command": "python", "args": ["gmail_mcp_server.py"], "cwd": "/path/to/your/gmail/mcp/server" } } }
Testing
Run the included test to verify functionality:
python direct_test.py
This will test authentication, email listing, searching, and sending.
Security
- OAuth2 credentials are stored securely using Google's official libraries
- Access tokens are refreshed automatically
- All API calls use HTTPS
- Keep
token.picklefile secure
License
This project is provided as-is for educational and integration purposes.
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.