Gmail MCP Server

Gmail MCP Server

Enables interaction with Gmail through the Gmail API to read, send, and manage emails. Supports multiple Gmail accounts with real-time monitoring and advanced features for email search and attachment handling.

Quantum-369

Communication
Python
Visit Server

README

Gmail MCP Server

smithery badge

A powerful and flexible Gmail integration server built using the MCP (Message Control Protocol) framework. This server provides a robust interface to interact with Gmail APIs, offering functionality for reading, sending, and managing emails programmatically.

Features

  • Read emails from multiple Gmail accounts
  • Send emails with attachments
  • Search emails with advanced query options
  • Download email attachments
  • Handle email conversations and threads
  • Real-time email monitoring
  • Support for multiple Gmail accounts

Prerequisites

Before running the Gmail MCP server, ensure you have the following:

  1. Python 3.12 or higher
  2. Google Cloud Project with Gmail API enabled
  3. OAuth 2.0 Client ID credentials
  4. Required Python packages (specified in pyproject.toml)

Installation

Installing via Smithery

To install Gmail Integration Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @Quantum-369/Gmail-mcp-server --client claude
  1. Clone the repository:
git clone <your-repository-url>
cd gmail-mcp-server
  1. Create and activate a virtual environment:
python -m venv venv
# On Windows
venv\Scripts\activate
# On Unix/MacOS
source venv/bin/activate
  1. Install dependencies:
pip install .

Setup Google Cloud Project

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Gmail API for your project
  4. Create OAuth 2.0 credentials:
    • Go to "APIs & Services" > "Credentials"
    • Click "Create Credentials" > "OAuth client ID"
    • Choose "Desktop app" as application type
    • Download the client configuration file
  5. Rename the downloaded file to client_secret.json and place it in the project root directory

Configuration

  1. Set up email identifiers in gmail_token_creator.py:
email_identifier = 'your.email@gmail.com'  # Change this for each account
  1. Run the token creator to authenticate your Gmail accounts:
python gmail_token_creator.py
  1. Repeat the process for each Gmail account you want to integrate

Server Structure

  • gmail_server.py: Main MCP server implementation
  • gmail_api.py: Gmail API interaction functions
  • google_apis.py: Google API authentication utilities
  • Supporting files:
    • read_emails.py: Email reading functionality
    • search_emails.py: Email search functionality
    • send_emails.py: Email sending functionality

Usage

Starting the Server

python gmail_server.py

Available Tools

  1. Send Email:
await send_gmail(
    email_identifier="your.email@gmail.com",
    to="recipient@example.com",
    subject="Test Subject",
    body="Email body content",
    attachment_paths=["path/to/attachment"]
)
  1. Search Emails:
await search_email_tool(
    email_identifier="your.email@gmail.com",
    query="from:someone@example.com",
    max_results=30,
    include_conversations=True
)
  1. Read Latest Emails:
await read_latest_emails(
    email_identifier="your.email@gmail.com",
    max_results=5,
    download_attachments=False
)
  1. Download Attachments:
await download_email_attachments(
    email_identifier="your.email@gmail.com",
    msg_id="message_id",
    download_all_in_thread=False
)

Security Considerations

  • Store client_secret.json securely and never commit it to version control
  • Keep token files secure and add them to .gitignore
  • Use environment variables for sensitive information
  • Regularly rotate OAuth credentials
  • Monitor API usage and set appropriate quotas

Error Handling

The server includes comprehensive error handling and logging:

  • Logs are written to gmail_mcp.log
  • Both file and console logging are enabled
  • Detailed error messages for debugging

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

Apachelicense2.0

Support

For issues and feature requests, please use the GitHub issue tracker.

Recommended Servers

graphlit-mcp-server

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.

Official
Featured
TypeScript
Apple MCP Server

Apple MCP Server

Enables interaction with Apple apps like Messages, Notes, and Contacts through the MCP protocol to send messages, search, and open app content using natural language.

Featured
Local
TypeScript
DuckDuckGo MCP Server

DuckDuckGo MCP Server

A Model Context Protocol (MCP) server that provides web search capabilities through DuckDuckGo, with additional features for content fetching and parsing.

Featured
Python
YouTube Transcript MCP Server

YouTube Transcript MCP Server

This server retrieves transcripts for given YouTube video URLs, enabling integration with Goose CLI or Goose Desktop for transcript extraction and processing.

Featured
Python
@kazuph/mcp-gmail-gas

@kazuph/mcp-gmail-gas

Model Context Protocol server for Gmail integration. This allows Claude Desktop (or any MCP client) to interact with your Gmail account through Google Apps Script.

Featured
JavaScript
MCP Server Trello

MCP Server Trello

Facilitates interaction with Trello boards via the Trello API, offering features like rate limiting, type safety, input validation, and error handling for seamless management of cards, lists, and board activities.

Featured
TypeScript
Tavily MCP Server

Tavily MCP Server

Provides AI-powered web search capabilities using Tavily's search API, enabling LLMs to perform sophisticated web searches, get direct answers to questions, and search recent news articles.

Featured
Python
Linear MCP Server

Linear MCP Server

A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.

Featured
JavaScript
Brev

Brev

Run, build, train, and deploy ML models on the cloud.

Official
Local
Python
Crawlab MCP Server

Crawlab MCP Server

Official
Python